jsonjavascript-objectsphaser-frameworktiledphaserjs

Create from objects not working in Phaser 2 CE


When working with Phaser3, this worked:

map.createFromObjects('Layer_Objects', 'sprite', { key: 'item' })

'Layer_Objects' is the name of layer in Tiled. 'sprite' is the image name that will replace the itens created in the layer. 'item' is the name of points created with Tiled. I've tried many other options, but none of them worked, some of them asks for a GID, but Tiled is not generating this property. This project is being made with Phaser 2 CE, latest version.


Solution

  • After some research, this code works:

    this.map.createFromObjects('Layer_Objects', 'item', 'sprite', 0, true, false, this.itens);
    

    Layer_Objects = name of layer objects created with Tiled

    item = name of itens (points) created on Layer_Objects (they will be dynamically replaced for sprites in the code)

    sprite = Name of spritesheet of sprite that will replace the itens created on layer by Tiled. It works even if the spritesheet has only 1 frame (index 0)

    0 = Index of current frame from spritesheet.

    true, false = Are default values (for existing sprite and created item will be on camera area), I didn't need to change those values

    this.itens = The group of itens which those itens just created will belong