0
https://i.stack.imgur.com/JQ9r6.png正在同步一個SKSpriteNode的運動與另一SKSpriteNode
你上面的旋轉可以看到我的遊戲的圖像。我有敵人產卵並在Y軸上向下移動。玩家想要在敵人到達牆壁之前擊落敵人。現在,玩家正在旋轉到觸摸位置。我想要的是讓子彈與旋轉方向一致。就像現在一樣,子彈直接向前。這是子彈的代碼。
func spawnBullets(towards point: CGPoint) {
let bullet = SKSpriteNode(imageNamed: "Bullet")
bullet.zPosition = 1
bullet.position = CGPoint(x: player.position.x + 19, y:
player.position.y)
let action = SKAction.move(to: point, duration:
TimeInterval(1))
bullet.run(SKAction.repeatForever(action))
self.addChild(bullet)
}
這是我的代碼有旋轉玩家:
static let Pi = CGFloat(Double.pi)
static let DegreesToRadians = Pi/180
override func touchesMoved(_ touches: Set<UITouch>, with event:
UIEvent?) {
let curTouch = touches.first!
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
}
我怎樣才能讓使子彈的方向和球員輪換「同步」?
我現在更改了代碼並在此處進行了編輯。雖然我忘了注意到我用「var timer = Timer.scheduledTimer(timeInterval:0.1,target:self,selector:Selector(」spawnBullets「),userInfo:nil,repeatats:true)」產生子彈。但是現在,隨着這些變化,當我開始遊戲時,我立即發現一個錯誤,提示「GameplayScene spawnBullets」:發送到實例0x7fa4511022f0的無法識別的選擇器「。你知道這個問題可能是什麼嗎?另外你是什麼意思,「你通過觸摸位置的功能」 – Flinigan
@Flinigan你可以得到觸摸位置,對吧?現在,當觸摸發生時,你想讓子彈形狀產生者可以使用這個位置,這樣你就可以將子彈引向好的方向。 –
至於你的錯誤,它發生是因爲選擇器簽名不允許將參數傳遞給函數。 –