0
votes

I have the following code:

func laser() {
    let scene: SKScene = SKScene(fileNamed: "Laser")!
    let laser = scene.childNode(withName: "laser")

    let waitAction: SKAction = SKAction.wait(forDuration: 0.0001)
    let removeAction: SKAction = SKAction.removeFromParent()
    laser?.run(SKAction.sequence([waitAction,removeAction]))
}

But it seems like the nodes are not been remove from memory because keep increasing. Any if you knows why either SKAction.wait or SKAction.removeFromParent() is not been executed?

I'll really appreciate your help.

1

1 Answers

0
votes
let scene: SKScene = SKScene(fileNamed: "Laser")!

This means you are loading a new scene, not using the scene you are on.

So you are loading a new scene, putting the action on the laser from that scene, then leaving the function.

Once you leave the function, the scene is destroyed, and you wasted CPU cycles.

Not sure where you are executing this code from, but you need to get to the scene that is actually in use.