Load actors from another scene

Justin

  • *
  • Posts: 4335
Load actors from another scene. Intended for loading enemy waves without switching scenes, but I'm sure it has other uses.

Code: [Select]
@:access(com.stencyl.Engine.loadActors)
@:access(com.stencyl.Engine.initActorScripts)
public static function loadActorsFromScene(sceneName:String):Void
{
var engine = Engine.engine;
var realScene = engine.scene;

engine.scene = GameModel.get().scenes.get(Script.getIDForScene(sceneName));
engine.scene.load();
engine.loadActors();
engine.initActorScripts();
engine.scene.unload();

engine.scene = realScene;
}

I'm not yet sure if anything weird happens with actor IDs or if it has other side effects.

To use it, put it in a freeform code behavior. Assuming the class name is "CreateActors", you can call it from anywhere with this line.

Code: [Select]
CreateActors.loadActorsFromScene("My Scene");

For Live Support: Join our discord server and ping me @justin.
I'm most often available between 8am and midnight Japan time. (GMT+9)

letmethink

  • *
  • Posts: 2547
I'd just like to say, I'm finding this really useful for certain aspects of UI such as menu screens and the like, so thanks for this share.
~Letmethink

yoplalala

  • *
  • Posts: 1530
I'd just like to say, I'm finding this really useful for certain aspects of UI such as menu screens and the like, so thanks for this share.

Nice . Indeed , like this you can design your menus in the scene instead of using blocks.