【问题标题】:My sequence action does not work Swift Sprite Kit我的序列动作不起作用 Swift Sprite Kit
【发布时间】:2014-12-26 11:07:18
【问题描述】:

我一直在尝试这样做很长时间,我想做的是让“bar1”移动到屏幕底部,然后两秒钟后,bar2 下降然后 bar3 等,我的问题是当我运行我的代码,我看到的只是 bar1 在我等待的屏幕上向下移动,没有任何反应。

这是我的代码:

    //
//  PlaysScene.swift
//  Pocket Rocket3
//
//  Created by Lucas Farleigh on 27/11/2014.
//  Copyright (c) 2014 Lucas Farleigh. All rights reserved.
//

import spriteKit

class PlayScene:SKScene {
    //declaring the node in this scene!
    let background = SKSpriteNode(imageNamed: "background")

    let bar1 = SKSpriteNode(imageNamed:"bar1")

    let bar2 = SKSpriteNode(imageNamed:"bar2")

    let bar3 = SKSpriteNode(imageNamed:"bar3")

    let bar4 = SKSpriteNode(imageNamed:"bar4")

    let bar5 = SKSpriteNode(imageNamed:"bar5")


    override func didMoveToView(view: SKView) {
        let delay = SKAction.waitForDuration(NSTimeInterval(2.5))
        let actionmove = SKAction.moveTo(CGPointMake(CGRectGetMidX(self.frame),0), duration:13)
        let sequence = SKAction.sequence([actionmove ,delay])
        actionmove.timingMode = SKActionTimingMode.EaseOut
        var num1 = CGFloat(50)
        var num2 = 1
        bar2.runAction(sequence)
        bar1.runAction(sequence)
        bar3.runAction(sequence)
        addChild(bar2)
        addChild(bar3)
        addChild(bar4)
        addChild(bar5)




        actionmove.timingMode = SKActionTimingMode.EaseOut
            bar1.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMaxY(self.frame))
        background.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame))

        //doing the background stuff
        background.yScale = 2.0
        background.xScale = 3.0
        addChild(background)
                //doing the the bar stuff
         bar1.xScale = 2.5
       addChild(bar1)
        println("hello!!!!")


}


    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {



    }
}

提前致谢!

【问题讨论】:

    标签: swift sprite-kit


    【解决方案1】:

    首先,我没有看到您将bar1 添加到您的场景中,所以请务必这样做。

    您只看到一个条形的原因是它们都从相同的位置开始,并且它们都同时以相同的速度移动。他们正在互相覆盖。

    有几种方法可以让它们按顺序移动,但一种方法是在每个动作结束时使用完成块来调用下一个动作。

    addChild(bar1)
    addChild(bar2)
    addChild(bar3)
    
    bar1.runAction(sequence, completion: {
        bar2.runAction(sequence, completion: {
            bar3.runAction(sequence)
        }
    }
    

    【讨论】:

    • 谢谢,我只希望它比上一个动作运行四分之一的距离
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多