So I have a game with a sprite called enemy which has an invisible circle around it and a player sprite that can move freely 360 degrees around the enemy. When the player enters the frame of the enemy's circle however, this triggers the enemy to begin shooting bullets at the player. The player can still move. The problems I am having is with keeping the enemy continuously shooting the bullets as well as continuously firing them toward the position of the player even after the player has changed locations.
I will add some code to help you checkout the problem:
For fast reference we have this short piece here where i included only the minimum of what I thought was necessary for fast help. (I am not sure where to call the fireBullets() function... Inside the update function? Inside of did move? Inside of didBegin?).
func fireBullets() {
var fireBulletAction: SKAction
fireBulletAction = SKAction.run {
let bullet = self.createBullets()
var moveBullet = SKAction.move(to: self.player.position, duration: 1)
bullet.run(moveBullet)
}
var waitForDuration: SKAction
waitForDuration = SKAction.wait(forDuration: 1)
var bulletSequence = SKAction.sequence([fireBulletAction, waitForDuration])
var repeatBulletSequence = SKAction.repeatForever(bulletSequence)
enemy.run(repeatBulletSequence, withKey: "fireBullet")
}
Or to recreate the problem even faster and easier with all components(It's still only 96 lines of code), I made this simple GameScene.swift file which you can easily copy and paste from text into XCode.