Last active
August 29, 2015 14:20
-
-
Save ruby0x1/218decd48cc54890cc22 to your computer and use it in GitHub Desktop.
luxe.structural.Pool example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//creation | |
var player_bullets : Pool<Sprite>; | |
player_bullets = new Pool<Sprite>(20, | |
function(index,total){ | |
var _sprite = new Sprite({ pos: new Vector(-999,-999), visible:false }); | |
var _projectile = _sprite.add( new Projectile({ | |
bullet_type:'player' | |
}) ); | |
return _sprite; | |
} | |
); | |
//use | |
function spawn() { | |
var bullet = player_bullets.get(); | |
bullet.pos.copy_from(player.pos); | |
var projecile = bullet.get('projectile'); | |
projectile.direction = player_direction; | |
projectile.spawn(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment