box2d - vertices smaller than sprite when rendered on iPhone screen -
box2d - vertices smaller than sprite when rendered on iPhone screen -
i using vertex helper edges of sprites. using cocos2d + box2d on iphone. problem getting debug draw on device testing on comes vertices rendered or shown smaller sprites after tracing edges of sprites , using same sprite.
ok here screen shot of problem!
the greenish triangle supposed fit edges of sprite. code used:
this glesdebugdraw code
- (void)setupdebugdraw { debugdraw = new glesdebugdraw(ptm_ratio* [[ccdirector shareddirector] contentscalefactor]); world->setdebugdraw(debugdraw); debugdraw->setflags(b2debugdraw::e_shapebit);
}
#import "box2dsprite.h" @interface stalag :box2dsprite { b2world *world; } - (id)initwithworld:(b2world *)world atlocation:(cgpoint)location; @end #import "stalag.h" @implementation stalag - (void)createbodyatlocation:(cgpoint)location { b2bodydef bodydef; bodydef.type = b2_staticbody; bodydef.position = b2vec2(location.x/ptm_ratio, location.y/ptm_ratio); self.body = world->createbody(&bodydef); body->setuserdata(self); b2polygonshape shape; int num = 8; b2vec2 verts[] = { b2vec2(36.8f / 100.0, -79.2f / 100.0), b2vec2(10.3f / 100.0, 33.2f / 100.0), b2vec2(1.8f / 100.0, 80.6f / 100.0), b2vec2(-4.6f / 100.0, 84.5f / 100.0), b2vec2(-8.5f / 100.0, 80.3f / 100.0), b2vec2(-22.6f / 100.0, 19.4f / 100.0), b2vec2(-31.8f / 100.0, -45.6f / 100.0), b2vec2(-37.5f / 100.0, -75.7f / 100.0) }; shape.set(verts, num); b2fixturedef fixturedef; fixturedef.shape = &shape; fixturedef.density = 1000.0; body->createfixture(&fixturedef); } - (id)initwithworld:(b2world *)theworld atlocation:(cgpoint)location { if ((self = [super init])) { world = theworld; [self setdisplayframe:[[ccspriteframecache sharedspriteframecache] spriteframebyname:@"hill.png"]]; gameobjecttype = kstalaguptype; [self createbodyatlocation:location]; } homecoming self; } @end
please can tell me do , doing wrong?
thanks
when specifying vertices coordinates dividing "magic number" 100. pixeltometersratio (ptm_ratio in cocos examples). using box2d debug draw. , when creating debug draw class must pass ptm_ratio in it's constructor. think passing number there (not 100). solve problem ?
cocos2d-iphone box2d
Comments
Post a Comment