[英]swift iOS - When moving speed = 0 … image still spawns, how do I stop it?
I'm generating a 2D platform game where the object of the game is to jump over objects without causing a collision. 我正在生成一个2D平台游戏,其中游戏的目标是跳过对象而不会引起碰撞。 I've not written the code so once a collision takes place all scenery stops, that is except one object that spawns every second.
我没有编写代码,所以一旦发生碰撞,所有风景都会停止,除了一个每秒产生的物体。 This spawning object is added in update(currentTime: CFTimeInterval).
此生成对象已添加到update(currentTime:CFTimeInterval)中。
Would anyone know how I can include this object to stop spawning when the collision is detected? 有人知道在检测到碰撞时如何包含此对象以停止生成吗?
Thank you, 谢谢,
override func didMoveToView(view: SKView) {
moving.addChild(trees)
moving.addChild(crow)
moving.addChild(cat) //working (hero)
moving.addChild(sprite) //working background
moving.addChild(dummy) //working ground
moving.addChild(sprite) //working skyline
}
func addCrow() {
// lots of code here
moving.addChild(crow) // not working, still spawning when game stops
}
override func update(currentTime: CFTimeInterval) {
if currentTime - self.lastCrowAdded > 1 {
self.lastCrowAdded = currentTime + 1
self.addCrow() //wont allow me to change from self
}
}
func didBeginContact(contact: SKPhysicsContact) {
if( moving.speed > 0 ) {
moving.speed = 0;
} }
Simply change the condition in the if to also check if the speed is greater than 0. 只需在if中更改条件即可检查速度是否大于0。
Something like this: 像这样:
if currentTime - self.lastCrowAdded > 1 && moving.speed > 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.