Reputation: 43
I'm trying to create a function that can dynamically create variables for adding sprites into a game. Here is what I have so far:
function SpriteSetUp(name,src){
var Sprites = [];
var i = Sprites.length;
if(Sprites[Sprites.indexOf(name)] == name){
return Sprites[Sprites.indexOf(name)];
}else{
Sprites[i] = name;
Sprites[i].src = src;
return Sprites[Sprites.indexOf(name)];
}
};
Upvotes: 0
Views: 133
Reputation: 1167
How about creating sprite objects and push them into your sprite array?
function SpriteContainer() {
this.sprites = [];
this.addSprite= function(name, src) {
var newSprite = new Sprite(name,src);
sprites.push(newSprite);
}
function Sprite(name, src) {
this.name = name;
this.src = src;
}
}
Upvotes: 1