Skip to content
Browse files

0.3.4 Example FIXES

  • Loading branch information...
1 parent def9db1 commit e93b1e668ee830b2cb73b0720f233f9673c80d5f @pshtif committed
View
BIN examples/assets/ball.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
23 examples/examples/Assets.as
@@ -0,0 +1,23 @@
+package examples
+{
+ public class Assets
+ {
+ [Embed(source = "./assets/mines.xml", mimeType = "application/octet-stream")]
+ static public const MinesXML:Class;
+
+ [Embed(source = "./assets/mines.png")]
+ static public const MinesGFX:Class;
+
+ [Embed(source = "./assets/ninja.xml", mimeType = "application/octet-stream")]
+ static public const NinjaXML:Class;
+
+ [Embed(source = "./assets/ninja.png")]
+ static public const NinjaGFX:Class;
+
+ [Embed(source = "./assets/crate.jpg")]
+ static public const CrateGFX:Class;
+
+ [Embed(source = "./assets/ball.png")]
+ static public const ParticleGFX:Class;
+ }
+}
View
170 examples/examples/CameraBasicExample.as
@@ -0,0 +1,170 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DCamera;
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+
+ import flash.display.Sprite;
+ import flash.events.KeyboardEvent;
+
+ public class CameraBasicExample extends Example
+ {
+ private var __cMineTexture:G2DTextureAtlas;
+ private var __cNinjaTexture:G2DTextureAtlas;
+
+ private const COUNT:int = 500;
+
+ private var __iClipCount:int;
+ private var __nCameraMove:Number = 4;
+ private var __nCameraRotation:Number = .05;
+ private var __nCameraZoom:Number = .02;
+
+ public function CameraBasicExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>CameraViewPortsExample</b>\n"+
+ "<font color='#FFFFFF'>Just to showcase 3 cameras each using a different viewport rectangle, its own transform and custom clear color background.\n"+
+ "<font color='#FFFF00'>";
+ }
+
+ override public function init():void {
+ super.init();
+
+ __cMineTexture = G2DTextureAtlas.createFromBitmapDataAndXML("mine", (new Assets.MinesGFX()).bitmapData, XML(new Assets.MinesXML()));
+ __cNinjaTexture = G2DTextureAtlas.createFromBitmapDataAndXML("ninja", (new Assets.NinjaGFX()).bitmapData, XML(new Assets.NinjaXML()));
+
+ __iClipCount = 0;
+ addSprites(COUNT);
+
+ _cGenome.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.add(onUpdate);
+
+ var camera:G2DCamera;
+ camera = _cCamera.getComponent(G2DCamera) as G2DCamera;
+ camera.normalizedViewWidth = 1/3;
+ camera.backgroundRed = .2;
+
+ var cameraNode:G2DNode = new G2DNode("camera1");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ camera.normalizedViewWidth = 1/3;
+ camera.normalizedViewX = 1/3;
+ camera.backgroundGreen = .2;
+ _cGenome.root.addChild(cameraNode);
+
+ cameraNode = new G2DNode("camera2");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ camera.normalizedViewWidth = 1/3;
+ camera.normalizedViewX = 2/3;
+ camera.backgroundBlue = .2;
+ _cGenome.root.addChild(cameraNode);
+
+ updateInfo();
+ }
+
+ override public function dispose():void {
+ super.dispose();
+
+ __cMineTexture.dispose();
+ __cNinjaTexture.dispose();
+
+ _cGenome.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.removeAll();
+ }
+
+ private function createSprite(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var sprite:G2DSprite = node.addComponent(G2DSprite) as G2DSprite;
+ sprite.setTexture(__cMineTexture.getTexture("mine2"));
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ return node;
+ }
+
+ private function createClip(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cMineTexture);
+ clip.setFrameRate(Math.random()*10+3);
+ clip.setFrames(new <String>["mine2", "mine3", "mine4", "mine5", "mine6", "mine7", "mine8", "mine9"]);
+ clip.gotoFrame(Math.random()*8);
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ //node.transform.rotation = Math.random()*Math.PI;
+ //node.addComponent(G2DComponent);
+ return node;
+ }
+
+
+ private function addSprites(p_count:int):void {
+ __iClipCount += p_count;
+ for (var i:int = 0; i<p_count; ++i) {
+ var clip:G2DNode;
+
+ //clip = createSprite(Math.random()*800, Math.random()*600);
+ clip = createClip(Math.random()*800, Math.random()*600);
+
+ _cContainer.addChild(clip);
+ }
+
+ updateInfo();
+ }
+
+ private function removeSprites(p_count:int):void {
+ __iClipCount -= p_count;
+ if (__iClipCount<0) __iClipCount = 0;
+ for (var i:int = 0; i < p_count; ++i) {
+ if (_cContainer.numChildren == 0) break;
+ _cContainer.removeChildAt(0);
+ }
+
+ updateInfo();
+ }
+
+ private function onUpdate(p_deltaTime:Number):void {
+ var cameraNode:G2DNode;
+
+ cameraNode = _cGenome.getCameraAt(0).node;
+ if (cameraNode.transform.x < 200 || cameraNode.transform.x>600) {
+ __nCameraMove = -__nCameraMove;
+ }
+ cameraNode.transform.x += __nCameraMove;
+ cameraNode.transform.y += __nCameraMove;
+
+ cameraNode = _cGenome.getCameraAt(1).node;
+ if (cameraNode.transform.rotation < -2*Math.PI || cameraNode.transform.rotation > 2*Math.PI) {
+ __nCameraRotation = -__nCameraRotation;
+ }
+ cameraNode.transform.rotation += __nCameraRotation;
+
+ cameraNode = _cGenome.getCameraAt(2).node;
+ var camera:G2DCamera = cameraNode.getComponent(G2DCamera) as G2DCamera;
+ if (camera.zoom < .2 || camera.zoom>2) {
+ __nCameraZoom = -__nCameraZoom;
+ }
+ camera.zoom += __nCameraZoom;
+ camera.zoom += __nCameraZoom;
+ /*
+ var length:int = _cContainer.numChildren;
+ for (var i:int = 0; i<length; ++i) {
+ _cContainer.getChildAt(i).transform.rotation+=.1;
+ }
+ /**/
+ }
+
+ private function onKeyDown(event:KeyboardEvent):void {
+ trace(event.keyCode);
+ }
+ }
+}
View
142 examples/examples/CameraInterpolateExample.as
@@ -0,0 +1,142 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DCamera;
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.signals.G2DMouseSignal;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+ import com.greensock.TweenLite;
+
+ import flash.display.Sprite;
+
+ public class CameraInterpolateExample extends Example
+ {
+ private var __cMineTexture:G2DTextureAtlas;
+ private var __cNinjaTexture:G2DTextureAtlas;
+
+ private const COUNT:int = 20;
+
+ private var __iClipCount:int;
+ private var __nCameraMove:Number = 4;
+ private var __nCameraRotation:Number = .02;
+ private var __nCameraZoom:Number;
+ private var __cSelected:G2DNode;
+
+ public function CameraInterpolateExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>CameraExample</b>\n"+
+ "<font color='#FFFFFF'>This is a simple camera example that shows camera interpolation and tweening.\n"+
+ "<font color='#FFFF00'>CLICK a clip where camera should go.";
+ }
+
+ override public function init():void {
+ super.init();
+
+ __cMineTexture = G2DTextureAtlas.createFromBitmapDataAndXML("mine", (new Assets.MinesGFX()).bitmapData, XML(new Assets.MinesXML()));
+ __cNinjaTexture = G2DTextureAtlas.createFromBitmapDataAndXML("ninja", (new Assets.NinjaGFX()).bitmapData, XML(new Assets.NinjaXML()));
+
+ for (var i:int = 0; i<COUNT; ++i) {
+ var node:G2DNode = createMine(Math.random()*800, Math.random()*600);
+ _cContainer.addChild(node);
+ }
+
+ updateInfo();
+ }
+
+ override public function dispose():void {
+ super.dispose();
+
+ __cMineTexture.dispose();
+ __cNinjaTexture.dispose();
+
+ __cSelected = null;
+
+ _cGenome.onUpdated.removeAll();
+ }
+
+ private function createClip(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cNinjaTexture);
+ clip.setFrameRate(15);
+ clip.setFrames(new <String>["nw1", "nw2", "nw3", "nw2", "nw1", "stood", "nw4", "nw5", "nw6", "nw5", "nw4"]);
+ clip.gotoFrame(Math.random()*8);
+ //clip.stop();
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ node.transform.scaleX = node.transform.scaleY = 2//Math.random()*2+1;
+ node.transform.rotation = Math.random()*2*Math.PI;
+ node.mouseEnabled = true;
+
+ clip.mousePixelEnabled = true;
+ node.transform.blue = node.transform.red = 0;
+
+ node.onMouseOver.add(onClipMouseOver);
+ node.onMouseOut.add(onClipMouseOut);
+ node.onMouseClick.add(onClipMouseClick);
+ return node;
+ }
+
+ private function createMine(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cMineTexture);
+ clip.setFrameRate(Math.random()*10+3);
+ clip.setFrames(new <String>["mine2", "mine3", "mine4", "mine5", "mine6", "mine7", "mine8", "mine9"]);
+ clip.gotoFrame(Math.random()*8);
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ node.transform.scaleX = node.transform.scaleY = Math.random()*2+1;
+ node.transform.rotation = Math.random()*2*Math.PI;
+ node.mouseEnabled = true;
+
+ node.transform.blue = node.transform.green = 0;
+
+ node.onMouseOver.add(onClipMouseOver);
+ node.onMouseOut.add(onClipMouseOut);
+ node.onMouseClick.add(onClipMouseClick);
+ return node;
+ }
+
+ private function onClipMouseClick(p_signal:G2DMouseSignal):void {
+ var sprite:G2DSprite = p_signal.dispatcher.getComponent(G2DMovieClip) as G2DMovieClip;
+ sprite.mousePixelEnabled = !sprite.mousePixelEnabled;
+ if (__cSelected) {
+ __cSelected.transform.red = 1;
+ __cSelected.transform.green = 0;
+ __cSelected.transform.blue = 0;
+ }
+
+ p_signal.dispatcher.transform.red = 1;
+ p_signal.dispatcher.transform.green = 1;
+ p_signal.dispatcher.transform.blue = 1;
+
+ __cSelected = p_signal.dispatcher;
+
+ TweenLite.to(_cCamera.transform, .5, {x:p_signal.dispatcher.transform.x, y:p_signal.dispatcher.transform.y, rotation:-p_signal.dispatcher.transform.rotation});
+ }
+
+ private function onClipMouseOver(p_signal:G2DMouseSignal):void {
+ if (p_signal.dispatcher == __cSelected) return;
+ p_signal.dispatcher.transform.red = 0;
+ p_signal.dispatcher.transform.green = 1;
+ p_signal.dispatcher.transform.blue = 0;
+ }
+
+ private function onClipMouseOut(p_signal:G2DMouseSignal):void {
+ if (p_signal.dispatcher == __cSelected) return;
+
+ p_signal.dispatcher.transform.red = 1;
+ p_signal.dispatcher.transform.green = 0;
+ p_signal.dispatcher.transform.blue = 0;
+ }
+ }
+}
View
177 examples/examples/CameraMouseExample.as
@@ -0,0 +1,177 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DCamera;
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.signals.G2DMouseSignal;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+
+ import flash.display.Sprite;
+ import flash.events.KeyboardEvent;
+
+ public class CameraMouseExample extends Example
+ {
+ private var __cMineTexture:G2DTextureAtlas;
+ private var __cNinjaTexture:G2DTextureAtlas;
+
+ private const COUNT:int = 50;
+
+ private var __iClipCount:int;
+ private var __nCameraMove:Number = 4;
+ private var __nCameraRotation:Number = .02;
+ private var __nCameraZoom:Number = .002;
+
+ public function CameraMouseExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>CameraMultipleMouseExample</b>\n"+
+ "<font color='#FFFFFF'>Showcase of working mouse interaction through multiple viewports into a scene with custom transforms.\n"+
+ "<font color='#FFFF00'>CLICK a clip to switch between pixel precise [green] and geometry [red] mouse test.";
+ }
+
+ override public function init():void {
+ super.init();
+
+ __cMineTexture = G2DTextureAtlas.createFromBitmapDataAndXML("mine", (new Assets.MinesGFX()).bitmapData, XML(new Assets.MinesXML()));
+ __cNinjaTexture = G2DTextureAtlas.createFromBitmapDataAndXML("ninja", (new Assets.NinjaGFX()).bitmapData, XML(new Assets.NinjaXML()));
+
+ for (var i:int = 0; i<COUNT; ++i) {
+ var node:G2DNode = createClip(Math.random()*800, Math.random()*600);
+ _cContainer.addChild(node);
+ }
+
+ _cGenome.onUpdated.add(onUpdate);
+
+ var camera:G2DCamera;
+ camera = _cCamera.getComponent(G2DCamera) as G2DCamera;
+ camera.normalizedViewWidth = .5;
+ camera.normalizedViewHeight = .5;
+ camera.normalizedViewX = 0;
+ camera.normalizedViewY = 0;
+
+ var cameraNode:G2DNode = new G2DNode("camera1");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ cameraNode.transform.rotation = Math.PI/4;
+ camera.normalizedViewWidth = .5;
+ camera.normalizedViewHeight = .5;
+ camera.normalizedViewX = .5;
+ camera.normalizedViewY = 0;
+ _cGenome.root.addChild(cameraNode);
+
+ cameraNode = new G2DNode("camera2");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ camera.normalizedViewWidth = .5;
+ camera.normalizedViewHeight = .5;
+ camera.normalizedViewX = 0;
+ camera.normalizedViewY = .5;
+ camera.zoom = .3;
+ _cGenome.root.addChild(cameraNode);
+
+ cameraNode = new G2DNode("camera3");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ camera.normalizedViewWidth = .5;
+ camera.normalizedViewHeight = .5;
+ camera.normalizedViewX = .5;
+ camera.normalizedViewY = .5;
+ _cGenome.root.addChild(cameraNode);
+
+ updateInfo();
+ }
+
+ override public function dispose():void {
+ super.dispose();
+
+ __cMineTexture.dispose();
+ __cNinjaTexture.dispose();
+
+ _cGenome.onUpdated.removeAll();
+ }
+
+ private function createClip(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cNinjaTexture);
+ clip.setFrameRate(15);
+ clip.setFrames(new <String>["nw1", "nw2", "nw3", "nw2", "nw1", "stood", "nw4", "nw5", "nw6", "nw5", "nw4"]);
+ clip.gotoFrame(Math.random()*8);
+ //clip.stop();
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ node.transform.scaleX = node.transform.scaleY = Math.random()*2+1;
+ node.mouseEnabled = true;
+ if (Math.random()*2<1) {
+ clip.mousePixelEnabled = true;
+ node.transform.blue = node.transform.red = 0;
+ } else {
+ node.transform.blue = node.transform.green = 0;
+ }
+
+ node.onMouseOver.add(onClipMouseOver);
+ node.onMouseOut.add(onClipMouseOut);
+ node.onMouseClick.add(onClipMouseClick);
+ return node;
+ }
+
+ private function onClipMouseClick(p_signal:G2DMouseSignal):void {
+ var sprite:G2DSprite = p_signal.dispatcher.getComponent(G2DMovieClip) as G2DMovieClip;
+ var val:Boolean = sprite.mousePixelEnabled;
+ sprite.mousePixelEnabled = !val;
+ }
+
+ private function onClipMouseOver(p_signal:G2DMouseSignal):void {
+ p_signal.dispatcher.transform.red = p_signal.dispatcher.transform.green = p_signal.dispatcher.transform.blue = 1;
+ }
+
+ private function onClipMouseOut(p_signal:G2DMouseSignal):void {
+ var sprite:G2DSprite = p_signal.dispatcher.getComponent(G2DMovieClip) as G2DMovieClip;
+
+ if (sprite.mousePixelEnabled) {
+ p_signal.dispatcher.transform.red = 0;
+ p_signal.dispatcher.transform.green = 1;
+ p_signal.dispatcher.transform.blue = 0;
+ } else {
+ p_signal.dispatcher.transform.red = 1;
+ p_signal.dispatcher.transform.green = 0;
+ p_signal.dispatcher.transform.blue = 0;
+ }
+ }
+
+ private function onUpdate(p_deltaTime:Number):void {
+ var cameraNode:G2DNode;
+
+ cameraNode = _cGenome.getCameraAt(3).node;
+ if (cameraNode.transform.x < 200 || cameraNode.transform.x>600) {
+ __nCameraMove = -__nCameraMove;
+ }
+ //cameraNode.transform.x += __nCameraMove;
+ //cameraNode.transform.y += __nCameraMove;
+
+ //cameraNode = _cGenome.getCameraAt(1).node;
+ if (cameraNode.transform.rotation < -2*Math.PI || cameraNode.transform.rotation > 2*Math.PI) {
+ //__nCameraRotation = -__nCameraRotation;
+ }
+ cameraNode.transform.rotation += __nCameraRotation;
+
+ //cameraNode = _cGenome.getCameraAt(2).node;
+ var camera:G2DCamera = cameraNode.getComponent(G2DCamera) as G2DCamera;
+ if (camera.zoom < .2 || camera.zoom>2) {
+ __nCameraZoom = -__nCameraZoom;
+ }
+ camera.zoom += __nCameraZoom;
+ camera.zoom += __nCameraZoom;
+ }
+ }
+}
View
178 examples/examples/CameraViewExample.as
@@ -0,0 +1,178 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DCamera;
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+
+ import flash.display.Sprite;
+ import flash.events.KeyboardEvent;
+
+ public class CameraViewExample extends Example
+ {
+ private var __cMineTexture:G2DTextureAtlas;
+ private var __cNinjaTexture:G2DTextureAtlas;
+
+ private const COUNT:int = 100;
+ static public const MAX_MILL_SPEED:Number = .005;
+
+ private var __cRotatingContainer:G2DNode;
+ private var __cNinjaContainer:G2DNode;
+
+ private var __iClipCount:int;
+ private var __nCameraMove:Number = 2;
+ private var __nCameraRotation:Number = .05;
+ private var __nCameraZoom:Number = .02;
+
+ public function CameraViewExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>CameraDynamicViewportExample</b>\n"+
+ "<font color='#FFFFFF'>First camera takes whole screen at default transform, second camera moves through scene at zoom 2 and uses dynamic viewport.\n"+
+ "<font color='#FFFF00'>";
+ }
+
+ override public function init():void {
+ super.init();
+
+ __cMineTexture = G2DTextureAtlas.createFromBitmapDataAndXML("mine", (new Assets.MinesGFX()).bitmapData, XML(new Assets.MinesXML()));
+ __cNinjaTexture = G2DTextureAtlas.createFromBitmapDataAndXML("ninja", (new Assets.NinjaGFX()).bitmapData, XML(new Assets.NinjaXML()));
+
+ __cRotatingContainer = new G2DNode();
+ __cRotatingContainer.mouseChildren = false;
+ __cRotatingContainer.transform.x = 400;
+ __cRotatingContainer.transform.y = 300;
+ for (var i:int = 0; i<23; ++i) {
+ var mine:G2DNode = createMine(-264+24*i, 0);
+ mine.userData = false;
+ __cRotatingContainer.addChild(mine);
+ var mine:G2DNode = createMine(0, -265+24*i);
+ mine.userData = false;
+ __cRotatingContainer.addChild(mine);
+ }
+ _cGenome.root.addChild(__cRotatingContainer);
+
+
+ __cNinjaContainer = new G2DNode();
+ __cNinjaContainer.mouseChildren = false;
+ for (var i:int = 0; i<COUNT; ++i) {
+ var clip:G2DNode = createNinja(Math.random()*(800-200)+100,Math.random()*(600-100)+50);
+ //clip.mouseEnabled = true;
+ //clip.onMouseDown.add(onClipMouseDown);
+ //clip.onMouseUp.add(onClipMouseUp);
+ __cNinjaContainer.addChild(clip);
+ }
+ _cGenome.root.addChild(__cNinjaContainer);
+
+ _cGenome.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.add(onUpdate);
+
+ var camera:G2DCamera;
+ camera = _cCamera.getComponent(G2DCamera) as G2DCamera;
+
+ var cameraNode:G2DNode = new G2DNode("camera1");
+ camera = cameraNode.addComponent(G2DCamera) as G2DCamera;
+ cameraNode.transform.x = 400;
+ cameraNode.transform.y = 300;
+ camera.normalizedViewWidth = 1/3;
+ camera.normalizedViewX = 1/3;
+ camera.zoom = 2;
+ _cGenome.root.addChild(cameraNode);
+
+ updateInfo();
+ }
+
+ override public function dispose():void {
+ __cMineTexture.dispose();
+ __cNinjaTexture.dispose();
+
+ _cGenome.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.removeAll();
+
+ super.dispose();
+ }
+
+ private function createMine(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cMineTexture);
+ clip.setFrameRate(Math.random()*10+3);
+ clip.setFrames(new <String>["mine2", "mine3", "mine4", "mine5", "mine6", "mine7", "mine8", "mine9"]);
+ clip.gotoFrame(Math.random()*8);
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ return node;
+ }
+
+ private function createNinja(p_x:Number, p_y:Number):G2DNode {
+ var node:G2DNode = new G2DNode();
+ var clip:G2DMovieClip = node.addComponent(G2DMovieClip) as G2DMovieClip;
+ clip.setTextureAtlas(__cNinjaTexture);
+ clip.setFrameRate(Math.random()*10+3);
+ clip.setFrames(new <String>["nw1", "nw2", "nw3", "nw2", "nw1", "stood", "nw4", "nw5", "nw6", "nw5", "nw4"]);
+ clip.gotoFrame(Math.random()*8);
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ return node;
+ }
+
+ private function onUpdate(p_deltaTime:Number):void {
+ var cameraNode:G2DNode;
+
+ cameraNode = _cGenome.getCameraAt(1).node;
+ var camera:G2DCamera = cameraNode.getComponent(G2DCamera) as G2DCamera;
+ if (camera.normalizedViewX <= 0 || camera.normalizedViewX >= 2/3) {
+ __nCameraMove = -__nCameraMove;
+ }
+ camera.normalizedViewX += __nCameraMove/800;
+ cameraNode.transform.x += __nCameraMove;
+
+ __cRotatingContainer.transform.rotation+=.01;
+
+ var i:int;
+ var j:int;
+ var c:Boolean = false;
+
+ for (i = 0; i<__cNinjaContainer.numChildren; ++i) {
+ c = false;
+ var ninja:G2DNode = __cNinjaContainer.getChildAt(i) as G2DNode;
+ var ninjaClip:G2DMovieClip = ninja.getComponent(G2DMovieClip) as G2DMovieClip;
+ for (j = 0; j<__cRotatingContainer.numChildren; ++j) {
+ var mine:G2DNode = __cRotatingContainer.getChildAt(j) as G2DNode;
+ if (c && mine.userData) continue;
+ var mineClip:G2DMovieClip = mine.getComponent(G2DMovieClip) as G2DMovieClip;
+ var a:Boolean = ninjaClip.hitTestObject(mineClip);
+ mine.userData = a || mine.userData;
+ c = a || c;
+ }
+
+ if (c) {
+ ninja.transform.green = ninja.transform.blue = 0;
+ } else {
+ ninja.transform.green = ninja.transform.blue = 1;
+ }
+ }
+
+ for (i = 0; i<__cRotatingContainer.numChildren; ++i) {
+ var mine:G2DNode = __cRotatingContainer.getChildAt(i) as G2DNode;
+ if (mine.userData) {
+ mine.transform.green = mine.transform.blue = 0;
+ mine.userData = false;
+ } else {
+ mine.transform.green = mine.transform.blue = 1;
+ }
+ }
+ }
+
+ private function onKeyDown(event:KeyboardEvent):void {
+ trace(event.keyCode);
+ }
+ }
+}
View
143 examples/examples/ParticleExample.as
@@ -0,0 +1,143 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DEmitter;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DParticle;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.context.G2DBlendMode;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.signals.G2DMouseSignal;
+ import com.flashcore.g2d.textures.G2DTexture;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+ import com.greensock.TweenLite;
+
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.Shape;
+ import flash.display.Sprite;
+ import flash.display.Stage;
+ import flash.events.KeyboardEvent;
+ import flash.geom.Matrix;
+ import examples.components.CustomParticle;
+
+ public class ParticleExample extends Example
+ {
+ private var __cMineTexture:G2DTextureAtlas;
+ private var __cParticleTexture:G2DTexture;
+
+ private var __iColor:int = 0;
+ private var __iSize:int = 16;
+ private var __bMove:Boolean = true;
+
+ private var __cParticles:G2DNode;
+
+ public function ParticleExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>ParticleExample</b>\n"+
+ "<font color='#FFFFFF'>This is just a simple demo of particle system using additive blending and particle prototype.\n"+
+ "<font color='#FFFF00'>Just move your mouse around and enjoy.";
+ }
+
+ /**
+ * Initialize example
+ */
+ override public function init():void {
+ super.init();
+
+ // Create a G2D texture based on our embedded asset bitmap
+ __cParticleTexture = G2DTexture.createFromBitmapData("particle", new Assets.ParticleGFX().bitmapData);
+
+ // Hook up a key event
+ _cGenome.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ // Hook up a Genome update signal
+ _cGenome.onUpdated.add(onUpdate);
+
+ // Create a particle for prototype
+ var particle:G2DNode = new G2DNode();
+ // Each particle needs to have G2DParticle component
+ particle.addComponent(G2DParticle);
+ // This is our custom component just for show, it actually only sets custom colors to each particle
+ particle.addComponent(CustomParticle);
+ // Add sprite texture for our particle
+ var sprite:G2DSprite = particle.addComponent(G2DSprite) as G2DSprite;
+ sprite.setTexture(__cParticleTexture);
+ sprite.blendMode = G2DBlendMode.ADDITIVE;
+
+ // Create our particle emitter
+ __cParticles = new G2DNode("particles");
+ __cParticles.mouseChildren = false;
+ var emitter:G2DEmitter = __cParticles.addComponent(G2DEmitter) as G2DEmitter;
+ // Set the particle prototype
+ emitter.particlePrototype = particle.getPrototype();
+ // This means that generated particles will use world space instead of local space therefore moving the emitter will not move the already generated partciles
+ // Just for fun try to set it to false and you'll see
+ emitter.useWorldSpace = true;
+ // Velocity
+ emitter.worldVelocityY = 200;
+ // Minimum number of particles generated per second
+ emitter.minEmission = 50;
+ // Maximum number of particles generated per second
+ emitter.maxEmission = 100;
+ // Maximum size of the particle, what this means is the scale of the prototype
+ emitter.maxSize = 4;
+ // Maximum energy of a particle, this means particle will live for 2 seconds
+ emitter.maxEnergy = 2;
+ // Angle of emission, this will set a 360 degree emission
+ emitter.angle = Math.PI*2;
+ _cContainer.addChild(__cParticles);
+
+ /**
+ * There are other properties of G2DEmitter that can be utilized, you can try them out as well
+ */
+
+ updateInfo();
+ }
+
+ /**
+ * Dispose example resources
+ */
+ override public function dispose():void {
+ super.dispose();
+
+ __cParticleTexture.dispose();
+
+ _cGenome.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.removeAll();
+ }
+
+ /**
+ * Update singal callback
+ */
+ private function onUpdate(p_deltaTime:Number):void {
+ // Move particle emitter to mouse position
+ __cParticles.transform.x = _cWrapper.stage.mouseX;
+ __cParticles.transform.y = _cWrapper.stage.mouseY;
+ }
+
+ /**
+ * Keyboard event callback
+ */
+ private function onKeyDown(event:KeyboardEvent):void {
+ switch (event.keyCode) {
+ case 40:
+ __iSize = (__iSize>1) ? __iSize-1 : 1;
+ break;
+ case 38:
+ __iSize++;
+ break;
+ case 80:
+ __bMove = !__bMove;
+ break;
+ }
+
+ updateInfo();
+ }
+ }
+}
View
148 examples/examples/TextureExample.as
@@ -0,0 +1,148 @@
+package examples
+{
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.components.G2DMovieClip;
+ import com.flashcore.g2d.components.G2DSprite;
+ import com.flashcore.g2d.core.G2DNode;
+ import com.flashcore.g2d.core.Genome2D;
+ import com.flashcore.g2d.g2d;
+ import com.flashcore.g2d.signals.G2DMouseSignal;
+ import com.flashcore.g2d.textures.G2DTexture;
+ import com.flashcore.g2d.textures.G2DTextureAtlas;
+ import com.flashcore.g2d.textures.G2DTextureLibrary;
+ import com.greensock.TweenLite;
+
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.Shape;
+ import flash.display.Sprite;
+ import flash.events.KeyboardEvent;
+ import flash.geom.Matrix;
+
+ public class TextureExample extends Example
+ {
+ private var __cCustomTexture:G2DTexture;
+ private var __cColorTexture:G2DTexture;
+
+ private var __iColor:int = 0;
+ private var __iSize:int = 16;
+ private var __bMove:Boolean = true;
+
+ public function TextureExample(p_wrapper:Genome2DExamples):void {
+ super(p_wrapper);
+ }
+
+ private function updateInfo():void {
+ _cWrapper.info = "<font color='#00FFFF'><b>TextureExample</b>[ "+__iSize+" ]\n"+
+ "<font color='#FFFFFF'>This is a demo of dynamic texture internal bitmap data and its invalidation to GPU.\n"+
+ "<font color='#FFFF00'>Paint into the texture using mouse. Us ARROW UP/DOWN to increase/decrease brush size. Press P to pause movement.";
+ }
+
+ override public function init():void {
+ super.init();
+
+ __cCustomTexture = G2DTexture.createFromBitmapData("custom", new BitmapData(256, 256, true, 0xFFFFFFFF));
+
+ var node:G2DNode = new G2DNode();
+ node.transform.x = 400;
+ node.transform.y = 300;
+ node.transform.scaleX = node.transform.scaleY = 1.5;
+ var sprite:G2DSprite = node.addComponent(G2DSprite) as G2DSprite;
+ sprite.setTexture(__cCustomTexture);
+ node.mouseEnabled = true;
+ node.onMouseMove.add(onMouseMove);
+ _cContainer.addChild(node);
+
+ __cColorTexture = G2DTexture.createFromBitmapData("color", new BitmapData(16,16, true, 0xFFFFFFFF));
+
+ createColor(760,100, 1, 1, 1);
+ createColor(760,140, 1, 0, 0);
+ createColor(760,180, 0, 1, 0);
+ createColor(760,220, 0, 0, 1);
+ createColor(760,260, 1, 1, 0);
+ createColor(760,300, 1, 0, 1);
+ createColor(760,340, 0, 1, 1);
+
+ _cGenome.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.add(onUpdate);
+
+ updateInfo();
+ }
+
+ private function createColor(p_x:int, p_y:int, p_red:Number, p_green:Number, p_blue:Number):void {
+ var node:G2DNode = new G2DNode();
+ node.transform.x = p_x;
+ node.transform.y = p_y;
+ node.transform.red = p_red;
+ node.transform.green = p_green;
+ node.transform.blue = p_blue;
+ node.transform.rotation = Math.random()*Math.PI*2;
+ var sprite:G2DSprite = node.addComponent(G2DSprite) as G2DSprite;
+ sprite.setTexture(__cColorTexture);
+ node.mouseEnabled = true;
+ node.onMouseClick.add(onColorClick);
+ node.onMouseOver.add(onColorOver);
+ node.onMouseOut.add(onColorOut);
+ _cContainer.addChild(node);
+ }
+
+ override public function dispose():void {
+ super.dispose();
+
+ __cCustomTexture.dispose();
+ __cColorTexture.dispose();
+
+ _cGenome.stage.removeEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
+ _cGenome.onUpdated.removeAll();
+ }
+
+ private function onMouseMove(p_signal:G2DMouseSignal):void {
+ if (!p_signal.buttonDown) return;
+ var shape:Shape = new Shape();
+ shape.graphics.beginFill(__iColor);
+ shape.graphics.drawCircle(0,0, __iSize);
+
+ var matrix:Matrix = new Matrix();
+ matrix.translate(p_signal.localX, p_signal.localY);
+
+ __cCustomTexture.bitmapData.draw(shape, matrix);
+ __cCustomTexture.invalidate();
+ }
+
+ private function onColorClick(p_signal:G2DMouseSignal):void {
+ __iColor = ((p_signal.dispatcher.transform.red*255)<<16) + ((p_signal.dispatcher.transform.green*255)<<8) + (p_signal.dispatcher.transform.blue*255);
+ }
+
+ private function onColorOver(p_signal:G2DMouseSignal):void {
+ TweenLite.to(p_signal.dispatcher.transform, .25, {scaleX:2, scaleY:2});
+ }
+
+ private function onColorOut(p_signal:G2DMouseSignal):void {
+ TweenLite.to(p_signal.dispatcher.transform, .25, {scaleX:1, scaleY:1});
+ }
+
+ private function onUpdate(p_deltaTime:Number):void {
+ if (!__bMove) return;
+ var length:int = _cContainer.numChildren;
+ for (var i:int = 0; i<length; ++i) {
+ _cContainer.getChildAt(i).transform.rotation+=.01;
+ }
+ }
+
+ private function onKeyDown(event:KeyboardEvent):void {
+ switch (event.keyCode) {
+ case 40:
+ __iSize = (__iSize>1) ? __iSize-1 : 1;
+ break;
+ case 38:
+ __iSize++;
+ break;
+ case 80:
+ __bMove = !__bMove;
+ break;
+ }
+
+ updateInfo();
+ }
+ }
+}
View
16 examples/examples/components/CustomParticle.as
@@ -0,0 +1,16 @@
+package examples.components
+{
+ import com.flashcore.g2d.components.G2DComponent;
+ import com.flashcore.g2d.core.G2DNode;
+
+ public class CustomParticle extends G2DComponent
+ {
+ public function CustomParticle(p_node:G2DNode) {
+ super(p_node);
+
+ node.transform.red = Math.random();
+ node.transform.green = Math.random();
+ node.transform.blue = Math.random();
+ }
+ }
+}

0 comments on commit e93b1e6

Please sign in to comment.
Something went wrong with that request. Please try again.