当移动速度= 0 ..图像仍然生成,我如何阻止它



我正在生成一款2D平台游戏,其中游戏的目标是跳过物体而不会造成碰撞。我没有编写代码,所以一旦发生碰撞,所有场景都会停止,除了一个物体每秒生成。这个衍生对象是在update(currentTime: CFTimeInterval)中添加的。

有人知道我怎么能包括这个对象停止产卵时碰撞检测?

谢谢你,

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;

}

只需改变if中的条件,同时检查速度是否大于0。

像这样:

if currentTime - self.lastCrowAdded > 1 && moving.speed > 0

最新更新