|
| 1 | +#ifndef __APPMACROS_H__ |
| 2 | +#define __APPMACROS_H__ |
| 3 | + |
| 4 | +#include "cocos2d.h" |
| 5 | + |
| 6 | +/* For demonstrating using one design resolution to match different resources, |
| 7 | + or one resource to match different design resolutions. |
| 8 | +
|
| 9 | + [Situation 1] Using one design resolution to match different resources. |
| 10 | + Please look into Appdelegate::applicationDidFinishLaunching. |
| 11 | + We check current device frame size to decide which resource need to be selected. |
| 12 | + So if you want to test this situation which said in title '[Situation 1]', |
| 13 | + you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina), |
| 14 | + or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform |
| 15 | + and modify "proj.mac/AppController.mm" by changing the window rectangle. |
| 16 | +
|
| 17 | + [Situation 2] Using one resource to match different design resolutions. |
| 18 | + The coordinates in your codes is based on your current design resolution rather than resource size. |
| 19 | + Therefore, your design resolution could be very large and your resource size could be small. |
| 20 | + To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536' |
| 21 | + and open iphone simulator or create a window of 480x320 size. |
| 22 | +
|
| 23 | + [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources. |
| 24 | + */ |
| 25 | + |
| 26 | +#define DESIGN_RESOLUTION_480X320 0 |
| 27 | +#define DESIGN_RESOLUTION_1024X768 1 |
| 28 | +#define DESIGN_RESOLUTION_2048X1536 2 |
| 29 | + |
| 30 | +/* If you want to switch design resolution, change next line */ |
| 31 | +#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320 |
| 32 | + |
| 33 | +typedef struct tagResource |
| 34 | +{ |
| 35 | + cocos2d::CCSize size; |
| 36 | + char directory[100]; |
| 37 | +}Resource; |
| 38 | + |
| 39 | +static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "iphone" }; |
| 40 | +static Resource mediumResource = { cocos2d::CCSizeMake(1024, 768), "ipad" }; |
| 41 | +static Resource largeResource = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" }; |
| 42 | + |
| 43 | +#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320) |
| 44 | +static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320); |
| 45 | +#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768) |
| 46 | +static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768); |
| 47 | +#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536) |
| 48 | +static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536); |
| 49 | +#else |
| 50 | +#error unknown target design resolution! |
| 51 | +#endif |
| 52 | + |
| 53 | +// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution |
| 54 | +#define TITLE_FONT_SIZE (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24) |
| 55 | + |
| 56 | +#endif /* __APPMACROS_H__ */ |
0 commit comments