Deino Posted March 6, 2015 Share Posted March 6, 2015 I am new to Phaser-Javascript, I can't figure out why this piece of code is not workingvar 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 More sharing options...
rich Posted March 6, 2015 Share Posted March 6, 2015 But there's no code in there to actually move your character at all. Deino 1 Link to comment Share on other sites More sharing options...
Berzee Posted March 6, 2015 Share Posted March 6, 2015 Is it because your jump function refers to this.bird instead of this.ball? =) Deino 1 Link to comment Share on other sites More sharing options...
Recommended Posts