Salut à tous !
Je suis en train de faire un jeux en Javascript à l'aide de Phaser, j'ai fait une classe Player avec deux méthodes move et update :
var Player = function(game, x, y, textureName){
Phaser.Sprite.call(this, game, x, y, textureName);
game.add.existing(this);
};
//l'Objet
Player.prototype = Object.create(Phaser.Sprite.prototype);
//on affecte à l'objet son constructeur
Player.prototype.constructor = Player;
Player.prototype.update = function(cursors){
this.move(cursors);
};
Player.prototype.move = function(cursors){
if(cursors.right.isDown){
this.body.velocity.x += 150;
}
else if(cursors.left.isDown){
this.body.velocity.x -= 150;
}
};
ludum.Game = function(game){
var text;
var style;
var hero;
var cursors;
var levelParams;
};
ludum.Game.prototype = {
create: function(){
this.style = { font: 'bold 25pt Arial', fill: 'white', align: 'left', wordWrap: true, wordWrapWidth: 450 };
this.text = this.add.text(0, 0, "Game state", this.style);
this.physics.startSystem(Phaser.Physics.ARCADE);
//le hero
this.hero = new Player(this,50,50,'hero');
this.physics.arcade.gravity.y = 250;
this.physics.enable(this.hero, Phaser.Physics.ARCADE);
this.cursors = this.input.keyboard.createCursorKeys();
//this.camera.follow(this.hero);
},
update: function(){
this.hero.update(this.cursors);
}
};
Le problème est le suivant lorsque que je lance le jeux il me dit que cursors n'est pas definie alors qu'il est ...
Je pense que c'est un problème avec le paramètre cursors dans update et move, mais en vrai je suis perdu, logiquement ( dans la tête ) ça devrait marcher, Javascript j'ai vraiment du mal ... Merci du votre en tout cas !