我如何定位我的" + 1"动画在哪里我的节点与Swift中的硬币接触?

时间:2015-03-24 14:23:52

标签: ios swift skspritenode

我有这个代码,当我的英雄节点与硬币接触时," + 1"动画运行。现在,每当英雄节点与硬币接触时,它就在屏幕中间。我希望该动画的位置在英雄节点与硬币接触的任何地方。我该怎么做?谢谢!

        let addCoinsLabel = SKSpriteNode(imageNamed: "plusone")
        addCoinsLabel.setScale(0.8)
        addCoinsLabel.zPosition = 200
        addCoinsLabel.position = CGPoint(x: CGRectGetMidX(self.frame), y: self.frame.size.height*0.7)
        self.addChild(addCoinsLabel)

        let actionLabelfadeIn = SKAction.fadeInWithDuration(0.3)
        let actionLabelFadeOut = SKAction.fadeOutWithDuration(0.3)
        let actionLabelMove = SKAction.moveBy(CGVector(dx: 0.0, dy: 100), 
        duration: 0.3)
        let actionRemoveFromParent = SKAction.removeFromParent()

        let sequence = SKAction.sequence([actionLabelfadeIn, 
        actionLabelMove, actionLabelFadeOut, actionRemoveFromParent])

        addCoinsLabel.runAction(sequence)

1 个答案:

答案 0 :(得分:0)

addCoinsLabel.position = CGPoint(x: coin.position.x, y: coin.position.y)