guys. I'm making an endless runner in which I need some objects to come from the top of the screen and then get destroyed once they're no longer visible.
Screenshot of how it looks like right now
I created the class "banana":
function Banana() {
this.height = 1.96;
this.width = 3.955;
this.pos_x = 300;
this.pos_y = -30;
this.banana_image = new Image();
this.banana_image.src = 'img/banana.png';
};
And a Move function:
Banana.prototype.move = function(){
if (this.pos_y > 500) {
//destroy it
this.constructor = undefined; //????
}
this.height += 0.5;
this.width += 0.5;
this.pos_y += 5;
this.pos_x -= 2.2;
};
I created the object in my Game.Initialize function, but it only runs once so it doesn't really help me.
I want to be able to create them dynamically on my Game.update. I was thinking about using an array of objects, but since I'm new to Javascript I don't know how it would work.
Aucun commentaire:
Enregistrer un commentaire