Jump to content

Phaser sprite rendering oddity


Recommended Posts

Hey, a Phaser/JS/Typescript beginner here.

Recently picked had an idea to create a simple game to get to grips with the Phaser/Typescript and all other related technologies, so far so good except I have a some what odd issue I can't get my head around. First off, the idea for the game is: endless platformer, sounds easy enough. Add in platforms from the right, get rid of them on the left (I don't destroy them, just take them out of the platform group ans re-add later when new platforms are needed). The player can move about 40% (If left/right arrow down, velocity is -x/x)of the screen, if trying to move further he stays in place and the world moves instead (same logic as for the player). Using Arcade physics where the player is enabled and the platforms are all in a group with enabledBody == true. All the movement updates/new platform addition is done in update().

What I'm getting can be seen in the attached screen shot. Some of the newly added platforms are miss aligned.. Printed their X coordinates before adding them back to the render group (from the image, all four where added with addMultiple) - all are fine, the result should be nice and aligned.

Tried searching for some materials on when the physics/render steps are done, but sadly all I get are links to simple tutorials, with little to no reasoning or backstory :(

Am I doing something fundamentally wrong? Seems to me that the physics tick was done in the middle of adding my platforms - is that even possible? But that doesn't explain why the last one is in the correct position though. Maybe because of floats? If I increase the velocity the gaps get bigger :)

Kudos if you read all of this.


Link to comment
Share on other sites

Hi, make sure your platform blocks have these settings:

                let body = <Phaser.Physics.Arcade.Body>sprite.body;
                body.allowGravity = false;
                body.immovable = true;
                body.moves = false;

 body.moves = false says, that your platform blocks are not being moved by physics, but by you. This property is set to true by default.

 To make a little promo :), I wrote book on making Endless platformer with Phaser/TypeScript: https://gumroad.com/l/CZuhn. FInal game is here: http://sbc.littlecolor.com/goblinrun/


Link to comment
Share on other sites


  • Recently Browsing   0 members

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