Jump to content

Change the body size of a tile?


toto88x
 Share

Recommended Posts

Hello,

 

I'm making a 2D platformer game with Tiled and Phaser with Arcade physics.

 

I'd like to change the body size of some of my tiles. For example: reduce by 2 the collision area of the spikes in my game.

How can I do that?

 

Thanks!

Link to comment
Share on other sites

Make sure the tiles you are trying to scale are inside an object layer, that is very important.

 

Then in your code just load the necessary json file and tiles image, and write down this:

map = game.add.tilemap('map');map.addTilesetImage('tiles');// create our enemies groupenemies = game.add.group();enemies.enableBody = true;//  And now we convert all of the Tiled objects with an ID of 5 into sprites within the enemies groupmap.createFromObjects('enemies', 5, 'enemy',0, true, false, enemies);// Loop trough all enemies and scale to the size we wantenemies.forEach(function(enemy){    enemy.scale.x = 1.5;    enemy.scale.y = 1.5;});

createFromObjects()

 

Here is a working example:

http://examples.phaser.io/_site/view_full.html?d=tilemaps&f=create+from+objects.js&t=create%20from%20objects

 

And the json file they use in the example (you can search for ID number inside here):

http://examples.phaser.io/assets/tilemaps/maps/features_test.json

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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