Box2D Forums

It is currently Tue May 21, 2013 5:11 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Apr 07, 2012 1:36 pm 
Offline

Joined: Sat Jan 28, 2012 11:13 am
Posts: 6
Hello,

I have a Cocos2d Sprite and a Box2d Body. I am using a PTM_Ratio of 32.

On a standard iPhone device (480 x 680) my sprite is at position 240 x 300 and the b2body at 7.5 x 9.375. The body and sprite match up perfectly. The sprite and box2d body also appear in the correct location.

On a retinar display iPhone device (960 x 320) my sprite is at position 480 x 600 and the b2body at 15 x 18.75. The b2Body appears in the correct place but the sprite is nowhere near, it is around 200 pixels away.
I have tried everything from changing the PTM ratio to 16 and 64 (as it's double the size in retinar) to removing the sprite position. None of these work.

Update: I have just noticed the bodies appear weird such as overlapping in the higher resolution. I assume it has something to do with the PTM.

What on earth am I doing wrong?


Top
 Profile  
 
PostPosted: Mon Apr 09, 2012 4:12 am 
Offline

Joined: Sat Jan 28, 2012 11:13 am
Posts: 6
I have found the solution to this encase anyone else if having the same issue.

It appears to be a common fault with box2d not scaling to the retinar display. The resolution and sprites are managed by Cocos2d but box2d appears to get left behind working in standard 480x320 mode.

To scale box2d add this in your draw method.

Code:
   
glPushMatrix();
glScalef(CC_CONTENT_SCALE_FACTOR(), CC_CONTENT_SCALE_FACTOR(), 1.0f);
world->DrawDebugData();
glPopMatrix();


This will scale box2d objects by 2 for HD and 1 by default.

You may find the physics act weird in the simulator but I found once I compiled to a device it works as expected.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group