的方向在這裏,你有遊戲的PRINTSCREEN:正在旋轉的觸摸的方向移動SKSpriteNode到觸摸
我有一個靜態SKSpriteNode(播放器)。這是我對這些代碼:
class GameplayScene: SKScene, SKPhysicsContactDelegate {
static let Pi = CGFloat(Double.pi)
static let DegreesToRadians = Pi/180
override func touchesMoved(_ touches: Set<UITouch>, with event:
UIEvent?) {
let curTouch = touches.first! as UITouch
let curPoint = curTouch.location(in: self)
let deltaX = self.player.position.x - curPoint.x
let deltaY = self.player.position.y - curPoint.y
let angle = atan2(deltaY, deltaX)
self.player.zRotation = angle + 90 * GameplayScene.DegreesToRadians
}
}
現在,我想從在同一方向上屏幕的觸摸移動玩家每秒拍攝子彈。當子彈移出屏幕時,我想實現「SKAction.removeFromParent」。
這裏是我的fireMissile功能:
func fireMissile() {
let missile = SKSpriteNode(color: .yellow, size: CGSize(width: 20,
height: 5))
missile.name = "Missile"
missile.position = CGPoint(x: player.position.x + 30, y:
player.position.y)
missile.zPosition = 2
missile.physicsBody = SKPhysicsBody(rectangleOf: missile.size)
missile.physicsBody?.isDynamic = false
missile.physicsBody?.categoryBitMask = ColliderType.Bullet
missile.physicsBody?.collisionBitMask = ColliderType.Enemy
missile.physicsBody?.contactTestBitMask = ColliderType.Enemy
self.addChild(missile)
}
我不是已經給你這個答案了嗎? – Knight0fDragon
困惑,還是你在這裏問兩個不同的問題?你需要幫助去除子彈,還是幫助旋轉坦克?或幫助移動坦克?這些都是獨立的問題:) – Fluidity
Fluidify - 我想讓基本上以恆定速度在屏幕上觸摸的方向(從玩家)射擊子彈。對不起,沒有明確說明這一點:P – Flinigan