Thanks for a fun and edifying challenge, @marioeligi!
What I also myself found immediately unintuitive, was that one cannot directly compare two Tiles OR two Tile Location objects directly to eachother, like you attempt with this statement:
The reason seems to be that two (instances?) of an object can not be equal and there is no _.isequal() method defined, as discussed by @cosmoscowboy et.al. here:
But there are other working solution which you could use, some of which I have played around with in this example:
- Compare both the column and row(or y and x) properties of the Tile Location Objects in the arrays and the tilemap location object of mySprite, respectively, against eachother, which give unique enough comparisons,
- Put the Tile Images in arrays instead of the Tile Location objects of the Tiles and compare those instead against the image of the tile that mySprite is on, or
- Keep Tile Location objects in arrays and compare the images of these to the image of the tile that mySprite is on.
All 3 above work with varying degree of efficiency, but you can see for the green grass tiles, that none of the direct object comparisons work.
There are probably other and more efficient ways to do this, but that would be a question for other more experienced forum members. I never, for instance, figured out @NightIsland’s myTile.tileSet methodology for the same type of comparisons discussed here: