Skip to content

Instantly share code, notes, and snippets.

@dakom
Created August 24, 2014 14:45
Show Gist options
  • Save dakom/db3a73214004424ea20b to your computer and use it in GitHub Desktop.
Save dakom/db3a73214004424ea20b to your computer and use it in GitHub Desktop.
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.events.TimerEvent;
import flash.geom.Matrix;
import flash.utils.Timer;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.TouchEvent;
import starling.filters.BlurFilter;
public class TestingRoot extends Sprite
{
private var images:Array;
public function TestingRoot()
{
super();
}
public function startApp():void
{
var img:Image;
var timer:Timer;
images = new Array();
img = getImage('circle', 0xFF0000);
images.push(img);
addChild(img);
img = getImage('rect', 0x00FF00);
images.push(img);
addChild(img);
img = getImage('circle', 0x0000FF);
images.push(img);
addChild(img);
img = getImage('rect', 0xFFFF00);
images.push(img);
addChild(img);
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, timerStep);
timer.start();
}
private function timerStep(evt:TimerEvent = null) {
var img:Image;
images.push(images.shift());
removeChildren();
//Add them back with new order
for each(img in images) {
addChild(img);
}
flatten();
}
private function getImage(type:String, color:uint):Image {
var bmd:BitmapData;
var shape:Shape;
var bmp:Bitmap;
var img:Image;
var size:uint = randomIntegerBetween(100, 300);
var mat:Matrix = null;
shape = new Shape();
shape.graphics.beginFill(color);
if(type == 'rect') {
shape.graphics.drawRect(0,0,size,size);
} else {
shape.graphics.drawCircle(0,0,size/2);
mat = new Matrix();
mat.translate(size/2, size/2);
}
shape.graphics.endFill();
bmd = new BitmapData(shape.width, shape.height,true, 0);
bmd.draw(shape, mat);
bmp = new Bitmap(bmd);
img = Image.fromBitmap(bmp);
img.x = 500;
img.y = 200;
img.filter = BlurFilter.createDropShadow();
img.addEventListener(TouchEvent.TOUCH,onTouchHandler);
bmd.dispose();
return(img);
}
private function onTouchHandler(evt:TouchEvent) {
}
private function randomIntegerBetween(min:int,max:int):int {
return(min + Math.round(Math.random()*(max-min)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment