Iphone 设置边缘问题Cocos 2D
我正在尝试用Cocos2D和Box 2D制作一个游戏 但当我尝试放置“setAsEdge”时,它只是告诉我该函数不存在 我的代码:Iphone 设置边缘问题Cocos 2D,iphone,cocos2d-iphone,Iphone,Cocos2d Iphone,我正在尝试用Cocos2D和Box 2D制作一个游戏 但当我尝试放置“setAsEdge”时,它只是告诉我该函数不存在 我的代码: // Define the ground body. b2BodyDef groundBodyDef; groundBodyDef.position.Set(0, 0); // bottom-left corner // Call the body factory which allocates memory for the ground
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
groundBody = world->CreateBody(&groundBodyDef);
// Define the ground box shape.
b2PolygonShape groundBox;
// bottom
groundBox.SetAsEdge(b2Vec2(0,FLOOR_HEIGTH/PTM_RATIO), b2Vec2(screenSize.width*2.0f/PTM_RATIO,FLOOR_HEIGTH/PTM_RATIO));
groundBody->CreateFixture(&groundBox,0);
// top
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width*2.0f/PTM_RATIO,screenSize.height/PTM_RATIO));
groundBody->CreateFixture(&groundBox,0);
// left
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0));
groundBody->CreateFixture(&groundBox,0);
// right
groundBox.SetAsEdge(b2Vec2(screenSize.width*2.0f/PTM_RATIO,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width*2.0f/PTM_RATIO,0));
groundBody->CreateFixture(&groundBox,0);
错误:“b2PolygonShape”中没有名为“SetAsEdge”的成员。我使用的是Cocos 2D 1.0.1稳定版
感谢大家您正在使用Box2D 2.2.1,与Cocos2D v1.0.1(使用Box2D v2.1.2)中的Box2D版本相比,它的API已经发生了变化。我想你用的是Cocos2D 2.0 alpha?如果是这样的话,它应该附带更新的Xcode项目模板,因此您可能希望安装这些模板并基于新模板创建一个项目 下面是我如何使用带有4个形状的实体来设置边界边界框:
// for the screenBorder body we'll need these values
CGSize screenSize = [CCDirector sharedDirector].winSize;
float widthInMeters = screenSize.width / PTM_RATIO;
float heightInMeters = screenSize.height / PTM_RATIO;
b2Vec2 lowerLeftCorner = b2Vec2(0, 0);
b2Vec2 lowerRightCorner = b2Vec2(widthInMeters, 0);
b2Vec2 upperLeftCorner = b2Vec2(0, heightInMeters);
b2Vec2 upperRightCorner = b2Vec2(widthInMeters, heightInMeters);
// Define the static container body, which will provide the collisions at screen borders.
b2BodyDef screenBorderDef;
screenBorderDef.position.Set(0, 0);
b2Body* screenBorderBody = world->CreateBody(&screenBorderDef);
b2EdgeShape screenBorderShape;
// Create fixtures for the four borders (the border shape is re-used)
screenBorderShape.Set(lowerLeftCorner, lowerRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(lowerRightCorner, upperRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperRightCorner, upperLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperLeftCorner, lowerLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
或者,获取Preview 5(明天提供)并查看Physics-Box2D模板项目。我做了运行Box2D v2.2.1应用程序所需的所有更改,包括Box2D调试绘图类所需的更改。我还主持了最新的。您正在使用Box2D 2.2.1,与Cocos2D v1.0.1(使用Box2D v2.1.2)中的Box2D版本相比,它的API发生了变化。我想你用的是Cocos2D 2.0 alpha?如果是这样的话,它应该附带更新的Xcode项目模板,因此您可能希望安装这些模板并基于新模板创建一个项目 下面是我如何使用带有4个形状的实体来设置边界边界框:
// for the screenBorder body we'll need these values
CGSize screenSize = [CCDirector sharedDirector].winSize;
float widthInMeters = screenSize.width / PTM_RATIO;
float heightInMeters = screenSize.height / PTM_RATIO;
b2Vec2 lowerLeftCorner = b2Vec2(0, 0);
b2Vec2 lowerRightCorner = b2Vec2(widthInMeters, 0);
b2Vec2 upperLeftCorner = b2Vec2(0, heightInMeters);
b2Vec2 upperRightCorner = b2Vec2(widthInMeters, heightInMeters);
// Define the static container body, which will provide the collisions at screen borders.
b2BodyDef screenBorderDef;
screenBorderDef.position.Set(0, 0);
b2Body* screenBorderBody = world->CreateBody(&screenBorderDef);
b2EdgeShape screenBorderShape;
// Create fixtures for the four borders (the border shape is re-used)
screenBorderShape.Set(lowerLeftCorner, lowerRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(lowerRightCorner, upperRightCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperRightCorner, upperLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
screenBorderShape.Set(upperLeftCorner, lowerLeftCorner);
screenBorderBody->CreateFixture(&screenBorderShape, 0);
或者,获取Preview 5(明天提供)并查看Physics-Box2D模板项目。我做了运行Box2D v2.2.1应用程序所需的所有更改,包括Box2D调试绘图类所需的更改。我也在主持最新的。使用
setAsBox(0,0,b2vec2(0,0),0);
使用
使用b2EdgeShape而不是b2PolygonShape,例如:
b2EdgeShape groundBox;
groundBox.Set( b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO,0));
使用b2EdgeShape而不是b2PolygonShape,例如:
b2EdgeShape groundBox;
groundBox.Set( b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO,0));