我的游戏截图 我想制作一个游戏(使用 Spritekit),您可以在其中使用左侧 dpad 在已经可以使用的瓷砖地图中移动玩家。使用正确的,您可以瞄准同样有效的对手。虽然我启用了多点触控,但只有一个控制器同时工作。
操纵杆的含义与 dpad 相同。
import SpriteKit
import GameplayKit
class GameScene: SKScene {
//These are just the touch functions
//touch functions
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for _ in touches {
if touches.first!.location(in: cam).x < 0 {
moveStick.position = touches.first!.location(in: cam)
}
if touches.first!.location(in: cam).x > 0 {
shootStick.position = touches.first!.location(in: cam)
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for _ in touches {
if touches.first!.location(in: cam).x < 0 {
moveStick.moveJoystick(touch: touches.first!)
}
if touches.first!.location(in: cam).x > 0 {
shootStick.waponRotate(touch: touches.first!)
}
}
}
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
for _ in touches {
resetMoveStick()
resetShootStick()
}
}
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
for _ in touches {
resetMoveStick()
resetShootStick()
}
}
// update function
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
let jSForce = moveStick.velocityVector
self.player.position = CGPoint(x: self.player.position.x + jSForce.dx,
y: self.player.position.y + jSForce.dy)
cam.position = player.position
}
}