如何在用户与场景交互后改变精灵的方向?

How to change the direction of a sprite after a user interacts with the scene?

我有一个 SKSpriteNode 对象,它有一个永远 运行 的动作序列。这些动作很简单,可以先移到最右边,然后再回到最左边。

当用户在应用中输入一些值时,我需要反转方向,即。 e.如果精灵向右移动,我需要让它向左移动,反之亦然。

我怎样才能做到这一点?

我会这样做:(在 swift

func movament() {

    if isMovingRight == true {
        runAction(SKAction.sequence([
            SKAction.moveByX(10, y: 0, duration: 0.05),
            SKAction.performSelector("movament", onTarget: self),
            ]))
    } else {
        runAction(SKAction.sequence([
            SKAction.moveByX(-10, y: 0, duration: 0.05),
            SKAction.performSelector("movament", onTarget: self),
            ]))
    }
}

根据用户输入将 isMovingRight 更改为相反的值

这有用吗?

你应该使用:

SpriteNode.removeAllactions() // to stop the node

函数的拼写可能不正确