Zendrael Posted December 15, 2015 Share Posted December 15, 2015 Hello all! Well, after about 8 hours on this I have to say that I really don't know what is happening... The collision simply is not working. All shows ok but not colliding... Here is my code so far:create : function() { GAME.physics.startSystem(Phaser.Physics.ARCADE); mapa = GAME.add.tilemap('mapa'); mapa.addTilesetImage('meuTileset', 'tilesetImg'); mapa.setCollisionBetween(970, 1026); //tryied even 0 to 5000 this.layer = mapa.createLayer('cenario'); this.layer.resizeWorld(); this.layer2 = mapa.createLayer('detalhes'); this.layer2.resizeWorld(); PLAYER = GAME.add.sprite(GAME.world.centerX, GAME.world.centerY, 'player1'); GAME.physics.arcade.enable(PLAYER); CURSORS = GAME.input.keyboard.createCursorKeys();}, //end createupdate : function() { this.physics.arcade.collide(PLAYER, this.layer); this.physics.arcade.collide(PLAYER, this.layer2); if (CURSORS.left.isDown) { PLAYER.body.velocity.x = -50; PLAYER.body.velocity.y = 0; } else if (CURSORS.right.isDown) { PLAYER.body.velocity.x = 50; PLAYER.body.velocity.y = 0; } else if (CURSORS.up.isDown) { PLAYER.body.velocity.x = 0; PLAYER.body.velocity.y = -50; } else if (CURSORS.down.isDown) { PLAYER.body.velocity.x = 0; PLAYER.body.velocity.y = 50; }}, //end updatePlease, where I am doing this wrong??? Link to comment Share on other sites More sharing options...
Skeptron Posted December 15, 2015 Share Posted December 15, 2015 Make sure your player object has a velocity before collisions check, otherwise it won't work. Also, I'm guessing calling resizeWorld() twice is useless : only the last one will actually be effective. Link to comment Share on other sites More sharing options...
Zendrael Posted December 15, 2015 Author Share Posted December 15, 2015 Hi Skeptron! Still nothing... the resizeWorld is one for each layers so there is no duplicate. All the rest is ok, just the collision is not working... Link to comment Share on other sites More sharing options...
Skeptron Posted December 15, 2015 Share Posted December 15, 2015 Doc : http://phaser.io/docs/2.4.4/Phaser.TilemapLayer.html#resizeWorld Doing it twice is useless : the last time you invoke it is the only one that's kept in the end (first time will be overridden). The world only has one size, so the last one you apply is the only one that's kept. For the collisions though I can't see what's wrong : could you do a sandbox please? That would help a lot. Link to comment Share on other sites More sharing options...
Zendrael Posted December 15, 2015 Author Share Posted December 15, 2015 Well, a dig into the docs solved my collision problem with mapa.setCollisionBetween(1,800, true, 'detalhes'); where the params say that it will enable collisions and in which layer. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts