- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有方向键和 2 个按钮的游戏 handle 。所有这些都是数字的(不是模拟的)。
我有一个处理他们的事件的程序:
-(void)gamepadTick:(float)delta
{
...
if ([gamepad.B active]) {
[ship shoot];
}
...
}
我通过命令调用它:
[self schedule:@selector(gamepadTick:) interval:1.0 / 60];
[船舶射击]从Weapon类调用射击函数:
-(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];
}
问题是武器发射了太多子弹。是否可以减少它们的数量,而无需编写使用每个按钮和方向板单独的计时器和功能?
最佳答案
使用 Delta 来跟踪拍摄之间的时间,并且仅在 Delta 增加一定量时才进行拍摄。这是一种常见的处理方式,但您并不希望每一帧都这样做。
您需要保留一个 iVar 计数器来记录所耗时,在每次拍摄时将其增加 Delta,然后测试所耗时量,看看它是否满足您所需的间隔阈值;如果是,则射击并将耗时重置为 0。
关于iphone - Cocos2d。降低射击(子弹)的速度(速率)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9957593/
我需要实现射击机制。我需要射弹的连续运动,但我无法对其进行编码。此时,当我按下空格键时,程序就会卡住。我们将不胜感激。 from tkinter import * # creates window w
我遇到了一个问题。如果有任何帮助,我将不胜感激。 我正在尝试从玩家位置射击到鼠标点击位置。代码没有给我任何错误,根据我的逻辑,它应该可以工作,但它没有 它创建了项目符号对象,仅此而已。 //Bulle
我正在用 Java 开发一款 Android 游戏,其中我将有一个 Sprite 跟随用户的手指,并且应该每秒发射一颗子弹。换句话说,我试图附加一个每秒向上移动的位图。位图从主要角色 Sprite 的
我需要在 JQuery 中使用 focusin 和 focusout 触发器。我将它与 Bootstrap Popovers 一起使用。 目前,由于我认为某些奇怪的原因,它不起作用。 这有什么问题吗?
我是一名优秀的程序员,十分优秀!