Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created with IntelliJ IDEA.
- * User: rodrigolopez
- * Date: 6/22/12
- * Time: 11:28 AM
- */
- package {
- import com.genome2d.components.GCamera;
- import com.genome2d.components.renderables.GMovieClip;
- import com.genome2d.context.GContext;
- import com.genome2d.core.GConfig;
- import com.genome2d.core.GNode;
- import com.genome2d.core.GNodeFactory;
- import com.genome2d.core.Genome2D;
- import com.genome2d.textures.GTextureAlignType;
- import com.genome2d.textures.GTextureAtlas;
- import com.greensock.TweenLite;
- import com.greensock.easing.Expo;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.display.StageAlign;
- import flash.display.StageQuality;
- import flash.display.StageScaleMode;
- import flash.events.MouseEvent;
- import flash.geom.Rectangle;
- [SWF(width="800", height="600", backgroundColor="#DEDEDE", frameRate="60")]
- public class Main extends Sprite {
- private var _genome: Genome2D;
- private var _rootNode: GNode;
- private var _camera: GCamera;
- private var _chars:Array = [];
- private var _isAlign:Boolean = false ;
- /***********************
- * Main Constructor.
- **********************/
- public function Main() {
- if (stage) {
- addEventListener ( Event.ADDED_TO_STAGE, onAddedToStage );
- } else {
- onAddedToStage ( null );
- }
- }
- private function onAddedToStage( event: Event ): void {
- removeEventListener ( Event.ADDED_TO_STAGE, onAddedToStage )
- initStage ();
- init ();
- }
- /***********************
- * Access point.
- **********************/
- private function init(): void {
- initGenome ();
- }
- private function initGenome(): void {
- _genome = Genome2D.getInstance ();
- var config: GConfig = new GConfig ( null );
- config.enableStats = true;
- config.separateAlphaShaders = true;
- config.viewRect = new Rectangle ( 0, 0, stage.stageWidth, stage.stageHeight )
- _genome.onInitialized.add ( onInit )
- _genome.init ( stage, config );
- }
- private function onInit(): void {
- start ();
- }
- private function start(): void {
- initCamera ();
- // displayList
- var char1: ZombieWalkVector = new ZombieWalkVector ();
- addChild ( char1 );
- char1.x = 100, char1.y = 100;
- // toggle button align
- var btn:MovieClip = new align_btn()
- addChild(btn).addEventListener(MouseEvent.CLICK, onAlignClick )
- btn.x = 30, btn.y = 200 ;
- addMovieChar(new ZombieWalkVector(), "char1_vector", 0x5500FF00, 200, 100 );
- addMovieChar(new ZombieWalkRaster(), "char1_raster", 0x55FF0000, 300, 100 );
- }
- private function onAlignClick( event: MouseEvent ): void {
- _isAlign = !_isAlign;
- TweenLite.to(_chars[0].node.transform, 0.5, { x: _isAlign ? 100 : 200, ease: Expo.easeOut })
- // TweenLite.to(_chars[1].node.transform, 0.5, { x: _isAlign ? 100 : 300 })
- }
- private function addMovieChar( pAsset:MovieClip, pId:String, pDebugColor:uint=0x0, pX:int = 0, pY:int=0): GNode {
- // atlasXML to fill
- var zombieXML:XML = <node/>;
- var zombieAtlas:GTextureAtlas = GAtlasUtils.createAtlasFromMovie(pId, pAsset, null, false, pDebugColor, zombieXML );
- // adjust TRIM! to center the textures in the GMovieclip
- GAtlasUtils.adjustTrim(zombieAtlas, zombieXML, GTextureAlignType.CENTER);
- // dispose bitmapDatas from Texture
- GAtlasUtils.disposeBitmapsAtlas(zombieAtlas, GAU.getIdsFromXML(zombieXML));
- var char:GMovieClip = GNodeFactory.createNodeWithComponent(GMovieClip) as GMovieClip;
- char.setTextureAtlas(zombieAtlas);
- // no frame labels in movie's timeline, use the frame numbers
- char.frames = GAtlasUtils.buildFrames("", 1, 21 );
- char.play();
- char.frameRate = stage.frameRate ;
- char.node.transform.setPosition(pX, pY)
- _chars.push(char);
- _rootNode.addChild(char.node);
- return char.node ;
- }
- private function initCamera(): void {
- _rootNode = GNodeFactory.createNode ( "rootNode" );
- _genome.root.addChild ( _rootNode );
- _camera = GNodeFactory.createNodeWithComponent ( GCamera ) as GCamera;
- _camera.backgroundAlpha = _camera.backgroundBlue = _camera.backgroundGreen = _camera.backgroundRed = 1;
- _camera.node.transform.setPosition ( 400, 300 );
- _rootNode.addChild ( _camera.node );
- }
- private function initStage(): void {
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.TOP_LEFT;
- stage.quality = StageQuality.HIGH;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment