LaaW 0 Posted March 17, 2017 Report Share Posted March 17, 2017 Hi, I started making simple pong like game in phaser but i don't really want to use any tutorial step by step so i started making game, when i try to make movement for paddle i saw first problem. My paddle don't move and completely i have no idea why. Anybody can show me what's i'm doing wrong? There is a main file with js //this game will have only 1 state var GameState = { //load the game assets before the game starts preload: function() { //adding sprites this.load.image('ball','assets/images/ball.png'); this.load.image('paddle','assets/images/paddle.png'); }, //executed after everything is loaded create: function() { //adding background game.stage.backgroundColor = '#d3de33'; //adding ball ball = this.game.add.sprite(game.world.centerX,game.world.centerY,'ball'); ball.scale.setTo(0.1); //adding paddles paddleLeft = this.game.add.sprite(5, game.world.centerY, 'paddle'); paddleLeft.anchor.setTo(0.5,0.5); paddleRight = this.game.add.sprite(795, game.world.centerY, 'paddle'); paddleRight.anchor.setTo(0.5,0.5); //paddle movemment if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { paddleLeft.x -= 50; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { paddleLeft.y += 50; }; }, update: function() { }, render(){ //render paddles game.debug.spriteInfo(paddleLeft, 20, 32); } }; //initiate the Phaser framework var game = new Phaser.Game(800, 600, Phaser.AUTO); game.state.add('GameState', GameState); game.state.start('GameState'); pong.rar Quote Link to post Share on other sites
Mattia 12 Posted March 18, 2017 Report Share Posted March 18, 2017 Hi LaaW, you are checking for keyboard inputs in the create function, so just once when the game starts. Use the update functions, instead, and it works fine, like this:http://jsfiddle.net/vq6ubnfo/ As shown in the Phaser keyboard example, too:https://phaser.io/examples/v2/input/keyboard Phaser examples are a good start too, if you don't want to follow step by step tutorials. Cheers! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.