我有一个精灵数组,用户可以在ccTouchesMoved中移动。 当用户选择其中一个精灵(通过触摸它),他们可以使用ccTouchesMoved方法旋转精灵,直到取消选择旋转功能。
精灵正确旋转,但我还有另一个方法,在精灵周围创建边缘,使它们具有碰撞等功能。
当调用此方法时,它会重置所有精灵的旋转角度,将它们设置为0,我不知道为什么。
精灵正确旋转,但我还有另一个方法,在精灵周围创建边缘,使它们具有碰撞等功能。
当调用此方法时,它会重置所有精灵的旋转角度,将它们设置为0,我不知道为什么。
for (CCSprite *sprite in bounceBarriers)
{
curBarrier = sprite;
curBarrier.rotation = 20;
[self bounceCreator];
}
//bounceCreator:
b2BodyDef barrierBodyDef;
barrierBodyDef.type = b2_staticBody;
barrierBodyDef.position.Set(curBarrier
.position.x/PTM_RATIO, curBarrier.position.y/PTM_RATIO);
barrierBodyDef.userData = curBarrier; //the userData is set to the current sprite
_body2 = _world->CreateBody(&barrierBodyDef);
barrierBodyDef.position.Set(0,0);
b2Body *barrierBody;
barrierBody = _world->CreateBody(&barrierBodyDef);
b2EdgeShape barrierEdge;
b2FixtureDef barrierShapeDef;
barrierShapeDef.shape = &barrierEdge;
barrierShapeDef.friction = 1.0f;
barrierShapeDef.restitution = 1.0f;
barrierEdge.Set(b2Vec2((curBarrier.position.x-70)/PTM_RATIO, (curBarrier.position.y+10)/PTM_RATIO),
b2Vec2((curBarrier.position.x-70)/PTM_RATIO, (curBarrier.position.y-10)/PTM_RATIO));
barrierBody->CreateFixture(&barrierShapeDef);
barrierEdge.Set(b2Vec2((curBarrier.position.x-70)/PTM_RATIO, (curBarrier.position.y-10)/PTM_RATIO),
b2Vec2((curBarrier.position.x+70)/PTM_RATIO, (curBarrier.position.y-10)/PTM_RATIO));
barrierBody->CreateFixture(&barrierShapeDef);
barrierEdge.Set(b2Vec2((curBarrier.position.x+70)/PTM_RATIO, (curBarrier.position.y-10)/PTM_RATIO),
b2Vec2((curBarrier.position.x+70)/PTM_RATIO, (curBarrier.position.y+10)/PTM_RATIO));
barrierBody->CreateFixture(&barrierShapeDef);
barrierEdge.Set(b2Vec2((curBarrier.position.x+70)/PTM_RATIO, (curBarrier.position.y+10)/PTM_RATIO),
b2Vec2((curBarrier.position.x-70)/PTM_RATIO, (curBarrier.position.y+10)/PTM_RATIO));
barrierBody->CreateFixture(&barrierShapeDef);