Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Tweens overlapping bug


shtanton
 Share

Recommended Posts

I'm making a top down game where the player moves smoothly around the plane but is confined to a 64x64 grid, I have achieved this by allowing them to move if they are exactly positioned on one of the 64x64 tiles and if they are, the game tweens them to the appropriate tile.  The problem is that despite my best efforts it is still possible to move diagonally which would cause a lot of bugs in my collision code.  This is the code I am using

update: function () {
    if (player.x%64 === 0 && player.y%64 === 0) {
        if (game.input.keyboard.isDown(Phaser.KeyCode.W)) {
            game.add.tween(player).to({y: player.y-64}, 250, Phaser.Easing.Linear.None, true);
        } else if (game.input.keyboard.isDown(Phaser.KeyCode.S)) {
            game.add.tween(player).to({y: player.y+64}, 250, Phaser.Easing.Linear.None, true);
        } else if (game.input.keyboard.isDown(Phaser.KeyCode.A)) {
            game.add.tween(player).to({x: player.x-64}, 250, Phaser.Easing.Linear.None, true);
        } else if (game.input.keyboard.isDown(Phaser.KeyCode.D)) {
            game.add.tween(player).to({x: player.x+64}, 250, Phaser.Easing.Linear.None, true);
        }
    }
},

Any help would be great! Thanks in advance

Link to comment
Share on other sites

9 hours ago, VitaZheltyakov said:

It is bad practice to use animation instead of physics. Use this example:

http://phaser.io/examples/v2/arcade-physics/bounce-knock

I couldn't find a method that interacted with my map the way I intended it to, I have a layer in the json map called hitboxes that either has 0 or a value for whether the sprite should collide with it, if you have a way that phaser can do this with the built in physics and still stay in the 64x64 grid alignment then I'm open to suggestions, thanks!

Link to comment
Share on other sites

2 hours ago, shtanton said:

I couldn't find a method that interacted with my map the way I intended it to, I have a layer in the json map called hitboxes that either has 0 or a value for whether the sprite should collide with it, if you have a way that phaser can do this with the built in physics and still stay in the 64x64 grid alignment then I'm open to suggestions, thanks!

Look at the player moves as in the example. This is what you need.

Link to comment
Share on other sites

6 hours ago, VitaZheltyakov said:

Look at the player moves as in the example. This is what you need.

The example still allows the player to move diagonally which is what I'm trying to avoid, I don't know why the "else if" statements aren't doing this

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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