-
-
Save anonymous/1039a2cd43b59d3bbf7cbdd58d3b4fb3 to your computer and use it in GitHub Desktop.
The simplified MaskScene of the Starling Demo, using an axis-aligned Quad.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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