Created
March 6, 2013 18:51
-
-
Save raimonds1503/5101967 to your computer and use it in GitHub Desktop.
Lisntening for events
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 blocked.events.NewWorldEvent; | |
import blocked.worlds.Lobby; | |
import blocked.worlds.World; | |
import blocked.worlds.WorldManager; | |
import feathers.controls.Button; | |
import feathers.controls.Callout; | |
import feathers.controls.Label; | |
import feathers.themes.AeonDesktopTheme; | |
import starling.events.Event; | |
import starling.display.Sprite; | |
/** | |
* ... | |
* @author Raimonds Zarins | |
*/ | |
public class Game extends Sprite | |
{ | |
public function Game() | |
{ | |
this.addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
private function init(e:Event):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
trace("Starling running"); | |
GV.worldManager = new WorldManager(); | |
this.addChild(GV.worldManager); | |
GV.worldManager.setWorld(new Lobby()); | |
GV.worldManager.addEventListener(NewWorldEvent.CHANGE, addToStage); | |
} | |
private function addToStage(e:NewWorldEvent):void | |
{ | |
this.addChild(e.world as World); | |
trace("Handling new world event!"); | |
} | |
} | |
} |
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 blocked.events.NewWorldEvent; | |
import blocked.worlds.World; | |
import blocked.worlds.WorldManager; | |
import net.hires.debug.Stats; | |
import playerio.Client; | |
import playerio.Connection; | |
import starling.core.Starling; | |
import starling.display.Sprite; | |
import starling.events.EventDispatcher; | |
/** | |
* ... | |
* @author Raimonds Zarins | |
*/ | |
public class GV | |
{ | |
public static var gameFramework:Starling; | |
public static var fpsStats:Stats; | |
public static var currentClient:Client; | |
public static var currentConnection:Connection; | |
public static var userName:String; | |
public static var userID:String; | |
public static var currentWorld:World = null; | |
public static var worldManager:WorldManager; | |
} | |
} |
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 blocked.events | |
{ | |
import blocked.worlds.World; | |
import starling.events.Event; | |
/** | |
* ... | |
* @author Raimonds Zarins | |
*/ | |
public class NewWorldEvent extends Event | |
{ | |
public static const CHANGE:String = "WorldChange"; | |
private var rWorld:World; | |
public function NewWorldEvent(type:String, result:World, bubbles:Boolean=false) | |
{ | |
super(type, bubbles); | |
this.rWorld = result; | |
trace("Dispatching NewWorldEvent!"); | |
} | |
public function get world():World { return this.rWorld; } | |
} | |
} |
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 blocked.worlds | |
{ | |
import blocked.events.NewWorldEvent; | |
import starling.display.Sprite; | |
import starling.events.EventDispatcher; | |
/** | |
* ... | |
* @author Raimonds Zarins | |
*/ | |
public class WorldManager extends Sprite | |
{ | |
public function WorldManager() | |
{ | |
} | |
public function setWorld(world:World):void | |
{ | |
trace("Changing world"); | |
if(GV.currentWorld != null) | |
GV.currentWorld.unloadWorld(); | |
GV.currentWorld = world; | |
dispatchEvent(new NewWorldEvent(NewWorldEvent.CHANGE, world)); | |
if(GV.currentWorld.loaded) | |
GV.currentWorld.loadWorld(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment