我只调用了 body->CreateFixture(&fixtureDef) 一次,但 Testbed 继续创建实体。这是我的代码:
#ifndef FOOTEST_H
#define FOOTEST_H
#define DEGTORAD 0.0174532925199432957f
#define RADTODEG 57.295779513082320876f
class FooTest : public Test
{
public:
FooTest() { } //do nothing, no scene yet
void Step(Settings* settings)
{
//run the default physics and rendering
Test::Step(settings);
b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
myBodyDef.position.Set(0, 20);
b2Body *dynamicBody = m_world->CreateBody(&myBodyDef);
b2PolygonShape polygonShape;
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &polygonShape;
myFixtureDef.density = 1;
for(int i=0;i<4;i++){
b2Vec2 pos(sinf(i*90*DEGTORAD), cos(i*90*DEGTORAD));
polygonShape.SetAsBox(1, 1, pos, 0);
dynamicBody->CreateFixture(&myFixtureDef);
}
myBodyDef.type = b2_staticBody;
myBodyDef.position.Set(0, 0);
b2Body *staticBody = m_world->CreateBody(&myBodyDef);
b2EdgeShape edgeShape;
edgeShape.Set( b2Vec2(-15,0), b2Vec2(15,3) );
myFixtureDef.shape = &edgeShape;
staticBody->CreateFixture(&myFixtureDef);
}
static Test* Create()
{
return new FooTest;
}
};
#endif
我正在关注本教程: iForce2D 本教程的屏幕截图仅显示了已创建夹具的一个实例。我在这里错过了什么吗?