2012-07-12 59 views
0

嗨,我要拍下面的代碼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所以請溫柔:)

回答

0

語法是這樣的:

// 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 
+0

這是否說明爲什麼沒有按-16」工作? – 2012-07-12 14:44:59

+0

權力的價值應該是什麼?有些近似? – vishnu 2012-07-12 14:53:47

0

其實我的子彈精靈並沒有issensor ...所以它擊中英雄精靈和它再次回到正確的side..my壞..embarassing:d