Jump to content

my sprite can't move


Recommended Posts

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
  //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');
    //adding paddles
    paddleLeft = this.game.add.sprite(5, game.world.centerY, 'paddle');
    paddleRight = this.game.add.sprite(795, game.world.centerY, 'paddle');
    //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 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);



Link to comment
Share on other sites

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:

As shown in the Phaser keyboard example, too:

Phaser examples are a good start too, if you don't want to follow step by step tutorials.

Cheers! :)

Link to comment
Share on other sites


  • Recently Browsing   0 members

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