E: me@sabisin.com | T: +49.151.68651209

Hungry Hero goes Open Source

hUngaryhEro

Hungry Hero is an open source Flash game built on Starling Framework. This game is built to give developers an idea of how a typical Starling based game looks like. The basic idea is to showcase how easy it is to build a Stage3D game, giving your games the power of GPU rendering or Hardware acceleration.

http://www.hsharma.com/games/hungry-hero-goes-open-source/

Actionscript 3 : Toggling a Boolean

No need of conditional statement to figure out which direction to toggle a Boolean value.

var iStRue:Boolean;
iStRue = !iStRue;
trace(iStRue);      //true
iStRue = !iStRue;
trace(iStRue);      //false

Device Shake – Accelerometer

Heres a small snippet to detect shakes on mobile devices with accelerometer:

var lastShake:Number = 0;
var shakeWait:Number = 600;
 
var acc:Accelerometer = new Accelerometer();
acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);
 
function onAccUpdate(evt:AccelerometerEvent):void
{
	if(getTimer() - lastShake > shakeWait && (evt.accelerationX >= 1.5 || evt.accelerationY >= 1.5 || evt.accelerationZ >= 1.5))
	{
		sHakeiT();
		lastShake = getTimer();
	}
}
 
function shakeIt()
{
	trace("shakeIt();");
}

To detect software render mode with Flare3D

For Flare3D the context object is exposed through the scene.context object. So to find out if you are using software you wait for your scene to initialize.

private function iNitsCene():void
{
	scene = new Scene3D(this);
	scene.addEventListener(Scene3D.COMPLETE_EVENT, Complete);
}

private function Complete(eVt:Event):void
{
	//Context3DRenderMode.AUTO
	if(scene.context.driverInfo == Context3DRenderMode.SOFTWARE || scene.context.driverInfo.indexOf("Software") != -1)
	{
		// Handle notifying users about their unsupported computers here.
	} else {
		// Start up the awesome!
	}
}

Update:
A good practice is to rely on Context3DRenderMode.AUTO, Stage3D will try to run on hardware, then fallback to software if the drivers are too old (released before January 1st, 2009), if the graphics card is not support Pixel Shader 2.x or if the graphics card chipset is blacklisted.

mYsTage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated);

// request the 3d context
mYsTage3D.requestContext3D(Context3DRenderMode.AUTO);

// when the context is available, grab it
function onContextCreated ( eVt:Event ):void
{
	// grab the 3D context
	var cOntext3D:Context3D = mYsTage3D.context3D;

	// are we running hardware of software ?
	var isHW:Boolean = context3D.driverInfo.toLowerCase().indexOf("software") == -1;
}

as3: removing duplicates from an array

Removing duplicate items from an array in one line of ActionScript 3

var tMpaRr:Array = ["a","b","b","c","b","d","c"];

var aRr:Array = tMpaRr.filter(function (a:*,b:int,c:Array):Boolean { return ((aRr ? aRr : aRr = new Array()).indexOf(a) >= 0 ? false : (aRr.push(a) >= 0)); }, this);

trace(aRr); //a,b,c,d