![]() Here you define designSize – the size you’re using when creating your game logic – and resourceSize – the size on which all your art assets are based.To implement this, add the following code inside AppDelegate::applicationDidFinishLaunching, just above the line that calls setDisplayStats on director:ĭirector->setContentScaleFactor(resourceSize.height / designSize.height) ĭirector->getOpenGLView()->setDesignResolutionSize(ĭesignSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT) So how do you handle multiple resolutions? In this tutorial, you’ll create a single set of game resources based on a 960×640 resolution, then simply scale the assets up or down as necessary at runtime. While this call to createWithRect changes the game’s frame on desktops, it doesn’t work this way on iOS devices instead, the game’s resolution matches the screen size. For example, to test a 1920×1080 resolution on a monitor smaller than 1920×1080, you could pass 0.5 to scale the window to 960×540. This parameter scales the frame, which is usually \used for testing resolutions larger than your monitor. ![]() Notice the third argument you passed to createWithRect - 1.0. This changes the app’s name to “SimpleGame” and sets its resolution to 480×320 to match the background art included with the template.īuild and run your app again to see your new, smaller game: Replace that line with the following code: Open AppDelegate.cpp and find the following line inside AppDelegate::applicationDidFinishLaunching: Porting this project to other platforms is a trivial (yes, trivial!) matter discussed briefly at the end of this tutorial.īuild and run your app to see the template project in all its glory:īy default, Cocos2d-x games are named “MyGame” and have a resolution of 960×640, but those details are easy to change. While Cocos2d-x is capable of building games for many platforms, in this tutorial you’ll focus on making an OS X app. Once you’re Inside Xcode, ensure that SimpleGame Mac is the active scheme, as shown below: ![]() You can also learn about any subcommand’s options by appending “-help” or “-h”, such as cocos new -h to see the options for the new command.ĭouble-click ~/Cocos2d-x-Tutorial/SimpleGame/proj.ios_mac/SimpleGame.xcodeproj in Finder to open the project in Xcode. Note: To learn about the available cocos subcommands, type cocos -help or cocos -h. This creates a directory named Cocos2d-x-Tutorial in your home directory, and inside that, a sub-directory named SimpleGame that contains your project’s files. Run the following command to create a C game template named SimpleGame:Ĭocos new -l cpp -d ~/Cocos2d-x-Tutorial SimpleGame Now you can call the cocos command in Terminal from any directory. The command you entered simply re-processes your shell configuration and gives it access to the new variables. Source ~/.zshrc (or source ~/.bash_profile) A great timesaving tip: you can use a tilde ( ~) in place of /Users/your_user_name, so to save keystrokes you could type the following: In the above screenshot, the setup package prompts for “source /Users/rwenderlich/bash_profile.” commands since I’m using Bash, but had I been using Zsh, for example, it would have prompted me to run “source /Users/rwenderlich/.zshrc”.Įnter the command as the script’s output instructed. Note: Depending on which shell you use, you might see some different output.
0 Comments
Leave a Reply. |