olgzich Posted August 5, 2018 Share Posted August 5, 2018 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++) { mushroomsGroup.add(mushroomsArray[i]); mushroomsArray[i].body.collideWorldBounds=true; } Link to comment Share on other sites More sharing options...
samme Posted August 6, 2018 Share Posted August 6, 2018 16 hours ago, olgzich said: the image size changes, but the size of the sprite is not Explain? Link to comment Share on other sites More sharing options...
olgzich Posted August 6, 2018 Author Share Posted August 6, 2018 4 hours ago, samme said: Explain? 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: ... "objects":[ { "gid":5, "height":66, "id":1, "name":"", "properties": { "alpha":"1" }, "propertytypes": { "alpha":"string" }, "rotation":0, "type":"", "visible":true, "width":70, "x":211.62610985568, "y":98.504325317887 } ... "tilesets":[ { "columns":2, "firstgid":5, "image":"benefits.png", "imageheight":200, "imagewidth":200, "margin":0, "name":"benefits", "spacing":0, "tilecount":4, "tileheight":100, "tilewidth":100 }] From debugging data( console.log( mushroomsArray ) ) : _scaleX: 0.7 _scaleY: 0.66 but: height: 100 width: 100 Link to comment Share on other sites More sharing options...
olgzich Posted August 18, 2018 Author Share Posted August 18, 2018 Did so: objectsArray[i].width = objectsArray[i].width * objectsArray[i]._scaleX; objectsArray[i].height = objectsArray[i].height * objectsArray[i]._scaleY; objectsArray[i].setOrigin(0); 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 More sharing options...
Recommended Posts