In my game I spawn many enemies with random coordinates, but they share the same internal data.
Currently I have a function SpawnEnemy()
who looks like this:
func spawnRedPawn(timer: NSTimer) {
var redPawn = Ship(entityNamed: ESHIP_REDPAWN)
let action = SKAction.moveToX(0, duration: timer.userInfo as! NSTimeInterval)
let actionDone = SKAction.removeFromParent()
redPawn.position = CGPoint(x: self.size.width, y: CGFloat(arc4random_uniform(UInt32(self.size.height - redPawn.size.height))))
redPawn.setupPhysicsBody(PC.enemy)
redPawn.setupContactTestBitmask([PC.projectile, PC.player])
redPawn.addEmitter("propulsionParticle", offset: CGPointMake(redPawn.size.width / 2 + 5, 0))
redPawn.runAction(SKAction.sequence([action, actionDone]))
self.addChild(redPawn)
}
PS: the function format (called by NSTimer Selector()) will probably be changed
I am new to SpriteKit but I feel that this setup process is quite resource intensive right?
My question is: is it possible/would it be better to run this fonction only once, and then only duplicate the created enemy?