baseEff

Programing/flash 2015.11.20 15:44 |

package objects.ObjectMgr
{
 import com.distriqt.extension.notifications.events.GenericEvent;
 import flash.geom.Point;
 import starling.animation.Juggler;
 import starling.core.Starling;
 import starling.display.MovieClip;
 import starling.display.Sprite;
 import starling.events.EnterFrameEvent;
 import starling.events.Event;
 import UI.BigInt;
 
 import starling.animation.Juggler;
 import starling.utils.deg2rad;

 import com.greensock.TweenLite;
 import flash.system.System;
 import starling.utils.getTimer;
 
 import starling.text.TextField;
 
 import starling.utils.HAlign;
 import starling.utils.VAlign;
 import flash.geom.Rectangle;
 
 /**
  * ...
  * @author searoopy
  */
 public class BaseEff extends Sprite
 {
  //static public var g_DamageEff:DamageEff = null;
  
  public var m_mvEff:Vector.<MovieClip>;// = new vec;
  
  public var m_textEff:Vector.<TextField>;
  
  public const MAX_EFF_CNT:int = 16;
  
  protected var m_imageName:String ;
  
  public var m_Dir:Vector.<int>;
  
  private var m_type:int = 0;
  
  
  private var m_val:BigInt = new BigInt( 50);
  
  
  public function BaseEff( imageName:String , type:int = 0 )
  {
   super();

   this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedStage);
   this.addEventListener(starling.events.Event.REMOVED_FROM_STAGE, onRemoveStage);

   
   m_imageName = imageName;
   
   m_type = type;
  }
  
  private function onAddedStage():void
  {
   this.removeEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedStage);
   
   init();

  }
  
   
  private function onRemoveStage():void
  {
   this.removeEventListener(starling.events.Event.REMOVED_FROM_STAGE, onRemoveStage);
   
   destroy();

  }
  
  public function init():void
  {
   m_mvEff = new Vector.<MovieClip>;
   m_Dir = new Vector.<int>;
   m_textEff = new Vector.<TextField>;

   var _tmv:MovieClip = null;
   var _text:TextField = null;
   for ( var i:int = 0; i < MAX_EFF_CNT; i++)
   {
    _tmv = new MovieClip( Assets.getAtlasTest().getTextures( m_imageName ), 15 );
    Assets.setCenterMC(_tmv);
    Starling.juggler.add(_tmv);
    _tmv.stop();
    _tmv.visible = false;
    addChild(_tmv);
    m_mvEff.push( _tmv ) ;
    
    m_Dir.push(0);
    
    
    _text = new TextField( 100, 70, "0", "Ubuntu", 30, 0xffffff );
    _text.pivotX = _text.width / 2;
    _text.pivotY = _text.height / 2;
    _text.x = 0; //130
    _text.y = 10;
    _text.hAlign = HAlign.CENTER;
    _text.vAlign = VAlign.CENTER;
    //_text.touchable = false;
    //m_textMoney.text = m_curStage.toString() +  " / " + m_maxStage.toString();// .1288';
    _text.visible = false;
    addChild(_text);
    
    m_textEff.push( _text);
   }
   
   this.addEventListener(EnterFrameEvent.ENTER_FRAME, onUpdate);

  }
  
  private function onUpdate():void
  {
   for ( var i:int = 0; i < MAX_EFF_CNT; i++)
   {
    if ( m_mvEff[i].visible == true)
    {
     //m_mvEff[i].x += m_Dir[i];
    }
    
   }

  }
  
  public function showEff( _x:int, _y:int , moveRan:Boolean = false ):void
  {
   for ( var i:int = 0; i < MAX_EFF_CNT; i++)
   {
    if ( m_mvEff[i].visible == false)
    {
     
     if ( moveRan == true)
     {
      var ran:Number = Math.random() ;
      if ( ran > 0.7)
      {
       m_Dir[i] = 1 + Math.random()*2;
      }
      else if (  ran > 0.3)
      {
       m_Dir[i] = -1 - Math.random()*2;
      }
      else
      {
       m_Dir[i] = Math.random()*2;
      }
     }
     
     
     //var text:TextField = m_textEff[i];
     //text.visible = true;
     //text.x = _x;
     //text.y = _y;
     
     /*
     if ( CoinTextEff.g_coinTextEff != null)
     {
      if( BigInt.compare(  LevelMgr.g_nBonusShowCoin , 0 ) > 0 )
       CoinTextEff.g_coinTextEff.showEff(  _x - 50, _y , LevelMgr.g_nBonusShowCoin.toString() );
     }
     */
     
     var tmv:MovieClip = m_mvEff[i];
     tmv.visible = true;
     //m_mvEff[i].x = 0;
     m_mvEff[i].x = _x;
     m_mvEff[i].y = _y ;
     //this.x = x;
     //this.y = y;
     tmv.stop();
     if ( m_type == 1 )
      tmv.currentFrame = Math.random() * 3;
     tmv.play();
     //tmv.addEventListener(Event.COMPLETE, onComplete);
     tmv.addEventListener(EnterFrameEvent.ENTER_FRAME, Delegate.sendParameters( onFrame ,  i , getTimer()  ) );
     break;
    }
   }
   
  }
  
  private function onFrame( idx:int , time:int ):void
  {
   if ( getTimer() - time > 300)
   {
    var mv:MovieClip = m_mvEff[idx ] as MovieClip;
    mv.removeEventListeners();
    mv.visible = false;
    
    //m_textEff[idx].visible = false;
    
    
   }
 
   
  }
  
  private function onComplete( event:Event ):void
  {
   //event.currentTarget.removeEventListeners();
   var mv:MovieClip = event.currentTarget as MovieClip;
   mv.removeEventListeners();
   mv.visible = false;
   
   
   if ( m_type == 1) // 코인일경우
   {
    if ( CoinTextEff.g_coinTextEff != null)
    {
     
     LevelMgr.addGameCoin( m_val );
     
     
     
     CoinTextEff.g_coinTextEff.showEff( this.x + mv.x , this.y + 20 , m_val.toString() );
    }
   }
  }
  
  
  public function destroy():void
  {
   if ( m_mvEff != null)
   {
    for ( var i:int = 0; i < MAX_EFF_CNT; i++)
    {
     Starling.juggler.remove(m_mvEff[i]);
     m_mvEff[i].removeFromParent(true);
     m_mvEff[i] = null;
    }
   }
   
   m_Dir = null;
   
   this.removeEventListeners();
   
   System.gc();
  }
  
  
 }

}

'Programing > flash' 카테고리의 다른 글

starling main frame  (0) 2015.11.20
starling moviebutton  (0) 2015.11.20
coineff  (0) 2015.11.20
baseEff  (0) 2015.11.20
objectMgr  (0) 2015.11.20
flash 용 app 인증 파일 만들기  (0) 2012.12.11
Posted by 패스맨

댓글을 달아 주세요