Create an image to map from ObjectLayer

Hello, trying to set a image onto map from the ObjectLayer I’ve created with Tiled.

However the object tile looks like this in the game.

object_missing

I could I have missed?

Object in Tiled

CreateFromObjects routine
private createPickups() { this.pickupsGroup = this.physics.add.staticGroup(); const pickupsGameObjects = this.map.createFromObjects('Pickups', {}); pickupsGameObjects.forEach((object) => { const sprite = object as Phaser.GameObjects.Sprite; sprite.setVisible(true); sprite.setDepth(9); this.pickupsGroup.add(sprite); }); }

Corresponding config in map:

[code]
{
         "draworder":"topdown",
         "id":13,
         "name":"Pickups",
         "objects":[
                {
                 "gid":4873,
                 "height":32,
                 "id":5,
                 "name":"",
                 "rotation":0,
                 "type":"",
                 "visible":true,
                 "width":32,
                 "x":431,
                 "y":541
                }],
         "opacity":1,
         "type":"objectgroup",
         "visible":true,
         "x":0,
         "y":0
        }, 
[/code]

I have verified I’ve loaded the corresponding tilemap where the image is.

:wave:

You need something like

const pickupsGameObjects = this.map.createFromObjects('Pickups', { key: 'KEY', frame: 'FRAME' });

Thank you for the reply samme.

By providing the tilesetImageKey and frame ends up rendering the whole tileset, not the individual frame, as seen the image.

How the individual objectLayer tile from the tileset could be rendered?

On initialization I’ve added the propsA tileset

...
 this.map.addTilesetImage('propsA')
...

Changed createFromObjects parameters so that it has key and frame in the config.

private createPickups() { 
  this.pickupsGroup = this.physics.add.staticGroup(); 
  const pickupsGameObjects = this.map.createFromObjects('Pickups', { key: 'propsA', frame: 0 });
  pickupsGameObjects.forEach((object) => { 
    const sprite = object as Phaser.GameObjects.Sprite; 
    sprite.setVisible(true); 
    sprite.setDepth(9); 
    this.pickupsGroup.add(sprite); 
  }); 
}

The whole tileset `propsA` is being rendered as seen in the image below.
![whole_tileset_rendered|800x487](upload://xY6C1u45jiZOEKjP10e0JlgeIFP.png)

You need to add a spritesheet texture. An easy way is

this.load.image('tileset', 'tileset.png');
this.load.spritesheet('tilesetSprite', 'tileset.png', { frameWidth: W, frameHeight: H });

(Fixed)

Thanks for a suggestion, samme.
However, the config containing frameWidth and frameHeight is not part of XHRSettings and thus is not accepted.

I guess you just had a typo, and loading the spritesheet as below

 this.load.spritesheet('tilesetSprite', 'assets/tilesets/decorative/propsA.png', { frameWidth: 32, frameHeight: 32});

it still renders the whole tileset (the tile below the player) as seen the picture below.

It would be nice to learn to load the image from Object layer

but as a fundamental question, should the frame mapping between objects and the tileset image be done in the code at all? It sounds quite tedious. Could it somehow happen automatically as in tile layers?
I will have several image objects drawn with Tiled tool in the Object layer. I would need to know each of their frame ids in the code, basically hardcode them.

On Tile layers the mapping between tile and image happens automatically with Tiled config (I just load the tileset to the map and it works). So this is not possible with Object layers?

If automatic tileset image mapping is not possible in object layers, just wondering what would be the proper way of creating collectible objects on the map? Could the object layer be just pointers to the Tile Layer, and the Tile Layer contains the collectible images?

Yes, I meant spritesheet(), thanks.

You need to use the spritesheet texture (as key) and frame:

this.map.createFromObjects('Pickups', { key: 'tilesetSprite', frame: FRAME });

If you’re using tile objects then you can figure out the correct texture frame from the object’s gid. But for that you will probably have to go through the object layer yourself instead of using createFromObjects().