iphone的cocos2d世界优势

时间:2011-11-07 09:42:57

标签: iphone cocos2d-iphone box2d

我设置了我的游戏世界(cocos2d-b2world)这样的边缘:

-(void)worldEdge
{
    CGSize winSize = [CCDirector sharedDirector].winSize;
    b2BodyDef groundBodyDef;
    groundBodyDef.position.Set(0,0);
    b2Body *groundBody = world->CreateBody(&groundBodyDef);
    b2PolygonShape groundBox;
    b2FixtureDef boxShapeDef;
    boxShapeDef.shape = &groundBox;
    groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0));
    groundBody->CreateFixture(&boxShapeDef);
    groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(0, winSize.height/PTM_RATIO));
    groundBody->CreateFixture(&boxShapeDef);
    groundBox.SetAsEdge(b2Vec2(0, winSize.height+100/PTM_RATIO), b2Vec2(winSize.width+100/PTM_RATIO, winSize.height+100/PTM_RATIO));
    groundBody->CreateFixture(&boxShapeDef);
    groundBox.SetAsEdge(b2Vec2(winSize.width+100/PTM_RATIO, winSize.height+100/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO, 0));
    groundBody->CreateFixture(&boxShapeDef);
}

我的iphone处于纵向模式,有些如何,我没有在顶部的边缘,但在地面上我做,而在左侧我有但在右侧我不。

似乎我不了解世界边缘的某些东西,有人可以帮助我改变它以使底部“边缘自由”,但右边会有优势吗?

非常感谢。

2 个答案:

答案 0 :(得分:1)

在cocos2d ccp(0,0)中放置在左下角。

 -(void)worldEdge
{
CGSize winSize = [CCDirector sharedDirector].winSize;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
b2Body *groundBody = world->CreateBody(&groundBodyDef);
b2PolygonShape groundBox;
b2FixtureDef boxShapeDef;
boxShapeDef.shape = &groundBox;
groundBox.SetAsEdge(b2Vec2(0,winSize.height/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO));//for Top edge
groundBody->CreateFixture(&boxShapeDef);
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(0, winSize.height/PTM_RATIO));//for Left edge
groundBody->CreateFixture(&boxShapeDef);
groundBox.SetAsEdge(b2Vec2(winSize.width/PTM_RATIO, 0), b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO));//for Right
groundBody->CreateFixture(&boxShapeDef);

groundBody->CreateFixture(&boxShapeDef);
}

答案 1 :(得分:0)

我已经知道了。 正如我所描述的答案,我就是这样做的:

// bottom edge
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(width,0));
groundBody->CreateFixture(&groundBox);

// top edge
groundBox.SetAsEdge(b2Vec2(0,height), b2Vec2(width,height));
groundBody->CreateFixture(&groundBox);

// left edge
groundBox.SetAsEdge(b2Vec2(0,height), b2Vec2(0,0));
groundBody->CreateFixture(&groundBox);

// right edge
groundBox.SetAsEdge(b2Vec2(width,height), b2Vec2(width,0));
groundBody->CreateFixture(&groundBox);

当在每个边缘时,我们有:(从点到点)每个点都是一个向量。