Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – setting up our screen resolution


The old AppDelegate class logic now exists inside a file called main.lua:

  1. In the IDE, open the main.lua file inside the src folder.

  2. After the line where we set the animation interval, type the following:

    cc.Director:getInstance():getOpenGLView(): setDesignResolutionSize(640, 960,  cc.ResolutionPolicy.SHOW_ALL)
       local screenSize =  cc.Director:getInstance():getVisibleSize()
       local designSize = cc.size(640, 960)
       if (screenSize.width > 320) then
         cc.Director:getInstance():setContentScaleFactor(640/   designSize.width)       
         cc.FileUtils:getInstance():addSearchPath("res/hd/") 
       else
         cc.Director:getInstance():setContentScaleFactor(320/designSize.width)
         cc.FileUtils:getInstance():addSearchPath("res/sd/")         
       end
  3. I designed the game for iPhone retina, and here we set the appropriate scale and asset folder for both retina and non-retina phones. Next, let's preload the sound files:

           local bgMusicPath =  cc...