Jump to content

Can't jump when colliding with tilemap using Arcade physics


Sawyer
 Share

Recommended Posts

I have a Tiled map successfully working in JSON. My problem is that when I'm colliding with my collision layer, my player is seemingly unable to jump. 

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', {preload: preload, create: create, update: update, render: render});                    function preload() {        game.load.spritesheet("player", "heroMainCharacter.png", 32, 32);                game.load.tilemap('tilemapTiled', 'jsons/mylevel.json', null, Phaser.Tilemap.TILED_JSON);        game.load.image('tileset', 'tilesets/tileset.png');    }    var cursor;    function create() {        game.physics.startSystem(Phaser.Physics.ARCADE);                var map = game.add.tilemap('tilemapTiled');        map.addTilesetImage('tileset');                bLayer = map.createLayer("bLayer");        cLayer = map.createLayer("cLayer");         cLayer.resizeWorld();        map.setCollisionBetween(1, 2000, true, 'cLayer');                sprite = game.add.sprite(30, 120, "player");               game.physics.arcade.enable(sprite);        sprite = true;        game.physics.arcade.gravity.y = 200;            cLayer = true;                cursors = game.input.keyboard.createCursorKeys();                game.camera.follow(sprite);            }    function update() {        game.physics.arcade.collide(sprite, cLayer)         if (cursors.up.isDown) {            sprite = -300;            console.log("called");        }                               }

If I have the sprite randomly floating in mid air, they can jump but as soon as they land on my collision platform, jumping no longer works.

 

I also can't get any way working to detect when the sprite is on the platform. I've trying sprite.touching, sprite.blocked, and onFloor(), none of which are being called at any point.

 

I'm using 2.4.4, but still had the same problems with the previous version.

Link to comment
Share on other sites

Hey drhayes, I was removing unnecessary code when I pasted in the question.  Must have accidentally removed the .body.velocity.y part. 

 

It's in the code but still have the same issue.  Not sure where I'm going wrong.

 

I've tried a few things to detect if I'm colliding before jumping, but nothing is returning the wanted result when my spite lands on a collision layer from my tilemap.  If it collides with the worldBounds I can jump and I'm getting detections so it's definitely something up with my tiles

Link to comment
Share on other sites

what is this code meant to do? looks wrong to me

sprite = true;cLayer = true;

you killed your reference to your sprite.

function create() {    sprite = game.add.sprite(30, 120, "player"); // <= 'sprite' points to the player    ..    sprite = true // <= 'sprite' no longer points to the player, it just equals 'true'    ..}function update() {       ...    game.physics.arcade.collide(sprite, cLayer)  // meaningless.. since 'sprite = true'    ...}
Link to comment
Share on other sites

Hey guys, sorry for the delayed response and that cluster of the code.  Have had internet issues the past few days.

 

I can see I've made a complete mess trying to filter down that code.

 

I've recreated the tilemap and the issue has seemingly disappeared, so not sure what went wrong and where.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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