Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

How to add an event using JS dynamically?

Hi guys, I am new to this forums. Hopefully I post this thread in the right place and use the language correctly.
I get a problem that puzzled me for a long time, that is as the title suggested how to create an event after the map is created using script.
So far, my approach is something like this (guess codes means more than my poor English)
in Console while the map is loaded:
JavaScript:
var e = JsonEx.parse(json)// json is some Json string
var l = $dataMap.events.length;
$dataMap.events[l] = e;
$gameMap._events[l] = new Game_Event($gameMap._mapId, l);
The result is that the event is created (somehow) and can be triggered while its animation does not play.
I know I must miss something there, but I have no clue how to fix it.
I really don't understand the source code very well especially when it comes to lower level.
Could anybody help me solve this? Or is there is a more appropriate method?
Many Thanks!
========================================================
solved(from other site) :
refreshing the display container works:
JavaScript:
SceneManager._scene.children = []; SceneManager._scene.createDisplayObjects();
========================================================
or better:
add the new event to the display container only
JavaScript:
SceneManager._scene.children[0]._tilemap.addChild(new Sprite_Character($gameMap._events[l]));
 
Last edited:
Top