Spritekit skaction scaleby导致节点消失

时间:2016-08-11 13:51:59

标签: swift sprite-kit skaction

我一直在尝试在Spritekit中使用scaleBy动作,并且在点击屏幕时节点消失时得到奇怪的结果,它应该永远保留。标签就在那里看看需要多长时间。我试过一个设备/模拟器。 我想这可能是因为我没有使用其他动作来反转尺寸,而是将其改为特定尺寸,因为这是我想要的尺寸,但我不确定。

节点消失后,这只是一段简单的代码,有谁知道为什么?以及如何更改代码以阻止它消失,以便我可以使用Skaction scaleby功能。我已经提供了所有代码,因此您可以尝试一下。感谢

以下是所有代码:

class GameScene: SKScene {


`let sprite = SKSpriteNode(imageNamed:"Spaceship")
  var timerSecs = 8.5
  var setScaleXY = 8.0
  let label = SKLabelNode(fontNamed: "Chalkduster")
  var tapped : Int = 0 {
    didSet{
      label.text = "\(tapped)"
  }
  }
  var action = SKAction()

 override func didMoveToView(view: SKView) {
        /* Setup your scene here */
    label.position = CGPoint(x: 500, y: 500)
    label.fontColor = UIColor.blueColor()
    addChild(label)
    sprite.position = CGPoint(x: frame.size.width / 2, y:    frame.size.height / 2)
    sprite.size = CGSize(width: 60, height: 60)
    self.addChild(sprite)


    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
       /* Called when a touch begins */

        for touch in touches {
            let location = touch.locationInNode(self)
            sprite.removeAllActions()
            sprite.size = CGSize(width: 60, height: 60)

        }
    }



 override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
   action = SKAction.scaleBy(CGFloat(self.setScaleXY), duration: self.timerSecs)
   tapped += 1

changeSize()
   sprite.runAction(action)

 }



func changeSize() {
    if tapped == 2 {
      setScaleXY = 20.0
    } else if tapped < 10 {
      setScaleXY = 15.0
    }

    else if tapped > 20 {
      setScaleXY = 25.0
    }
    else if tapped > 40 {
      setScaleXY = 15.0
    }
    else {
      setScaleXY = 20.0
    }
  }

0 个答案:

没有答案