I am new to Swift and SpritKit and have several problems with my game.
In my didMoveToView(view: SKView) { } section of my code, I invoke the statement below, which fills the monsters on the screen. In my func addMonster() { } Then the monsters move from the right side, to the left side of the screen. When they exit the screen to the opposite side, the sprite is deleted.
CODE A
runAction(SKAction.repeatActionForever( SKAction.sequence([ SKAction.runBlock(addMonster), SKAction.waitForDuration(1.0),SKAction. ]) ))
In the Mons β er add function, I call the following code, which moves Monster around the screen.
let actualDuration = random(min: CGFloat(6.0), max: CGFloat(10.0)) let actionMove = SKAction.moveTo(CGPoint(x: -monster.size.width/2, y: actualY), duration: NSTimeInterval(actualDuration)) let actionMoveDone = SKAction.removeFromParent() monster.runAction(SKAction.sequence([actionMove, actionMoveDone]))
All of the above code is working fine.
When the user killed the number of monsters X, I want all the other monsters on the screen to disappear and stop appearing.
My questions are: how do I: a) Stop CODE And from spawning monsters and b) how do I get the monsters that are on view, delete them?
Thanks,
Ryann
source share