xcode 如何使用 b2PolygonShape 顶点创建静态体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4361420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a static body with b2PolygonShape vertices
提问by Mattias
I can′t seem to create a b2PolygonShape with vertices in my Box2D Cocos2D project. I get no errors but nothing shows up at the screen.
我似乎无法在我的 Box2D Cocos2D 项目中创建一个带有顶点的 b2PolygonShape。我没有收到任何错误,但屏幕上没有显示任何内容。
How do you get a static body with b2PolygonShape vertices to work?
你如何让一个带有 b2PolygonShape 顶点的静态物体工作?
I would like to use it with a list set up like this:
我想将它与如下设置的列表一起使用:
b2Vec2 verts[] = {
b2Vec2(-194.5f / PTM_RATIO, 83.0f / PTM_RATIO),
b2Vec2(-118.5f / PTM_RATIO, 65.0f / PTM_RATIO),
b2Vec2(-77.5f / PTM_RATIO, 2.0f / PTM_RATIO),
b2Vec2(3.5f / PTM_RATIO, -59.0f / PTM_RATIO),
b2Vec2(62.5f / PTM_RATIO, -61.0f / PTM_RATIO),
b2Vec2(108.5f / PTM_RATIO, -63.0f / PTM_RATIO),
b2Vec2(138.5f / PTM_RATIO, -41.0f / PTM_RATIO),
b2Vec2(169.5f / PTM_RATIO, 11.0f / PTM_RATIO),
b2Vec2(184.5f / PTM_RATIO, 49.0f / PTM_RATIO),
b2Vec2(218.5f / PTM_RATIO, 51.0f / PTM_RATIO),
b2Vec2(219.5f / PTM_RATIO, -89.0f / PTM_RATIO),
b2Vec2(-174.5f / PTM_RATIO, -88.0f / PTM_RATIO)
};
回答by gixdev
The next step will specifying the vertices to shape
下一步将指定要塑造的顶点
b2PolygonShape shape;
int num = 4;
b2Vec2 vertices[] = {
b2Vec2(10.5f / PTM_RATIO, 10.6f / PTM_RATIO),
b2Vec2(11.8f / PTM_RATIO, 18.1f / PTM_RATIO),
b2Vec2(-11.9f / PTM_RATIO, 18.3f / PTM_RATIO),
b2Vec2(-10.5f / PTM_RATIO, 10.8f / PTM_RATIO)
};
shape.Set(vertices, num);
b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;