Skip to content

Instantly share code, notes, and snippets.

/MaskScene.as Secret

Created April 21, 2016 06:49
Show Gist options
  • Save anonymous/1039a2cd43b59d3bbf7cbdd58d3b4fb3 to your computer and use it in GitHub Desktop.
Save anonymous/1039a2cd43b59d3bbf7cbdd58d3b4fb3 to your computer and use it in GitHub Desktop.
The simplified MaskScene of the Starling Demo, using an axis-aligned Quad.
package scenes
{
import flash.geom.Point;
import starling.core.Starling;
import starling.display.Image;
import starling.display.Quad;
import starling.display.Sprite;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
public class MaskScene extends Scene
{
private var _contents:Sprite;
private var _mask:Quad;
public function MaskScene()
{
_contents = new Sprite();
addChild(_contents);
var stageWidth:Number = Starling.current.stage.stageWidth;
var stageHeight:Number = Starling.current.stage.stageHeight;
var touchQuad:Quad = new Quad(stageWidth, stageHeight);
touchQuad.alpha = 0; // only used to get touch events
addChildAt(touchQuad, 0);
var image:Image = new Image(Game.assets.getTexture("flight_00"));
image.x = (stageWidth - image.width) / 2;
image.y = 80;
_contents.addChild(image);
_mask = new Quad(100, 100);
_mask.alignPivot();
_contents.mask = _mask;
addEventListener(TouchEvent.TOUCH, onTouch);
}
private function onTouch(event:TouchEvent):void
{
var touch:Touch = event.getTouch(this, TouchPhase.HOVER) ||
event.getTouch(this, TouchPhase.BEGAN) ||
event.getTouch(this, TouchPhase.MOVED);
if (touch)
{
var localPos:Point = touch.getLocation(this);
_mask.x = localPos.x;
_mask.y = localPos.y;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment