iphone - Box2d fixture and body out of sync on retina display -


I am trying to work on the Cocos 2D / Box 2D game on the iPad, iPhone and iPhone retina. My problem is that not line up on the stability and body retina simulator, click on to get the screenshot below (as a new stackoverflow member, it will not be allowed to post my screenshot here).

(Ignore different shapes, I want to line up 4 corners) I've done quite a bit of research on this in the last few days, and the closest I found It was:

But the solution does not seem to work in my case with PTM_RATIO and CC_CONTENT_SCALE_FACTOR (). I think what to do with this fact that I do not load a picture from my file into my phantom. Most of the solutions to this problem are based on load-holding HD image files for retina displays, but I do not want to use the files in my game at all. I basically want to polygons at runtime to draw myself, so

My code looks like this:

  - (CCSprite *) addSprite {CGSize Contextsize = CGSizeMake (200, 200); UIGraphicsBeginImageContext (contextsize); CGContextRef Reference = UIGraphicsGetCurrentContext (); CGContextFlush (reference); CGContextSetAllowsAntialiasing (context, true); CGContextTranslateCTM (references, 0, contextsize.height); CGContextScaleCTM (Reference, 1.0, -1.0); CGColorSpaceRef colorpace = CGColorSpaceCreateDeviceRGB (); CGFloat components [] = {0.0, 0.0, 1.0, 1.0}; CGColorRef color = CGColorCreate (colorspace, component); CGContextSetStrokeColorWithColor (reference, color); UIBezierPath * aPath; aPath = [UIBezierPath bezierPathWithArcCenter: under CGPointMake (100, 100): 100 startAngle: 0 endAngle: 1.57 clockwise: YES]; [Epath ADARC with center: CGPointMake (100, 100) Radius: 50 Startgang: 1.57 Andangle: 0 clockwise: no]; [Epath stroke]; CGContextStrokePath (reference); CGColorSpaceRelease (colorspace); CGColorRelease (color); UIImage * graphImage = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); CCTEext 2D * Texx = [[[CCTitact 2D ALL] Init with Image: Graph Images] AutoWrecks]; CCSpract * Phantom [[CCSprakash Praveenvita: Technique]; Return Phantom; } - (void) addFixture: (CCSprite *) fixsprite {b2Vec2 arcdots [] = {b2Vec2 (50.0f / PTM_RATIO, 0.0f / PTM_RATIO), b2Vec2 (100.0f / PTM_RATIO, 0.0f / PTM_RATIO), b2Vec2 (0.0f / PTM_RATIO, 100.0F / PTM_RATOOO), B2VK2 (0.0F / PT_RATOO, 50.0F / PTM_RATOIT)}; B2 PolygonSpeed ​​p_shape; B2 FixExtif fixture Def; B2BodyDef bodyDef; BodyDef.type = b2_kinematicBody; BodyDef.position.Set (100 / PTM_RATIO, 100 / PTM_RATIO); BodyDef.userData = fixsprite; B2Body * body = world-> CreateBody (& bodyDef); P_shape.Set (arcdots, 4); FixtureDef.shape = & amp; P_shape; Stability Def Density = 1.0 F; Stability Definition = 0.3 F; Body & gt; CreateFixture (& fixtureDef); }   

And I call these functions from the main routine the following way:

  CCSprite * sprite2 = [addSprite manually]; Sprite2.position = CCP (0, 0); [Self add cats: sprite2 z: 0]; [Self added effect: sprite2];   

I do Panktian you went written representative file:

  if (! [Director able Krentina display: Yes]) CCLOG (@ "retina display supported is not" );   

Please tell me if more information is needed. And please be kind, I'm only starting to learn this. Thanks for your time.

After

Unless otherwise noted, all coordinates (and most of UIKit) are given in Cocos2d In, on a pixel not retina display device, you still have a point solution of 480x320 (960x640 pixels) point.

As follows: When you calculate in real pixels, multiply or divide by CC_CONTENT_SCALE_FACTOR. If you deal with point coordinates, do not do anything since you are translating your own policies. You believe that whether you use actual pixel coordinates or if you use OpenGL directly , Then you will work with pixel coordinates.

I'm not sure if you do not use Cocos 2D to render your content, enabling retina display mode does anything for you. Finally, a common misconception is that the box is using 2D world point coordinates and it should be converted to pixel or vice versa. Neither is the case. Box 2D world is completely unaware of a specific coordination system. Use PTM_RATIO are within reasonable ranges for sure is used Box2D Coordinate Box 2D engine, because it works best with objects of 1 m size / diameter, and 0.1 in most object diameter Must have up to 10 meters

Comments