AppMacros.h 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifndef _APPMACROS_H_
  30. #define _APPMACROS_H_
  31. #include "cocos2d.h"
  32. /* For demonstrating using one design resolution to match different resources,
  33. or one resource to match different design resolutions.
  34. [Situation 1] Using one design resolution to match different resources.
  35. Please look into Appdelegate::applicationDidFinishLaunching.
  36. We check current device frame size to decide which resource need to be selected.
  37. So if you want to test this situation which said in title '[Situation 1]',
  38. you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
  39. or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
  40. and modify "proj.mac/AppController.mm" by changing the window rectangle.
  41. [Situation 2] Using one resource to match different design resolutions.
  42. The coordinates in your codes is based on your current design resolution rather than resource size.
  43. Therefore, your design resolution could be very large and your resource size could be small.
  44. To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
  45. and open iphone simulator or create a window of 480x320 size.
  46. [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
  47. */
  48. #define DESIGN_RESOLUTION_480X320 0
  49. #define DESIGN_RESOLUTION_960x640 1
  50. #define DESIGN_RESOLUTION_1024X768 2
  51. #define DESIGN_RESOLUTION_2048X1536 3
  52. /* If you want to switch design resolution, change next line */
  53. #define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_960x640
  54. typedef struct tagResource {
  55. cocos2d::Size size;
  56. char directory[100];
  57. } Resource;
  58. static Resource smallResource = {cocos2d::Size(480, 320), "iphone"};
  59. static Resource mediumResource = {cocos2d::Size(960, 640), "iphone-retina"};
  60. static Resource largeResource = {cocos2d::Size(1024, 768), "ipad"};
  61. static Resource extralargeResource = {cocos2d::Size(2048, 1536), "ipad-retina"};
  62. #if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
  63. static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
  64. #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_960x640)
  65. static cocos2d::Size designResolutionSize = cocos2d::Size(960, 640);
  66. #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
  67. static cocos2d::Size designResolutionSize = cocos2d::Size(1024, 768);
  68. #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
  69. static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
  70. #else
  71. #error unknown target design resolution!
  72. #endif
  73. // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
  74. #define TITLE_FONT_SIZE (cocos2d::Director::getInstance()->getOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
  75. #endif /* _APPMACROS_H_ */