Hello,
it seems to be a simple question but I haven’t found it in the documentation.
So, how do I react to the “At the beginning of the scene
” event in Javascript?
Here the documentation for the function;
gdjs.evtTools.runtimeScene.sceneJustBegins
The function check if it’s the first frame, so the JSevent have to be called at each frame, not in a subevent.
So I guess you have to code:
if( gdjs.evtTools.runtimeScene.sceneJustBegins() ){
// add more code here
}
Thanks for that hint! I’ve overseen the function sceneJustBegins()
. Using isFristFrame()
works fine like this:
if(runtimeScene.getTimeManager().isFirstFrame()){
// Do the magic
}
The example with gdjs.evtTools.runtimeScene.sceneJustBegins()
leads to an Error (Uncaught TypeError: Cannot read property 'getTimeManager' of undefined
) ¯\_ (ツ)_/¯
That is kinda obviously you take a look at the docs or bouge screenshot from the implementation, since that call is not passing in runtime scene as an argument, even though this is a wrapper function calling methods on it.
Not really, any code used in gdjs.evtTools are functional wrapper functions for the JavaScript API to be called by the events code generator. You should use the JavaScript API directly when working in JavaScript whenever possible, not those wrappers.