Tilemap Canvas Boundaries - RPG Tutorial 6

Wow, you actually tuned in, I am impressed! As promised, I said we would set our sprite to take into account our canvas boundaries, so here is how we do it!

Pop the following code within our create() function:

// enable game physics on sprite
game.physics.enable(sprite, Phaser.Physics.ARCADE);
// set sprite to hit boundaries of our world bounds
sprite.body.collideWorldBounds = true;

That’s really it, super simple. We set our game physics on our sprite (SS Goku) and then tell the sprite to respect our canvas map boundaries and bounce off.. (ARCADE setting).

So next, we will talk about updating our sprite’s image depending on which direction it is moving (* looks left, looks right *) whoa.

Demo the thing..

Open Demo

Download Source Files

If you would like the source files for this tutorial: Download source files

Load Comments