0
在我的遊戲中,每隔2秒鐘我創建一個新身體,然後對這個Box2d身體施加衝動。Box2d,Cocos2D - 相同的身體,相同的衝動,但不同的效果
我的問題是衝動還是一樣,但身體在兩個方面的表現:
它慢慢地從下至上,或其他時間很快倒下
我想身體的行爲衝動之後也是如此,有可能嗎?
代碼:
- (void)newBullet
{
CGPoint touchedAt;
touchedAt.x = 184;
touchedAt.y = 1200;
bullet = [CCSprite spriteWithSpriteSheet:spriteSheet rect:CGRectMake(586, 719, 32, 32)];
[spriteSheet addChild: bullet z: 10 tag: 8];
bullet.position = ccp(touchedAt.x , touchedAt.y);
bullet.rotation = 90;
bulletBodyDef.type = b2_dynamicBody;
bulletBodyDef.position.Set(touchedAt.x/PTM_RATIO, touchedAt.y/PTM_RATIO);
bulletBodyDef.userData = bullet;
bulletBodyDef.angle = CC_DEGREES_TO_RADIANS(90);
bulletBody = _world->CreateBody(&bulletBodyDef);
b2CircleShape bulletShape;
bulletShape.m_radius = bullet.contentSize.width/PTM_RATIO/2;
b2FixtureDef bulletShapeDef;
bulletShapeDef.shape = &bulletShape;
bulletShapeDef.density = 0.0f;
bulletShapeDef.friction = 0.9f;
bulletShapeDef.restitution = 0.0f;
bulletShapeDef.isSensor = false;
bulletFixture = bulletBody->CreateFixture(&bulletShapeDef);
b2Vec2 force = b2Vec2(6.0f, 4.0f);
bulletBody->ApplyImpulse(force, bulletBody->GetPosition());
}
視頻(對不起,質量差,但你可以明白我的意思) http://vimeo.com/34215327
「直到你重置力量」Ups ..我忘了它。現在效果很好,非常感謝 – Dawid 2011-12-26 21:13:43