Resize view

Resize view
0.0 0


Hi, I’ve developed a game using the iPad resolution and now I’d like to support the iPhone. For this particular game I just need to autoscale the entire game to fit the device. It actually looks good. I’ve tested this using another game sdk that supports virtual resolution (Moai SDK)… Unfortunately I decided not to use it because it’s still in beta and I need to implement a lot of things that are already supported in cocos2d-x.

Any tips to support this? I understand autoscale is for Android, but I’m sure there is a way to modify Cocos2d-x to scale an iPad resolution down.

If not, I thought of a different alternative which did not involve rescaling the game view, but modifying the coordinates based on the device resolution.

Center position would be:
iPhone: (160, 240)
iPhone-Ret: (320, 480)
iPad: (384, 512)

If I am not mistaken I would be able to support correct placement on every device by modifying ccp() to figure out where to place the object based on the device size. I understand this is built-in for iPhone and retina but why not iPad as well? Perhaps we should include the ability to set a virtual resolution and ccp() would calculate correct position based on that.

Now I got placement setup correctly, I am thinking I could create the assets by scaling them based on different scale factor from the original resolution (which is 1024x768) in my case.

So to prepare the iPhone assets I scale all assets by (320/768, 480/1024). If I am not mistaken, this should produce the same effect as scaling the entire game to the device size, correct?

If so, why isn’t this built-in? If I am wrong, could you explain my error.


Yes you can do that in cocos2d, you just need to call “setScale(xxx)” from within you main layer (main CCLayer).

There is one small problem, the iPad resolution is 1024x768, a different ratio to the iPhones 480x320 (or 4’s 960x640) so you’ll end up needing to fill a few more pixels on the borders.

Have a go, open up the HelloWorld sample, in the Init function just before the “return true;” line put “setScale( 2.1f );”. Run the app on the iPad and you’ll see it is all scaled up. Of course this is the other way around to what you want, you just need to develop on the iPad with a 1024x768 screen and scale down with a call like “setScale(0.46f);”.

Only other thing to consider is the speed requirements of your app/game running on the older slower iPhones/iPods.


Do you know what is wrong?

Since I am using Windows, in the Appdelegate I changed the size to (320, 480).

In my main layer in the scene method I have the following:
if (scene)

In CCNode.cpp I modified setPosition:
m_tPosition = newPosition;//position is in 768,1024 space.
m_tPositionInPixels = CCPoint(newPosition.x**, newPosition.y**(480/1024));//position is in 320,480 space

I modified setPositionInPixels:
m_tPositionInPixels = newPosition;
m_tPosition = CCPoint(newPosition.x**, newPosition.y**(1024/480));

But I am not able to get the correct positioning.