Box2D的:使用Box2D的
问题描述:
嗨,我要拍下面的代码Box2D的:使用Box2D的
-(void)shooter
{
LHSprite* laserSprite = [lh newPhysicalSpriteWithUniqueName:@"ball_1" ];
b2Body* laserBody = [laserSprite body];
[self addChild:laserSprite z:10];
NSAssert(laserSprite!=nil, @"Couldn't find devil1");
[laserSprite transformPosition:_hero.position];
b2Vec2 ballvel = laserBody->GetLinearVelocity();
ballvel.x = 16;
laserBody->SetLinearVelocity(ballvel);
}
上面的代码射精灵右侧我sprite..i使用,
拍摄左侧,但我要拍左侧。即使我改变了ballvel.x = 16; to ballvel.x = -16;它还是向右side..please帮助拍摄
我是新来的Box2D所以请温柔:)
答
语法是这样的:
// 1。首先计算移动角度。 // 2。计算命中的力量(力量)。
b2Vec2 force;
force.x = cos(angle * M_PI/180) * power;
force.y = sin(angle * M_PI/180) * power;
laserBody->ApplyLinearImpulse(force, laserBody->GetPosition()); //or SetLinearVelocity
答
其实我的子弹精灵并没有issensor ...所以它击中英雄精灵和它再次回到正确的side..my坏..embarassing:d
这是否说明为什么没有按-16”工作? – 2012-07-12 14:44:59
权力的价值应该是什么?有些近似? – vishnu 2012-07-12 14:53:47