I did some searching and googling, but couldn't find a solution. Basically, I'm using the drawspace.h/c files to draw the shapes of my Chipmunk objects for debugging purposes. It's fine normally, but if I test with a retina display, it seems to be drawing everything with pixels instead of points. Any fixes out there? Thanks.
Chipmunk drawspace.c
(6 posts) (3 voices)-
Posted 6 months ago #
-
You need to scale by CC_CONTENT_SCALE_FACTOR(). Something like this:
-(void) draw; { glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); glPushMatrix(); { glScalef(CC_CONTENT_SCALE_FACTOR(), CC_CONTENT_SCALE_FACTOR(), 1.0); glLineWidth(1.0f); cpSpaceEachShape(space.space, drawShape, NULL); glColor4f(0.5f, 1.0f, 0.5f, 1.0f); cpSpaceEachConstraint(space.space, drawConstraint, NULL); } glPopMatrix(); glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); }You might also find this useful, it's written for Objective-Chipmunk, but would be trivial to change to work with vanilla Chipmunk: http://files.slembcke.net/temp/ChipmunkDebugNode.tgz
Posted 6 months ago # -
Cool bro. Thanks very much, I'll try it out as soon as I get back to the physics part of my game.
Posted 6 months ago # -
Hi,
I am using this debugnode file, but I am experiencing the same problem with it. Once I change to retina display, the sprite which is linked to the body is at the right position, but the shape and body is just at the half coordinates.
How can I fix this? I could be able to size the shape to the right size, by scaling it up at the verts, but in objective chipmunk there is a simple body.syncednodes=sprite thing, which make the job and I cannot figure out how can I get the coordinates synced.
If I change the body position to double, then it moves the sprite as well by doubling its coordinates.
Thanks for helping me out.
Posted 3 months ago # -
Finally, I had an idea to search for the use of the syncednodes variable and I have found that the ChipmunkCocosBody.m is updated the nodes, but the display scale is not considered at all, so I have changed a line from
node.position = body->p
to
node.position = ccp(body->p.x/CC_CONTENT_SCALE_FACTOR(),body->p.y/CC_CONTENT_SCALE_FACTOR());
as this line is now changing the sprite position to the body location in points and not in pixels, I have to upscale the body and shape coordinates to the pixel coordinates. But this is quote easy, so my problem is solved. I just can hope that nothing else is effected by this in the physics engine. :)))
Posted 3 months ago #
Reply
You must log in to post.