Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The source of the demo used to showcase the GodRayPlane class in the Starling Wiki.
package
{
import flash.geom.Point;
import flash.ui.Keyboard;
import starling.core.Starling;
import starling.display.DisplayObjectContainer;
import starling.display.Image;
import starling.events.KeyboardEvent;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
import starling.extensions.GodRayPlane;
import starling.textures.Texture;
public class Demo_GodRayPlane extends DisplayObjectContainer
{
[Embed(source="../assets/water.jpg")]
private static const BackgroundAsset:Class;
private var _godRays:GodRayPlane;
public function Demo_GodRayPlane()
{
var background:Image = new Image(Texture.fromEmbeddedAsset(BackgroundAsset));
addChild(background);
_godRays = new GodRayPlane(background.width, background.height);
_godRays.speed = 0.1;
_godRays.size = 0.1;
_godRays.skew = 0;
_godRays.shear = 0;
_godRays.fade = 1;
_godRays.contrast = 1;
_godRays.size = 0.065;
_godRays.shear = 0.5;
_godRays.skew = -0.26;
_godRays.contrast = 2;
addChild(_godRays);
Starling.juggler.add(_godRays);
addEventListener(TouchEvent.TOUCH, onTouch);
Starling.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKey);
}
private var _testProperty:String = "skew";
private function onKey(event:KeyboardEvent, keyCode:uint):void
{
switch (keyCode)
{
case Keyboard.P: _testProperty = "speed"; break;
case Keyboard.I: _testProperty = "size"; break;
case Keyboard.K: _testProperty = "skew"; break;
case Keyboard.H: _testProperty = "shear"; break;
case Keyboard.F: _testProperty = "fade"; break;
case Keyboard.C: _testProperty = "contrast"; break;
}
trace("now modifying " + _testProperty);
}
private function onTouch(event:TouchEvent):void
{
var touch:Touch = event.getTouch(this, TouchPhase.MOVED);
if (touch)
{
var movement:Point = touch.getMovement(this);
var delta:Number = movement.x / 200;
_godRays[_testProperty] += delta;
trace("godRays." + _testProperty + " = " + _godRays[_testProperty]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.