Jump to content

Tilemap, collision and jumping problem


pros22su
 Share

Recommended Posts

Hi all,

I am trying to develop my second game with Phaser. First one was really simple and worked for me and now trying to get to more advanced stuff.

 

This time I decided to use tilemaps. Now I am in the situation where I can move around the tilemap but all controls donät still work as I expect so I am asking for your help.

 

First to understand what is my problem I uploaded my example to this address: http://smoking.wc.lt/

 

To reproduce my issue:

 

1. when player falls down to the white sprite try to press spacebar and you will see that player doesn't jump

2. if you move to the right with cursor key then you will be able to jump when you reach the edge of the white sprites

 

Also there is a console.log added when spacebar is down, so when you are on the step one then actually it should jump (console gets output) but velocity is not applied to the player.

 

Code to check is spacebar down:

		if (this.jumpButton.isDown) {			console.log('upISDOWN');			this.player.body.velocity.y = -320;		}

My own opinion is that something is wrong somewhere where I am setting the collision between tiles, maybe I need to do something else when I am initialising a tilemap/layer?

		//'smoking-game' is the name of the spritesheet inside of Tiled Map Editor		this.map.addTilesetImage('smoking-game', 'smoking-game-tiles1');		this.map.setCollisionBetween(0, 4);		//'Tile Layer 1' is the name of a layer inside of Tiled Map Editor		this.layer = this.map.createLayer('Tile Layer 1');		this.layer.debug = true;		this.layer.resizeWorld();

Bonus question: is it possible to allow jumping only from the layers that are defined by me, for example right now if you jump from the edge of the sprite then you are able to jump while you are in the air - so when you are not touching any tile.

Link to comment
Share on other sites

In the sprite vs. tilemap collision callback you will be passed the sprite and the tile it has collided with. Here you can poll the tile properties or id and then decide if you want to allow them to jump from it or not.

 

When you jump you should set a "cool down" value for the jump key too. I.e. you set their velocity, and then set a flag saying "don't allow jumping again for at least another 50ms". Otherwise what can happen is that the jump is applied multiple times before it registers it's no longer colliding with a tile which might lead to strange effects or audio later on (if you play a jump sound for example).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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