我在objective c中使用LiquidFun和spritekit,在我的Box2d世界中,我想为我的sprite创建b2PolygonShape,我的sprite如下图所示:

我尝试了以下代码:
b2PolygonShape polygonShape;
b2Vec2 vertices[6];
for (int i = 0 ; i < 6 ; i++) {
floate angle = -i/6.0 * 360 * DEGTORAD;
vertices[i].Set(sinf(angle), cosf(angle));
}
polygonShape.Set(vertices, 6);它可以工作,但它比精灵的图像小,我看不到物理线,因为我可以在spritekit的物理世界通过设置:
SkView.showsPhysics = YES;我的问题是:如何将polygonShape设置为我的精灵图像大小?
谢谢。
发布于 2015-04-07 20:58:13
当没有人回答你的问题,然后你发布你的问题的答案时,这是一种可怕的感觉:)
它就像下面这几行一样简单:
b2Vec2 Verts[6];
Verts[5].Set(-(sprite.frame.size.width/2)/DISPLAY_SCALE,0/DISPLAY_SCALE);
Verts[4].Set(-(0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,(sprite.frame.size.height/2)/DISPLAY_SCALE);
Verts[3].Set((0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,(sprite.frame.size.height/2)/DISPLAY_SCALE);
Verts[2].Set((sprite.frame.size.width/2)/DISPLAY_SCALE,0/DISPLAY_SCALE);
Verts[1].Set((0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,-(sprite.frame.size.height/2)/DISPLAY_SCALE);
Verts[0].Set(-(0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,-(sprite.frame.size.height/2)/DISPLAY_SCALE);
b2PolygonShape Shape;
Shape.Set(Verts,num);请注意:
const float DISPLAY_SCALE = 32.0;https://stackoverflow.com/questions/29486650
复制相似问题