我有一个位于屏幕中央的节点,可以在屏幕左侧轻按一下,如果点击屏幕右侧则可以向右移动。我添加了一个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()
}
答案 0 :(得分:1)
假设你在触摸中实现你的代码,开始的方法是让英雄面对被点击的屏幕一侧,如果是这种情况,重置英雄面对用户(屏幕)就像当用户停止触摸屏幕时,可以轻松设置图像。
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
hero.texture = SKTexture(imageNamed: "screenFacing")
}
请注意,如果你在触摸中使用任何逻辑开始确定屏幕上的手指数量应该如何影响你的英雄状态,你应该在结束的触摸中实现相同的。