Skip to content

Instantly share code, notes, and snippets.

@rishavs rishavs/Main.hx
Created Jan 16, 2020

Embed
What would you like to do?
Stuck in creating basic scene manager for haxe + openfl
package;
import openfl.text.TextField;
import openfl.events.KeyboardEvent;
import openfl.display.Sprite;
class Scene extends Sprite {
public function new()
{
super();
}
public function draw() {}
public function update() {}
public function destroy() {}
}
class LogoScn extends Scene
{
public function new()
{
super();
var t:TextField = new TextField();
t.x = 100;
t.y = 200;
t.text = "Logo Scene";
addChild(t);
}
}
class TitleScn extends Scene
{
public function new()
{
super();
var t:TextField = new TextField();
t.x = 100;
t.y = 200;
t.text = "Title Scene";
addChild(t);
}
}
enum Scenes {
LogoScn;
TitleScn;
}
class Main extends Sprite
{
public var previous_scene:Scenes;
public var current_scene:Scenes;
public function new()
{
super();
}
public function switch_scene_to(scene:Scenes):Void
{
previous_scene = current_scene;
trace("Scene switched from:" + previous_scene);
current_scene = scene;
trace("Scene switched to:" + current_scene);
var new_scene = new Scenes.{current_scene} // I am stuck here. No idea how I should call dynamic scene names
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):Void
{
switch (e.keyCode) {
case 49 :
trace('1 was pressed');
switch_scene_to(Logo);
case 50 :
trace('2 was pressed');
switch_scene_to(Title);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.