简体   繁体   English

swift iOS-当移动速度= 0…图像仍然产生时,如何停止它?

[英]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.

相关问题 如何创建产生可移动图像的按钮? iOS 5 - How to create a button that spawns a movable image? iOS 5 图像未放大时如何停止移动图像? - how to stop moving image when image is not zoomed in? iOS-我的TextBox在单击时会生成常规键盘,如何设置它以生成数字键盘? - iOS - My TextBox spawns a regular keyboard when clicked, how can I set it to spawn a numeric keyboard? 在iOS中录制视频时如何检测设备的移动速度 - How to detect moving speed of device when recording video in ios iOS Swift-使用滑块移动图像 - iOS Swift - moving image with slider 对象停止移动-UIDynamics和Swift iOS - Objects stop moving - UIDynamics and Swift iOS 如何使用Swift在iOS中使用透明设置背景图片? - How do I set a background image in iOS with transparency using Swift? 如何在 iOS Swift 中向图像添加文本? - How do I add text to an image in iOS Swift? Swift-如果与以前的图像相同,如何阻止表重新加载图像? - Swift - How do I stop a table from reloading an image if it's the same image as before? 当使用UIPanGestureRecognizer垂直移动UILabel时,如何阻止它们在任一方向上走得太远? - When moving a UILabel vertically with a UIPanGestureRecognizer, how do I stop them from going too far in either direction?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM