Created
January 16, 2020 18:40
-
-
Save rishavs/53676dc24f8e12b2d953a3e34c190f5a to your computer and use it in GitHub Desktop.
Stuck in creating basic scene manager for haxe + openfl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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