Here's my code, I'm experimenting stuff with canvas:
function Map(){
this.personnages = new Array();
}
Map.prototype.addPersonnage = function(perso) {
this.personnages.push(perso);
console.log(this.personnages);
}
Map.prototype.drawMap = function(){
console.log(this.personnages);
for(var i = 0; i < this.personnages.length; i++) {
this.personnages[i].dessinerPersonnage(context);
}
}
The thing is : the first console.log prints the array just fine, but the second one (in Map.prototype.drawMap) returns "undefined" (therefore the loop can't be executed)... I guess that functions are called in a correct order :
var canvas = document.getElementById('main');
var ctx = canvas.getContext('2d');
var tilesetImage = new Image();
tilesetImage.src = 'img/tileset.png';
var map1 = new Map();
var player = new Personnage("img/player.png", 7, 14, DIRECTION.BAS);
map1.addPersonnage(player);
tilesetImage.onload = map1.drawMap;
I'm kinda new here, please tell me if I gave enough elements. Thanks in advance, any little help appreciated!