// Error on unmasking
package tests.genome
{
import com.genome2d.components.renderable.GShape;
import com.genome2d.context.GContextConfig;
import com.genome2d.Genome2D;
import com.genome2d.node.GNode;
import com.genome2d.textures.GTexture;
import com.genome2d.textures.GTextureManager;
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.events.MouseEvent;
/**
* All rights reserved.
* @author Lukas Damian Opacki
*/
public class BasicG2DMask extends MovieClip
{
private var rect:GShape;
private var triangle:GShape;
public function BasicG2DMask()
{
haxe.initSwc (this);
var config:GContextConfig = new GContextConfig (stage);
config.enableDepthAndStencil = true;
Genome2D.getInstance ().onInitialized.addOnce (onG2d);
Genome2D.getInstance ().init (config);
}
private function onG2d():void
{
var w:Number = 100;
var h:Number = 100;
var green:GTexture = GTextureManager.createTexture ("green", new BitmapData (100, 100, false, 0x00ff00));
var red:GTexture = GTextureManager.createTexture ("red", new BitmapData (100, 100, false, 0xff0000));
rect = GNode.createWithComponent (GShape) as GShape;
rect.texture = green;
rect.setup( [0, 0, w, 0, 0, h, 0, h, w, 0, w, h],
[0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
triangle = GNode.createWithComponent (GShape) as GShape;
triangle.texture = red;
triangle.setup( [0,h, w/2,0, w,h],
[0,1, .5,1, 1,1]);
Genome2D.getInstance ().root.addChild (rect.node);
Genome2D.getInstance ().root.addChild (triangle.node);
stage.addEventListener (MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener (MouseEvent.CLICK, onClick);
rect.node.mask = triangle.node;
}
private function onClick(e:MouseEvent):void
{
rect.node.mask = null;
}
private function onMouseMove(e:MouseEvent):void
{
rect.node.y = stage.mouseY;
rect.node.x = stage.mouseX;
}
}
}