我有一個方向鍵和2個按鈕的遊戲手柄。所有這些都是數字(不是模擬)。Cocos2d。降低火災(子彈)的速度(速度)?
我處理自己的事件過程:
-(void)gamepadTick:(float)delta
{
...
if ([gamepad.B active]) {
[ship shoot];
}
...
}
而且我通過一個命令調用它:
[self schedule:@selector(gamepadTick:) interval:1.0/60];
[船拍]調用從武器級拍攝功能:
-(void)shoot
{
Bullet *bullet = [Bullet bulletWithTexture:bulletTexture];
Ship *ship = [Ship sharedShip];
bullet.position = [ship getWeaponPosition];
[[[CCDirector sharedDirector] runningScene] addChild:bullet];
CGSize winSize = [[CCDirector sharedDirector] winSize];
int realX = ship.position.x;
int realY = winSize.height + bullet.contentSize.height/2;
CGPoint realDest = ccp(realX, realY);
int offRealX = realX - bullet.position.x;
int offRealY = realY - bullet.position.y;
float length = sqrtf((offRealX*offRealX) + (offRealY*offRealY));
float velocity = 480/1; // 480pixels/1sec
float realMoveDuration = length/velocity;
[bullet runAction:[CCSequence actions:[CCMoveTo actionWithDuration:realMoveDuration position:realDest],
[CCCallFuncN actionWithTarget:self selector:@selector(bulletMoveFinished:)], nil]];
}
-(void)bulletMoveFinished:(id)sender
{
CCSprite *sprite = (CCSprite *)sender;
[[[CCDirector sharedDirector] runningScene] removeChild:sprite cleanup:YES];
}
問題是武器射出太多的子彈。是否可以減少它們的數量,而無需使用每個按鈕和方向鍵分開的定時器和功能?
+1,但我發現同樣的事情的具體例子。如果沒有人想嘗試,那麼我會發布它 – Gargo 2012-04-03 22:00:21