Tilemap.getTileLeft
and its fellow methods do exactly what they say on the tin: They'll return the tile immediately to the left of the given coordinates (or null
if no tile was found).Math.floor
on its x and y values and then using Phaser.Math.snapToFloor
to convert those to grid coordinates. This will give us the exact tile is the car is in. We store this in the marker
variable.directions
array. With the debug render turned on we can see what the car knows about its surroundings:checkDirection
method.Phaser.LEFT
or Phaser.DOWN
.turnPoint
, a Phaser.Point
object that holds the coordinate of point at which we want the car to change direction.Phaser.Math.fuzzyEqual
. This works by taking two values and a threshold. It compares the values and if they are within the threshold difference of each other, they are considered as being equal:update
method we check to see if the car has reached the turning point.move
method we need to turn him to face his new direction:scale.x
to make him face left. In order to face up or down we rotate him.dots
Group for every one of them. The setAll
calls adjust the position of the dot sprites, adding 6px to their values because they are only 4x4 in size - this puts them back into the middle of the tiles.update
: