Skip to content

Instantly share code, notes, and snippets.

@neuronix
Created September 26, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuronix/d81431c278eea4849a64580c78748150 to your computer and use it in GitHub Desktop.
Save neuronix/d81431c278eea4849a64580c78748150 to your computer and use it in GitHub Desktop.
package tests.reboot {
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.utils.setTimeout;
import starling.core.Starling;
import starling.display.Image;
import starling.display.Sprite;
import starling.textures.Texture;
public class MainTestRebootStandalone extends flash.display.Sprite {
[Embed(source="picture.png")]
public static const Picture:Class;
public var starling:Starling;
public function MainTestRebootStandalone() {
super();
setup();
}
public function setup() : void {
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
starling = new Starling(starling.display.Sprite, stage);
starling.addEventListener("rootCreated", starlingRootCreated);
starling.start();
}
protected function starlingRootCreated(event:*, root:starling.display.Sprite) : void {
starling.removeEventListener("rootCreated", starlingRootCreated);
ready();
}
public function ready() : void {
var q:Image = new Image(Texture.fromBitmap(new Picture() as Bitmap));
q.scale = 0.5;
q.x = randomInt(q.width, stage.stageWidth - q.width);
q.y = randomInt(q.height, stage.stageHeight - q.height);
(starling.root as starling.display.Sprite).addChild(q);
setTimeout(function () : void {
q.removeFromParent();
q.dispose();
reboot();
}, 5000);
}
public function reboot() : void {
setTimeout(function () : void {
starling.dispose();
starling = null;
setup();
}, 1);
}
public static function randomInt(low:int, high:int) : int {
return (Math.floor(Math.random() * (1 + high - low)) + low) as int;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment