gpt4 book ai didi

ios - 移动我的 SpriteNode Swift SpriteKit

转载 作者:行者123 更新时间:2023-11-29 01:33:27 24 4
gpt4 key购买 nike

对不起我的英语我是法国人。大家好。

我目前正在用 Swift 编写一个小游戏,我想知道一开始如何移动我的角色在中间,以及如何在使用 touchesMoved 函数时移动他跟随我的手指但不是瞬间,就是它自己的速度可以说。如果是的话,你也可以告诉我当我在箭头屏幕的另一侧拖动我的手指改变方向时,如何使我的角色(例如箭头)与我放置手指的方向相同:)

谢谢你的帮助

最佳答案

太棒了,这是我的代码:

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch : AnyObject in touches {
let location = touch.locationInNode(self)

let actionBouger = SKAction.moveTo(CGPoint(x: location.x, y: location.y), duration: 2.5)
Vaisseau.runAction(actionBouger)

let dx = location.x - Vaisseau.position.x
let dy = location.y - Vaisseau.position.y
var angleInRadians = atan2(dy, dx) - CGFloat(M_PI_2)

if(angleInRadians < 0){
angleInRadians = angleInRadians + 2 * CGFloat(M_PI)
}

Vaisseau.zRotation = angleInRadians

let actionAngle = SKAction.rotateToAngle(angleInRadians, duration: 0)
Vaisseau.runAction(actionAngle)
}
}

关于ios - 移动我的 SpriteNode Swift SpriteKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33212112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com