WebDevUa Posted October 2, 2017 Share Posted October 2, 2017 Hello everybody I write my first application, add physics for my player, add cursors , input keyboards. En error you will see on the screenshots. var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'gameDiv'); var spacefield; var backgroundv; var player; var cursors; var mainState = { preload: function(){ game.load.image('starfield', "assets/starfield.png"); game.load.image('player', "assets/player.png"); }, create: function(){ spacefield = game.add.tileSprite(0, 0, 800, 600, 'starfield'); backgroundv = 5; game.add.sprite(game.world.centerX, game.world.centerY + 200, 'player'); game.physics.enable(player, Phaser.Physics.ARCADE); cursors = game.input.keyboard.createCursorKeys(); }, update: function(){ spacefield.tilePosition.y += backgroundv; if(cursors.left.isDown){ player.body.velocity.x = -350; } if(cursors.right.isDown){ player.body.velocity.x = 350; } } }; game.state.add('mainState', mainState); game.state.start('mainState'); Whats wrong? Link to comment Share on other sites More sharing options...
samid737 Posted October 2, 2017 Share Posted October 2, 2017 You have to assign the player variable: player = game.add.sprite(game.world.centerX, game.world.centerY + 200, 'player'); WebDevUa 1 Link to comment Share on other sites More sharing options...
WebDevUa Posted October 2, 2017 Author Share Posted October 2, 2017 16 minutes ago, samid737 said: You have to assign the player variable: player = game.add.sprite(game.world.centerX, game.world.centerY + 200, 'player'); thank you, rescued! Link to comment Share on other sites More sharing options...
Recommended Posts