2013-03-01 191 views
0

我有兩個對象...一個靜態和一個動態(它是一個球)。靜態對象具有多邊形形狀。 Sommethimes當我擊球時,球通過靜態物體:(我已經玩過密度和其他屬性,但沒有成功。有人知道我怎樣才能使靜態物體變得難以穿透。對象通過對象Box2d

// Create ball body 
b2BodyDef ballBodyDef; 
ballBodyDef.type = b2_dynamicBody; 
ballBodyDef.position.Set(110/2/PTM_RATIO, 300/PTM_RATIO); 
ballBodyDef.userData = playerCartoonSprite; 
ballBodyDef.bullet = YES; 
playerCartoonBody = localWorld->CreateBody(&ballBodyDef); 

// Create circle shape 
b2CircleShape circle; 
circle.m_radius = 10.0/PTM_RATIO; 

// Create shape definition and add to body 
b2FixtureDef ballShapeDef; 
ballShapeDef.shape = &circle; 
ballShapeDef.density = 0.0f; 
ballShapeDef.friction = 0.3f; 
ballShapeDef.restitution = 1.f; 
playerCartoonFixture = playerCartoonBody->CreateFixture(&ballShapeDef); 

// static polygon object 

    b2BodyDef bodyDef; 
    bodyDef.type = b2_staticBody; 

    int num = 6; 
    b2Vec2 verts[] = { 
     b2Vec2(8.6f/PTM_RATIO, 89.3f/PTM_RATIO), 
     b2Vec2(5.0f/PTM_RATIO, 81.7f/PTM_RATIO), 
     b2Vec2(10.5f/PTM_RATIO, 61.9f/PTM_RATIO), 
     b2Vec2(13.1f/PTM_RATIO, 9.1f/PTM_RATIO), 
     b2Vec2(17.3f/PTM_RATIO, 9.9f/PTM_RATIO), 
     b2Vec2(12.7f/PTM_RATIO, 70.6f/PTM_RATIO) 
    }; 

    b2PolygonShape boxShape; 
    boxShape.Set(verts, num); 
    b2FixtureDef fixtureDef; 
    fixtureDef.shape = &boxShape; 
    bodyDef.position.Set(teeterSprite.position.x/PTM_RATIO, teeterSprite.position.y/PTM_RATIO); 
    fixtureDef.shape = &boxShape; 
    m_bodyA = world->CreateBody(&bodyDef); 
    m_bodyA->CreateFixture(&fixtureDef); 
+1

提供你的代碼是解決方案,請。 – Pavel 2013-03-01 04:09:59

+0

我現在貼出我的代碼 – user232343 2013-03-01 14:34:59

回答