Jump to content

Unable to move my character


Deino
 Share

Recommended Posts

I am new to Phaser-Javascript, 

I can't figure out why this piece of code is not working


var game = new Phaser.Game(400, 490, Phaser.AUTO, 'gameDiv');
 
var mainState = 
{
preload: function()
{
game.stage.backgroundColor = "#71c5cf";
game.load.image('ball','assets/fireball.png');
},
 
create: function()
{
game.physics.startSystem(Phaser.Physics.ARCADE);
 
this.ball = this.game.add.sprite(100,250,'ball');
game.physics.arcade.enable(this.ball);
var spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
         spaceKey.onDown.add(this.jump, this);
this.ball.body.gravity.y = 1000;
 
 
},
 
update: function()
{
if (this.ball.inWorld == false)
{
this.restartGame();
}
 
        
},
 
restartGame: function()
{
game.state.start('main');
},
jump: function() {  
    
    this.bird.body.velocity.y = -350;
},
 
};
 
game.state.add('main',mainState);
game.state.start('main');
 

[\code]

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...