-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PutTileAt sid wrong if layer does not use all tilesets #5931
Comments
What is your |
Hi @samme, The example is using a tiled tilemap from this tutorial. I have simply added two additional tilesets and an additional empty layer to the tiled file. After installing all packages with Here is the code of the example: import "phaser";
export default class Demo extends Phaser.Scene {
constructor() {
super("demo");
}
preload() {
this.load.image("tiles2", "assets/tilesets/debug.png");
this.load.tilemapTiledJSON("map", "assets/tilemaps/tuxemon-town.json");
}
create() {
const map = this.make.tilemap({ key: "map" });
const tileset2 = map.addTilesetImage("debug", "tiles2");
const myNewLayer = map.createLayer("MyNewLayer", [tileset2], 0, 0);
const tileGid = tileset2.firstgid;
map.putTileAt(tileGid, 5, 5, false, myNewLayer);
}
}
const config = {
type: Phaser.AUTO,
backgroundColor: "#125555",
width: 800,
height: 600,
scene: Demo,
};
const game = new Phaser.Game(config); |
I ran in to this as well and meant to open a PR, but instead just made a TODO in my code and as a workaround added each tileset to every layer so that sid are correct. @christianvoigt I'll probably still open a quick PR for it if you aren't already |
@fielding great, go ahead, I'm currently not working on the project where I use this. |
I can't seem to get this working even with adding each tileset to every tilemap layer. :/ |
Any progress here? The same issue comes up if you create multiple tilesets and multiple layers. One of most frustrating Phaser tasks yet have been creating a tilemap NOT using Tiled... the GID system is very unclear. It seems as if every added tileset stacks it's tiles/frames on top of the other, so if you add 3 tilesets of 50 frames each, tileset 1 will use frames 0-49, 2 will use 50-99, and 3 will use 100-149. I had this working briefly, just having to tell each tileset with it's first gid is:
I recently had to introduce a 4th layer before the other 3, so I adjusted all the numbers, but no dice, constant error at the same place, when I can't tell what is even the point of telling each layer which tileset(s) it should use. |
This may be #6474 . GIDs are "global" because they're unique within the tilemap (not a tileset). You assign GIDs with the |
Yah I noted all of that, and it more-or-less would be fine on it's own, but causes this error when a particular layer is assigned not-all tilesets, hence having to assign all tilesets to all layers, making any assignment effectively meaningless. I noticed while debugging with 4 tilesets and 4 layers, that if I assigned tilesets indexed 1 & 2 to layer 0, So it seems that you need to include at least every tileset from the start: |
Thank you for submitting this issue. We have fixed this and the fix has been pushed to the |
@photonstorm In example I tried to use this code After this line 26: But in console I got error message:
|
@poodoff yeah someone told me on Discord, this is now fixed in main branch and will be in 3.61 Beta 2. |
Version
Description
I am using a tilemap JSON file from Tiled with three embedded tilesets ("tileset1", "tileset2", "tileset3"). I have defined a new tile layer in Tiled "MyNewLayer" and recreated it in my game with:
If I use
map.putTileAt(tileGid, x, y, false, myNewLayer)
the following error is thrown:TypeError: Cannot read properties of undefined (reading 'tileWidth')
The issue is caused by
var sid = tiles[index][2];
inPutTileAt.js
. This tileset id is wrong if not all tilesets have been added to the layer. In my case Phaser assumes the sid is "2" when it should actually be "0".So if I change my code accordingly, the error disappears:
It is probably not the intention to require that all tilesets have to be added to all layers, so I think this is a bug.
The text was updated successfully, but these errors were encountered: