Hi,
I would like to repeat an action every 2 seconds using a SKSpriteNode, but it tells me an error.
The purpose of my operation is to stop an object that moves to perform another repeated action.
Thank !
Here is my code:
func GestionContactSoldat1EtMur (Mur:SKSpriteNode, Soldat1:SKSpriteNode) {
Soldat1.removeAllActions() // arret sur place du soldat
//gestion attaque soldat1
gameTimer = Timer.scheduledTimer(timeInterval: 0.75, target: self, selector: AttaqueDuSoldat1(Soldat2: Soldat1), userInfo: nil, repeats: true)
}
@objc func AttaqueDuSoldat1(Soldat2:SKSpriteNode) {
self.run(SKAction.playSoundFileNamed("Mitrailleuse.mp3", waitForCompletion: false))
let BalleSoldat1 = SKSpriteNode(imageNamed: "BalleFusil")
BalleSoldat1.size.height = Soldat2.frame.height
BalleSoldat1.size.width = Soldat2.frame.width
BalleSoldat1.position = Soldat2.position
BalleSoldat1.physicsBody = SKPhysicsBody(circleOfRadius: BalleSoldat1.size.width / 2)
BalleSoldat1.physicsBody?.isDynamic = true
BalleSoldat1.physicsBody?.categoryBitMask = BalleSoldat1Category
BalleSoldat1.physicsBody?.contactTestBitMask = MurCategoryContact
BalleSoldat1.physicsBody?.collisionBitMask = MurCategoryContact
self.addChild(BalleSoldat1)
let animationDuration:TimeInterval = 5.5
BalleSoldat1.zPosition = 5
var actionArray = [SKAction]()
actionArray.append(SKAction.move(to: CGPoint(x: Soldat2.frame.origin.x, y: Mur.frame.minY), duration: animationDuration))
actionArray.append(SKAction.removeFromParent())
BalleSoldat1.run(SKAction.sequence(actionArray))
}