Load assets into haxe-starling via runtime texture packer

Much like my previous post which demonstrated how to Load assets into away3d-openfl via runtime texture packer, this post will establish the same work flow only for Starling instead of Away3D.

To achieve this we are again going to be using the texture-packer library, however this time we’re going to use the StarlingConverter class. In a nutshell this class’s parse method accepts an openfl display object and will convert it’s top level children into textures and then return an IStarlingPackage which contains a number of items that can be used within the starling display list.

package net.peteshand.swfAssetsToStarling;

import com.imagination.texturePacker.api.convert.starling.IStarlingPackage;
import com.imagination.texturePacker.impl.convert.starling.StarlingConverter;
import openfl.events.MouseEvent;
import starling.core.Starling;
import starling.display.Sprite;
import starling.display.Sprite3D;
import starling.events.Event;

 * ...
 * @author P.J.Shand
class StarlingRoot extends Sprite
	var starlingPackage:IStarlingPackage;
	var container:Sprite3D;

	public function new() 
		addEventListener(Event.ADDED_TO_STAGE, OnAdd);
	private function OnAdd(e:Event):Void 
		removeEventListener(Event.ADDED_TO_STAGE, OnAdd);
		container = new Sprite3D();
		container.x = stage.stageWidth / 2;
		container.y = stage.stageHeight / 2;
		var clip = new Mc_Assets();
		starlingPackage = StarlingConverter.parse(clip);
		Starling.current.nativeStage.addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove);
	private function OnMouseMove(e:MouseEvent):Void 
		container.rotationY = ((Starling.current.nativeStage.mouseX / stage.stageWidth) - 0.5) * Math.PI * -0.5;
		container.rotationX = ((Starling.current.nativeStage.mouseY / stage.stageHeight) - 0.5) * Math.PI * 0.5;

The result of the above code can be viewed below in both the flash and html5 targets.

Flash Version

HTML5 Version