Jump to content

createFromObjects, objects sizes


Recommended Posts

I use the createFromObjects function to create sprites. And everything works well. But, when I change the size of the object in the json file, the image size changes, but the size of the sprite is not. The size of the sprite remains equal to the size of the original picture. And my game object is in the air.
How can I fix this?

And one more question. How can I get my properties that I added to the object?

My code:

var map = this.make.tilemap({ key: 'map' });   
var tiles = map.addTilesetImage('layer1', 'tiles');

layer = map.createDynamicLayer(0, tiles, 0, 0);

var mushroomsArray = map.createFromObjects('object layer', 5, { key: 'benefits' });
var mushroomsGroup = this.physics.add.group();
for (var i = 0; i < mushroomsArray.length; i++)


Link to comment
Share on other sites

4 hours ago, samme said:


For my map, I want to use a tileset with many different objects of different sizes.
For example, it can have a large mushroom and a small nut.
At this point, I have an image of 200 * 200 pixels and 4 objects on it.

When I don’t change the size of the object all is well.


The mushroom is located at the top. And it begins to fall down to the "floor". The boundaries of the image are equal to the size of the sprite.

But, if I reduce the size of an object, the image is reduced, but not the sprite boundaries


The mushroom falls, but does not reach the "floor".

My .json file:


From debugging data( console.log( mushroomsArray ) ) :

_scaleX: 0.7
_scaleY: 0.66
height: 100
width: 100
Link to comment
Share on other sites

  • 2 weeks later...

Did so:

objectsArray[i].width = objectsArray[i].width * objectsArray[i]._scaleX;
objectsArray[i].height = objectsArray[i].height * objectsArray[i]._scaleY;

objectsArray[i].x = objectsArray[i].x - (objectsArray[i].width/2);
objectsArray[i].y = objectsArray[i].y - (objectsArray[i].height/2);


Link to comment
Share on other sites


  • Recently Browsing   0 members

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