Create a gist now

Instantly share code, notes, and snippets.

@amosl / Secret
Created Mar 22, 2014

What would you like to do?
Spot Light
package ui
import flash.display.Bitmap;
import starling.display.BlendMode;
import starling.display.Image;
import starling.display.Quad;
import starling.textures.RenderTexture;
import starling.textures.Texture;
public class Spotlight extends Image
private var scrWidth:Number;
private var scrHeight:Number;
private var mAlpha:Number;
private var mBuffer:RenderTexture;
private var mOverlay:Quad;
private var mSpot:Image;
private static var OVAL_IMG_CLS:Class;
public function Spotlight(w:Number, h:Number)
scrWidth= w;
mBuffer= new RenderTexture(scrWidth/2, scrHeight/2, false);
public function create(alphaVal:Number=0.7, color:uint= 0x333333):void
mAlpha= alphaVal;
mOverlay= new Quad(scrWidth/2, scrHeight/2, color); // size is 1/4 of the screen
var ovalImg:Bitmap = new OVAL_IMG_CLS();
mSpot= new Image(Texture.fromBitmap(ovalImg, false));
mSpot.pivotX= mSpot.width/2;
mSpot.pivotY= mSpot.height/2;
// Place spot and set blendMode to erase
mSpot.x = mOverlay.width/2;
mSpot.y = mOverlay.height/2;
mSpot.blendMode= BlendMode.ERASE;
// Draw the texture
this.touchable = false;
this.scaleX = this.scaleY = 2; // Scale by 2
override public function dispose():void
mBuffer= null;
mSpot= null;
public function updateSpot(xp:Number, yp:Number, szX:Number=0, szY:Number=0):void
mSpot.x = xp/2;
mSpot.y = yp/2;
if (szX > 0) mSpot.width = szX/2;
if (szY > 0) mSpot.height = szY/2;
// Redraw
private function drawElements():void
mBuffer.draw(mOverlay, null, mAlpha);

This comment has been minimized.

Show comment Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment