- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在开发一个 Sprite Kit 游戏,我有一个名为 hero 的节点,它会躲避接近的恶棍。我对 applyImpulse
的跳跃 Action 有疑问,在这种情况下,英雄可以反复跳跃和飞行,而不是躲避坏人。我使用了一个 bool 变量来更改定时器值的状态,使其在 3 秒内仅跳转一次,但这是行不通的。这是我的代码
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
if isGameOver == true {
self.restart()
}
if isstarted {
self.runAction(SKAction.playSoundFileNamed("jump.wav", waitForCompletion: false))
for touch: AnyObject in touches{
if jumpon == false { //hero has not jumped
let location = touch.locationInNode(self)
heroAction()
jumpon = true //hero jumped
}
}
} else {
isstarted = true
hero.stop()
hero.armMove()
hero.rightLegMove()
hero.leftLegMove()
treeMove()
villanMove()
let clickToStartLable = childNodeWithName("clickTostartLable")
clickToStartLable?.removeFromParent()
addGrass()
// star.generateStarWithSpawnTime()
}
}
func changeJump(){
jumpon = false // hero has landed
}
每秒都会调用函数更新,然后必须调用 changeJump
override func update(currentTime: CFTimeInterval) {
if isstarted == true {
let pointsLabel = childNodeWithName("pointsLabel") as MLpoints
pointsLabel.increment()
}
if jumpon == true { // checked everyframe that hero jumped
jumpingTimer = NSTimer.scheduledTimerWithTimeInterval(3, target: self, selector: "changeJump", userInfo: nil, repeats: true) // changing jump status
}
}
我应该如何更新我的代码,让英雄在三秒内只跳一次。提前致谢。
最佳答案
一些想法...
SKAction
而不是 NSTimer
。 SKAction
在您暂停/恢复场景和/或查看时适本地暂停/恢复update
方法每秒被调用约 60 次,而不是每秒调用一次update
中检查跳转状态还有一些代码...
if (!jumping) {
jumping = true
let wait = SKAction.waitForDuration(3)
let leap = SKAction.runBlock({
// Play sound and apply impulse to hero
self.jump()
})
let action = SKAction.group([leap, wait])
runAction(action) {
// This runs only after the action has completed
self.jumping = false
}
}
关于ios - 在 SpriteKit 节点上应用脉冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31810138/
如果之前已经回答过这个问题,我深表歉意,但我无法找到我想要的东西。 我有一个 Box2D 动态主体,我对其应用线性脉冲以将其变成射弹。因此,当我单击屏幕上的任意位置时,我希望 body 投影到触摸位置
脉冲神经网络和循环神经网络都可以对时变信息进行建模。但我不确定哪种模型相对于计算成本更好。使用更复杂的脉冲神经网络是否值得,或者循环神经网络是否可以在所需计算量少得多的情况下工作?脉冲网络收敛得更快吗
如何在我的应用程序运行且屏幕打开时使 LED 或轨迹球闪烁或闪烁?比如接到电话时? 谢谢 最佳答案 Android 具有仅在屏幕关闭时 LED 才会亮起的硬编码功能。这是在源代码 Notificati
我的目标是从健身手环获取数据(脉搏)Torntisc T1使用我的应用程序并独立处理来自手环的数据。 为了实现,我使用了 Xamarin 并找到了一个 Bluetooth LE plugin for
我很难理解 Wait()、Pulse()、PulseAll()。他们都能避免僵局吗?如果您解释一下如何使用它们,我将不胜感激? 最佳答案 简短版: lock(obj) {...} 是 Monitor.
我在 Cigarette Smoker Problem 工作. 我只应该使用 Monitor 类。没有信号/信号量。 (是的,这是给学校的,但不是家庭作业,只是我的实践测试的免费练习,我真的需要做好准
我想使用 bcm2835.h 和纯 C 语言通过 PWM 控制 LED 二极管。我的代码不起作用。我错过了什么? 我尝试过“gpio”控制台命令,它工作正常,所以我知道 LED 已连接到正确的端口。我
在 ARKit/SceneKit 中,当用户点击按钮时,我想对我的节点施加一个脉冲。我希望冲动来自当前用户的角度。这意味着节点将远离用户的视角。多亏了这段代码,我能够获得当前的方向/方向: func
我正试图在 SK/SWIFT 中“脉冲”一个 Sprite 。我尝试使用 For 循环和 .setScale 进行粗略尝试,但它们不起作用(没有错误 - 只是没有动画)。我觉得使用 SKActions
我想为以下绘图符号设置动画(脉冲、发光)。实现所需行为的最佳方法是什么。谢谢 最佳答案 您不能为绘图符号设置动画。您可以做的是在突出显示的点上放置一个绘图空间注释。创建一个自定义的 CPTLayer
在 Perl 下,在 Linux 上将 Serial::Device 作为文件打开会重置我的 Arduino,但我不希望它被重置。 Arduino 可以通过脉冲 DTR 来重置,因此默认打开串口设备必
我用 alsa 成功渲染了音频,但是我完全无法确定 channel 映射。正如各种消息来源所说,我调用 snd_pcm_get_chmap设置好硬件和软件参数并准备好设备后。 snd_config_g
我是一名优秀的程序员,十分优秀!