Posts Tagged Starling

Tricks when starting using the Starling framework

I am working on my next game, well trying to. I am a bit lazy but I am fighting that. Anyway I came to a point where performance was an issue in the prototype, so I decided it was time to jump into the Starling Framework.

I have been wanting to try it for some time and I must say it was quite easy to port my existing code to it since it uses the same API than the Flash display list. But there are a lot of little things that are different. I’m am going to list a few gotchas, but first I think every one new to Starling should read Thibault Imbert book (which is free) about it. It is only 122 pages long and it took me about 20 mins to go through it. Also the wiki on the starling framework website is quite useful.

Starling; the walled garden

Here is the code you need to start Startling:

_starling = new Starling(Game, stage);
_starling.start();

Game being a class where you will control what will happen inside of Starling (also called the Root Class). Now you see my next game interface will use the normal Flash display list, but from it the user will be able to change stuff that happens on the graphics inside Starling. So I need a way to communicate with it, but there is no easy way to access the Game class… Here is the way I found:

_starling.addEventListener(Event.ROOT_CREATED, _onRootCreated);
private function _onRootCreated(event:Event):void {
	_starling.removeEventListener(Event.ROOT_CREATED, _onRootCreated);
	_game = Starling.current.stage.getChildAt(0) as Game;
	_game.init(_whateverData);
}

If you ask me this is a bit hackish, mostly the stage.getChildAt(0) but it works. I think you should just be able to access it using Starling.rootClass but that is just me I guess. I read somewhere that you could listen to the Event.CONTEXT3D_CREATE but that didn’t work in the latest version.

Little differences

So they wanted Starling to be similar to the display list but some little differences remained. The first one I noticed was that the rotation property on a DisplayObject is in radians instead of degrees. A bit annoying but not really a huge thing. Starling comes with a utility function to convert angles that you can find here: starling.utils.deg2rad. They did this in order to be consistent with the Sparrow framework; not sure why Flash people should care but hey, what can you do…

Also if you are looking for filters on display objects, stop looking it’s not there.

Finally the is 2 great new properties on display object pivotX and pivotY which allow you to change the origin point which is really useful in rotations and scaling.

Well that is it for now, as I play more with it I should find more stuff and I will edit this post. Also, I will be working on a book soon, so I might not feel like writing on this blog too ( you know, like writing too much in one day).

, , ,

3 Comments