如何在向左或向右移动时水平翻转精灵?
在我的 SpriteKit 项目中,我有一艘船,我可以左右拖动来捕捉从天上掉下来的物品,我希望船能够朝它移动的方向看,我想我必须将 xScale 从 CGFloat(1) 更改为 CGFloat( -1)但我不知道如何,任何建议都表示赞赏,这就是我处理船运动的方式:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let location = touch?.location(in: self){
node.run(SKAction.move(to: CGPoint(x: nodePosition.x + location.x - startTouch.x, y: nodePosition.y + location.y - startTouch.y), duration: 0.1))
}
}
In my SpriteKit project I have a boat that I drag left and right to catch items falling from the sky, I would like the boat to look in the direction it's moving, I think I have to change xScale from CGFloat(1) to CGFloat(-1) but I don't know how, any suggestion is appreciated, this is how I handle the boat movement:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let location = touch?.location(in: self){
node.run(SKAction.move(to: CGPoint(x: nodePosition.x + location.x - startTouch.x, y: nodePosition.y + location.y - startTouch.y), duration: 0.1))
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内部
touchesmaid
您可以使用touch.location.location
和touch.previouslocation
确定x位置的更改。然后,如果Delta X为正或负数,则可以相应地翻转XScale。inside
touchesMoved
you can usetouch.location
andtouch.previousLocation
to determine a change in the x position. then if the delta x is positive or negative you can flip your xScale accordingly.