2015-04-07 3 views
2

J'utilise LiquidFun avec spritekit dans c objectif, Dans mon monde Box2d Je veux créer b2PolygonShape pour mon sprite, mon sprite est montré dans l'image ci-dessous:Set polygonShape à la forme hexagonale

enter image description here

J'ai essayé le code suivant:

b2PolygonShape polygonShape; 
b2Vec2 vertices[6]; 
for (int i = 0 ; i < 6 ; i++) { 
floate angle = -i/6.0 * 360 * DEGTORAD; 
vertices[i].Set(sinf(angle), cosf(angle)); 
} 

polygonShape.Set(vertices, 6); 

il fonctionne, mais il est plus petit que l'image de sprite et je ne peux pas voir les lignes de physique que je peux les voir dans le monde de la physique de spritekit en définissant:

SkView.showsPhysics = YES; 

Ma question est: Comment puis-je définir polygonShape exactement à ma taille d'image sprite?

Merci.

Répondre

2

C'est un sentiment génial quand personne ne répond à votre question, alors vous postez une réponse à votre question :)

Il était aussi simple que ces lignes:

b2Vec2 Verts[6]; 

    Verts[5].Set(-(sprite.frame.size.width/2)/DISPLAY_SCALE,0/DISPLAY_SCALE); 
    Verts[4].Set(-(0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,(sprite.frame.size.height/2)/DISPLAY_SCALE); 
    Verts[3].Set((0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,(sprite.frame.size.height/2)/DISPLAY_SCALE); 
    Verts[2].Set((sprite.frame.size.width/2)/DISPLAY_SCALE,0/DISPLAY_SCALE); 
    Verts[1].Set((0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,-(sprite.frame.size.height/2)/DISPLAY_SCALE); 
    Verts[0].Set(-(0.5*sprite.frame.size.width/2)/DISPLAY_SCALE,-(sprite.frame.size.height/2)/DISPLAY_SCALE); 

    b2PolygonShape Shape; 
    Shape.Set(Verts,num); 

Notez que:

const float DISPLAY_SCALE = 32.0;