如果没有触摸,我将如何改变我的形象?

How would I change my image if there is no touch?

我在屏幕中央有一个节点,点击屏幕左侧可以向左移动,如果点击屏幕右侧则可以向右移动。我添加了一个 SKTexture 这样,如果我按下左侧,图像将是一个面向左侧的节点,如果我点击右侧,则该节点将面向右侧。

当我不点击屏幕时,如何使图像面向屏幕?我已经制作了图像,但我不知道如何编码。

let location = touch.locationInNode(self)
if location.x < CGRectGetMidX(self.frame) {
    hero.position.x -= speedOfTouch
    hero.texture = SKTexture(imageNamed: "lefthero")
    AudioPlayer.play()
} else {
    hero.position.x += speedOfTouch
    hero.texture = SKTexture(imageNamed: "righthero")        
    AudioPlayer.play() 
}

假设您在 touches begin 方法中实现您的代码,使英雄面向屏幕被点击的一侧,如果是这种情况,将英雄重置为面向用户(屏幕)就像就像在用户停止触摸屏幕时设置该图像一样简单。

override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
    super.touchesEnded(touches, withEvent: event)

    hero.texture = SKTexture(imageNamed: "screenFacing")
}

请注意,如果您在 touches begins 中使用任何逻辑来确定屏幕上的手指数量应如何影响英雄的状态,您应该在 touches ended 中实现相同的逻辑。