English 中文(简体)
b2 博茨瓦纳的面积与CCC Sprite不相同。
原标题:b2Body not same size as CCSprite?

I have noticed in my game that my b2Bodies are not the same size as my CCSprite s. This is the code I am using:

- (void)addBoxBodyForSprite:(CCSprite *)sprite {
    b2BodyDef spriteBodyDef;
    spriteBodyDef.type = b2_dynamicBody;
    spriteBodyDef.position.Set(sprite.position.x/CTM_RATIO, sprite.position.y/CTM_RATIO);
    spriteBodyDef.userData = sprite;
    b2Body *spriteBody = world->CreateBody(&spriteBodyDef);
    b2PolygonShape spriteShape;
    spriteShape.SetAsBox(sprite.contentSize.width/CTM_RATIO/2, sprite.contentSize.height/CTM_RATIO/2);
    b2FixtureDef spriteShapeDef;
    spriteShapeDef.shape = &spriteShape;
    spriteBody->CreateFixture(&spriteShapeDef);
}

我怎么会把这一守则推到仅仅无视CTM(PTM) 整体来看,也只是《共同标准》的确切规模? 我知道我本应使用PTM比率,但我的情况并非如此。

感谢!

www.un.org/Depts/DGACM/index_spanish.htm Edit1:

- (void)addBoxBodyForSprite:(CCSprite *)sprite {
    b2BodyDef spriteBodyDef;
    spriteBodyDef.type = b2_dynamicBody;
    spriteBodyDef.position.Set(sprite.position.x/(CC_CONTENT_SCALE_FACTOR() * CTM_RATIO), sprite.position.y/(CC_CONTENT_SCALE_FACTOR() * PTM_RATIO));
    spriteBodyDef.userData = sprite;
    b2Body *spriteBody = world->CreateBody(&spriteBodyDef);
    b2PolygonShape spriteShape;
    spriteShape.SetAsBox(sprite.boundingBox.size.width/(CC_CONTENT_SCALE_FACTOR() * PTM_RATIO)/2, sprite.boundingBox.size.height/(CC_CONTENT_SCALE_FACTOR() * PTM_RATIO)/2);
    b2FixtureDef spriteShapeDef;
    spriteShapeDef.shape = &spriteShape;
    spriteBody->CreateFixture(&spriteShapeDef);
}

www.un.org/Depts/DGACM/index_spanish.htm Edit2:

- (void)addBoxBodyForSprite:(CCSprite *)sprite {
    b2BodyDef spriteBodyDef;
    spriteBodyDef.type = b2_dynamicBody;
    spriteBodyDef.position.Set(sprite.position.x/CTM_RATIO, sprite.position.y/CTM_RATIO);
    spriteBodyDef.userData = sprite;
    b2Body *spriteBody = world->CreateBody(&spriteBodyDef);
    b2PolygonShape spriteShape;
    spriteShape.SetAsBox(sprite.boundingBox.size.width/CTM_RATIO, sprite.boundingBox.size.height/CTM_RATIO);
    b2FixtureDef spriteShapeDef;
    spriteShapeDef.shape = &spriteShape;
    spriteBody->CreateFixture(&spriteShapeDef);
}
最佳回答

我有两点看法:

  1. 你们在“Retina”屏幕上测试了它,但没有为你的间谍和形状设定分级系数。

  2. Try to use boundingBox property instead of contentSize.

第一例:

使用:(CC_CONTENT_SCALE_FACTOR()* PTM_RATIO);

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签