batiste / sprite.js

An efficient javascript sprite animation framework
MIT License
871 stars 98 forks source link

Custom Sprite options #19

Closed exaboy closed 12 years ago

exaboy commented 12 years ago
//Create the sprite
missile = this.scene.Sprite("cannon-ball.png",{
    "layer": this.layer,
    "w":      10,
    "h":      10,
    "angle":  a,
    "x":      x,
    "y":      y,
    "k":      this.ticker.currentTick+100
});

//Add it to the sprites array
this.missiles.push(missile);

As you can see above I'm looking to kill the missile after currentTick+100 however this custom variable is not being preserved when interrogating the Sprite object in a later loop. Does this make sense? How can I achieve this?

batiste commented 12 years ago

You need to assign k manually as the property k is not created when you use the shortcut.

Do:

missile.k = scene.ticker.currentTick+100;

exaboy commented 12 years ago

Thanks for the update thats good to know for future reference! I ended up adding a 'created' property inside the Sprite which I'm assigning when new ones are created.