我有一个方向键和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