Get single Tile from Tilemap - NOWAY?

Hi !

I’m trying to add a single tile from a tilemap, here is my code :

  //LEVEL TILEMAP
  const map = this.make.tilemap({ key: 'map' });
  const tileset = map.addTilesetImage('pixel-adventure', 'tiles');
  this.plateforms = map.createStaticLayer('Plateforms', tileset, 0, 0).setScale(1);
  this.plateforms.setCollisionByExclusion(-1, true);

  //LEVEL OBJECTS
  //Sticks
  this.sticks = this.physics.add.group({
    allowGravity: false,
    immovable: true
  });
  // Let's get the sticks objects, these are NOT sprites
  const sticksObjects = map.getObjectLayer('sticks')['objects'];
  // Now we create sticks in our sprite group for each object in our map
  sticksObjects.forEach(sticksObject => {
    // Add new platforms to our sprite group, change the start y position to meet the platform
    console.log(sticksObject);
    let stick = this.sticks.create(sticksObject.x, sticksObject.y, tileset); //ERROR IS HERE
  }); 

I’ve tried a lot of things… But without solution,

Could you help me please ?

There’s this example:
https://labs.phaser.io/edit.html?src=src\game%20objects\tilemap\static\create%20from%20objects.js&v=3.9.0

Hi, It’s not my case, because in your example the coin is loaded separately, in my case i have on tile map for the level and the elements like box, platforms, etc…

Exact sorry, i didn’t see the load coin spritesheet.
I’m pretty sure to already read an answer to your question, but didn’t find it…
If i remember well, @samme gave the solution.

What’s the error you are seeing? I see that you are passing tileset into the group create() method when it wants a key: string

I would assume you want to give it the key of the tileset and the frame number of the tile you want that represents a stick?

Hi !

Exactly, i’m trying to pass a key to the create method from my tileset !

So i think your key is ‘tiles’ based on how you created the tileset and then the index that represents a stick you’ll have to look up in Tiled, I think it is “id”. Use the index number as the frame parameter so if your stick tile index is 34:

this,sticks.create(sticksObject.x, sticksObject.y, 'tiles', 34)

I try ! It’s adding the complete tile image in every objects positions and throw me an error message :
Texture.frame missing: 20

EDIT :

I was loaded my tiles as image, I switch to spritesheet, it works now !!! Thank you !! Juste a problem white selected image of the spritesheet :wink:

1 Like

Nice :slightly_smiling_face: