melonJS
melonJS copied to clipboard
TMX Object and Points / Vector2d throws exception
If you are submitting a bug report, please respect the below template :
OS platform / Browser
e.g. Mac OS 12.4 / Chrome 103
melonJS version
13.0
Bug description
I am trying to use an object layer (amongst several other tiled layers) with some objects in there which should describe a Path my enemy should walk along. I am using either the Point object from Tiled or a Spline for this approach. Both don't work as MelonJS seems to expect Renderable resources as object names.
GitHub repository: https://github.com/wpernath/quarkus-grumpycat
Steps to reproduce the bug
- Create a new map in Tiled with just tiled map layers.
- Create an Object layer
- Add a point and rename it to "me.Vector2d"
- In MelonJS try to load that map --> exception
- Melon tries to set a "z" property on Vector2d which does not exist
Console log Extract
Uncaught TypeError: Cannot set properties of undefined (setting 'z') at TMXTileMap.getObjects (melonjs.module.js:29278:23) at TMXTileMap.addTo (melonjs.module.js:29127:12) at loadTMXLevel (melonjs.module.js:29408:9) at safeLoadLevel (melonjs.module.js:29376:3) at Object.load (melonjs.module.js:29515:9) at LevelManager.prepareCurrentLevel (level.js:296:73) at PlayScreen.setupLevel (play.js:176:78) at PlayScreen.onResetEvent (play.js:108:12) at PlayScreen.reset (melonjs.module.js:24167:25) at Color._switchState (melonjs.module.js:24535:33)
Other questions
- Why are you using the 'name' property of a tiled object to instantiate a new object if there is a 'class' property in Tiled as well? I tried to use any name for my Path objects, but this would then raise an error saying that there is no class in my game with that name.
- Using no 'name' property in Tiled also results in "no object found" error
- If your map only consists of tiled map layers, with a special layer (like my 'persons' layer) containing a tile for each enemy, how would you add path descriptions in Tiled for those enemies if Tiled objects are not meant to be used for this feature?
Thank you very much for your help!
Hi, thanks for the report.
the thing is that those features you are using have been added in recent versions of Tiled and yet not added in melonJS, like the class property was added in the just released 1.9 version of Tiled (and literally just added in the current working build of melonJS, see here, although not fully tested).
also, since the move to pure es6, the trick where we were able to instantiate a melonJS class from a Tiled map does not work anymore simply because the me namespace is not defined anymore globally as it was with es5.
so while we work on those things, what you can try (if you don't mind) :
- register
pointas a Vector object by addingpool.register("Point", Vector2d, true);in your game. This said I'm almost sure it will not work to be honest, but worth a try. - maybe rather use Polyline to define your path, that's what I usually do for my entities. the other benefits is that it draws a line on screen (I mean in the editor) which makes it easier to visualise them in the editor.
thanks for your ticket and support !
and I will look into this as soon as the 13.1 release is published (which should be today anyway!)
and 13.1.0 was just released ! Followed by a quick 13.1.1 fix but just for date and change tracking :)
Thanks a lot for your quick reply. I have managed to get it by
- Creating my own class called WayPoint
- This class needs a 'z' property
- This class needs an 'update()' method (which does nothing)
- Registering WayPoint in the global pool as you mentioned
- Parsing path data in my own LevelManager
- Using those way points in my enemy implementation
Thanks a lot and I am looking forward seeing your awesome ongoing work on MelonJS!
BTW, are you interested in contributions of some UI elements? For example this one:
- BaseTextButton
- With the base class BaseClickableComponent
?
@wpernath sorry I did not reply about the UI elements, I definitely would love to reuse the base text round rect button class, I would make a few changes to make it even more generic, and rather rely on this base class, but it would be a nice addition for some default UI element !
[edit] happy to see as well someone else (I mean other than me) using the RoundRect stuff we added recently ;)
No problem.
I was about to create a pull request, but feel free to implement it as you like.
I was creating a generic clickable container as I had some issues with GUI_Object, because that is inheriting from Sprite.
Perhaps I just overlooked something, I am still learning. As always. :-D
Olivier Biot @.***> schrieb am Do. 11. Aug. 2022 um 01:45:
@wpernath https://github.com/wpernath sorry I did not reply about the UI elements, I definitely would love to reuse the base text round rect button class, I would make a few changes to make it even more generic, and rather rely on this base https://github.com/melonjs/melonJS/blob/master/src/renderable/GUI.js class, but it would be a nice addition for some default UI element !
— Reply to this email directly, view it on GitHub https://github.com/melonjs/melonJS/issues/1117#issuecomment-1211410942, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJF76SXZ34JYHKK2D5N6XLVYQ5J3ANCNFSM556XTIBQ . You are receiving this because you were mentioned.Message ID: @.***>
oh you are right that GUI_Object inherit from Sprite..... which does not make it generic "enough" for a base text button class (only using RoundRect and a Text component).
I think that would be actually a good opportunity to look back at the basic UI object and maybe do some revamping as well, adding more stuff indeed and maybe changing the one we have currently into something else (doing more or less I don't know)
Well then, let me create the pull request with the two classes inside and if you like it, you take it. If not, please feel free to do whatever you want with the code.
Olivier Biot @.***> schrieb am Do. 11. Aug. 2022 um 09:28:
oh you are right that GUI_Object inherit from Sprite..... which does not make it generic "enough" for a base text button class (only using RoundRect and a Text component).
I think that would be actually a good opportunity to look back at the basic UI object and maybe do some revamping as well, adding more stuff indeed and maybe changing the one we have currently into something else (doing more or less I don't know)
— Reply to this email directly, view it on GitHub https://github.com/melonjs/melonJS/issues/1117#issuecomment-1211640477, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJF76S6TFNLJMJHENZT2STVYSTRPANCNFSM556XTIBQ . You are receiving this because you were mentioned.Message ID: @.***>
@wpernath work in progress here, but for now I added a new "Point" geometry object, and parsed the Tiled (TMX) point to actually instantiate those points. I thought about using Vector object, but I'd rather have a geometry "shape" Point similarly to a rectangle and polygon being used when parsing the map.
I still need to play more with it, but at least some progress here as well
Hi @wpernath, with the 13.2 version published, and support for Point in Tiled, I will close this ticket. I know that you might use this in a different way, but since at least it does not trigger any exception anymore and do parse/add those point in the live map, it does address the initial ticket.
we can open another one if you revisit the feature later based on the new implementation and find anything else !