GithubHelp home page GithubHelp logo

fengmoyan / robotlegs-starling-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from s9tpepper/robotlegs-starling-plugin

1.0 2.0 0.0 335 KB

A Robotlegs plugin that adds some Robotlegs classes to support usage with the Starling framework.

robotlegs-starling-plugin's Introduction

robotlegs-starling-plugin

This plugin adds some classes to Robotlegs to support usage with the Starling framework. Because the Starling framework uses Stage3D and not the flash.display.DisplayList a StarlingContext must be used along with a StarlingMediator. The rest of the framework usage remains the same.

Pull Requests are encouraged! Please if you add/fix anything contribute it back! :)

Added Classes

  • StarlingMediatorMap.as
  • StarlingViewMap.as
  • StarlingViewMapBase.as
  • IStarlingMediatorMap.as
  • IStarlingViewMap.as
  • StarlingContext.as
  • StarlingMediator.as
  • StarlingCommand.as

Usage Example

Below are some excerpts from a very simple usage example. The .fxp file for the example file is in the Downloads section. Below are the key parts.

The main class set up remains the same:

package
{
	import com.example.MyGame;

	import flash.display.Sprite;
	import flash.events.Event;

	import org.robotlegs.mvcs.StarlingContext;

	import starling.core.Starling;

	public class Main extends Sprite
	{
		private var _starling:Starling;
		private var _starlingContext:StarlingContext;

		public function Main()
		{
			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}

		protected function onAddedToStage(event:Event):void
		{
			_starling = new Starling(MyGame, stage);
			_starling.start();
		}
	}
}

Inside the main Starling class (MyGame) sent into the first Starling constructor argument start a subclass of a StarlingContext instance. Usage of the StarlingContext is identical to the default Robotlegs Context class.

package com.example
{
	import flash.utils.setTimeout;

	import org.robotlegs.mvcs.StarlingContext;

	import starling.display.Sprite;
	import starling.events.Event;

	public class MyGame extends Sprite
	{
		private var _starlingContext:StarlingContext;

		public function MyGame()
		{
			super();

			_starlingContext = new MyStarlingGameContext(this);

			addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}

		private function onAddedToStage(event:Event):void
		{
			var secondView:SecondView = new SecondView();
			addChild(secondView);

			// Test mediator removal
			setTimeout(secondView.parent.removeChild, 3000, secondView);
		}
	}
}

Contents of the MyStarlingGameContext class (StarlingContext subclass):

package com.example
{
	import org.robotlegs.mvcs.StarlingContext;

	import starling.display.DisplayObjectContainer;

	public class MyStarlingGameContext extends StarlingContext
	{
		public function MyStarlingGameContext(contextView:DisplayObjectContainer=null, autoStartup:Boolean=true)
		{
			super(contextView, autoStartup);
		}

		override public function startup():void
		{
			mediatorMap.mapView(MyGame, MyGameMediator);
			mediatorMap.mapView(SecondView, SecondViewMediator);
			
			commandMap.mapEvent(FlashEvent.EVENT_NAME, EventCommand);

			super.startup();
		}
	}
}

Contents of the EventCommand (StarlingCommand sub-class, alternatively you can no subclass anything and declare a public execute() method, but do not use the default Robotlegs Command class, it will crash.)

package com.example
{
	import org.robotlegs.mvcs.StarlingCommand;

	public class EventCommand extends StarlingCommand
	{
		public function EventCommand()
		{
			super();
		}

		override public function execute():void
		{
			trace("EventCommand.execute()");
		}
	}
}

Alternate EventCommand class declaration (you dont get access to default things you might be used to with the default Robotlegs command class, like the injector, mediator map, etc):

package com.example
{
	public class EventCommand
	{
		public function EventCommand()
		{
		}

		public function execute():void
		{
			trace("EventCommand.execute()");
		}
	}
}

And finally, the contents of one of the mediators (SecondViewMediator):

package com.example
{
	import org.robotlegs.mvcs.StarlingMediator;

	public class SecondViewMediator extends StarlingMediator
	{
		public function SecondViewMediator()
		{
			super();
		}

		override public function onRegister():void
		{
			trace("SecondViewMediator.onRegister()");
		}

		override public function onRemove():void
		{
			trace("SecondViewMediator.onRemove()");
		}
	}
}

robotlegs-starling-plugin's People

Contributors

joshtynjala avatar s9tpepper avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.