gutaideng
gutaideng

Reputation: 57

how to adapt my cocos2d-x app on iphone 5

My game is designed with cocos2d-x, the picture resource size is 320x480, which is adapted to iphone4, now I want my game adapt to iphone5, what should I do?, thanks!

Upvotes: 1

Views: 1539

Answers (2)

Emadpres
Emadpres

Reputation: 3747

Cocos2D-x 2.0.4+ have very easy solution for multi-resolution problem. ( either iDevices or Android devices.)

In fact you just need to set your DesignResolution and then just imagine your target device will has this resolution.

If target device really has this resolution ( or some other but with same ratio) cocos2d will handle to fix screen and your game looks same in all devices.

And when ratio of target device is different, you have many option ( as cocos2d language, policy) to manage that.

For example if you use Exact fit policy, cocos2d will force your game ( and design) to fit target device screen (without that black boarder).

Exact fit

The entire application is visible in the specified area without trying to preserve the original aspect ratio. Distortion can occur, and the application may appear stretched or compressed.

For more detail just take a look at this link : http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support

Upvotes: 0

Laurent Zubiaur
Laurent Zubiaur

Reputation: 438

It actually depends on your current cocos2d-x version and the resolutions you're planning to support. But basically if you're running the latest stable release (2.0.4) and you only want to support iPhone4 and iphone5 resolutions then you have to:

  1. create the art for both resolutions (this is not mandatory but the graphics might be scaled too much and lose quality).

  2. define at runtime the DesignResolutionSize and ContentScaleFactor based on the actual device's resolution

  3. select the correct resource path

Here a simple example on how it can be implemented:

// Get the real screen size
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);

// Set the design resolution. Please see the doc for the different modes
pEGLView->setDesignResolutionSize(480, 320, kResolutionNoBorder);

// Here you have to chose between width or height depending your game's design
if (frameSize.width > 480) {
      // iphone5
      pDirector->setContentScaleFactor(1136/480);
      CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
} else { 
     // iphone4
     pDirector->setContentScaleFactor(1);
     CCFileUtils::sharedFileUtils()->setResourceDirectory("sd");
}

/// Now load the sprites....

If you're want to support more iOS/android resolutions please refer to the following links for fullscreen multi-resolution solutions offered by cocos2d-x:

http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support

http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Mechanism_of_loading_resources

Hope it helped.

Upvotes: 1

Related Questions