Wednesday, May 15, 2013

Starling MovieClip Hiccup! (Games)

   Even Daniel admits that should be enhanced and fixed when issue gets priority.

   What is important in any animation?

By my opinion is to see all the frames even in dropped frame rate then expected. I noticed big hiccups in how Starling implements MovieClip.advanceTime(and no matter what you do, you couldn't get precise duration of the frame especially with difference in time of frames of AVM depending of workload, so if you are expecting some currentFrame to be hit might never be. I think I remember Adobe encourages making timings based on TimerEvent and not onEnterFrame.

 You could also make adjusting of difference of more precise time with getTimer() but you never should allowed you jump frame cos previous frame have took some or all of his time. This would tell you at least to drop frame rate or try to solve bottlenecks.      

 Why not to using the AVM "juggler", but creating new one? I personally don't like whole concept of juggler cos first it makes Starling different from Flash, second hanging one MovieClip hangs all animations depending  of juggler (could happen to AVM too, but that is on global) and your advanceTime function is called no matter your MovieClip is stopped or not (checking flag and go in or go out of).

 Next "stop()" function should be stop(). Not reset. ;)

How many cases we want MovieClip to start playing on creation.

 If you see the animation carefully you would see that cos of different sizes of frames (width/height)
 SubTexture name="flight_03" x="916" y="1" width="382" height="286" frameX="-32" frameY="-73" frameWidth="440" frameHeight="440"/>
    SubTexture name="flight_04" x="1314" y="285" width="402"

height="218"
after switching the texture some parts could be cut and give also wrong hit area so you need to fix with readjustSize() after switching of texture.

 The other big problem is that often you have multiply animations of the Character (walking,runing,jumping...) and some of them should be combined(ex. run first and then run second on the end of first....). Also you need to trigger some action on some frame and not just last.

 What Daniel proposed on forums for mulitiply animations and also saw on guy having done tutorial on AciveTuts by creating MovieClip for every animation and using switch in you loop by (key or/and mouse action)  and which includes

 removeChild(currentMc);
juggler.remove(currentMc);
addChild(newMc);
juggler.add(newMc)

and count numbers of executing above, when checking loop is very fast and mouse/keys changes happen very often so the need of change of the Character. At the top of the cake aren't the fundaments of Flash are actually gotoAndPlay and gotoAndStop() :))). Other thing that boders me alot in Starling are big use of "private" modifier instead of "protected" and top of that when you create MovieClip you need to supply textures (not adequate in many situation see the feedback of the people in forums).

 //Most used call
  //mc= new MovieClipEx(Assets.getTextureAtlas("StarlingTexture","StarlingXml").getTextures("flight_"));
  
   //Add textures later
   //mc= new MovieClipEx();
   //mc.textures = Assets.getTextureAtlas("StarlingTexture", "StarlingXml").getTextures("flight_");
   

   //Add Label, Sound and Call frame script

   mc= new MovieClipEx();
   mc.textures = Assets.getTextureAtlas("StarlingTexture", "StarlingXml").getTextures("flight_");
   mc.setFrameSound(5, Assets.getSound("WingFlapSound"));
   mc.setFrameLabel(new FrameLabel("Starling Stand", 14));
   mc.fps = 60;

  //try adding label again
   try {
    mc.setFrameLabel(new FrameLabel("Starling Stand",14));
   }catch (e:Error) {
    trace("Intentional error", e);
   }
   trace("Label at frame 14 is:" + mc.getFrameLabel(14));
   //mc.setFrameDuration(14, 5);//set frame duration to 5s
   mc.addFrameScript(14, callback14,mc);//add arguments to callback
   mc.addFrameScript(15, callback15);
//add Complete and enter frame events listeners
mc.addEventListener(Event.COMPLETE, onComplete);
mc.addEventListener(Event.ENTER_FRAME, onEnterFrame);

    
   //GOTO and Stop by ID and label/FrameLabel
   // mc.gotoAndStop(14);
   //mc.gotoAndStop("Starling Stand");
   //mc.gotoAndStop(new FrameLabel("Starling Stand", 14));
  

//mc.nextFrame();
//mc.gotoAndStop("Starling Stand");
//mc.prevFrame();

//mc.gotoAndPlay(5);

  
   mc.play();
   
   this.addChild(mc);
   //Starling.juggler.add(mc)  NO MORE;
//Use original Starling MovieClip (hiccup test)
var mcOrg:MovieClipTrace = new MovieClipTrace( Assets.getTextureAtlas("StarlingTexture", "StarlingXml").getTextures("flight_"),60);
   mcOrg.x = 400;
   this.addChild(mcOrg)
   Starling.juggler.add(mcOrg);


 private function onEnterFrame(e:Event):void 
  {
   trace("MovieClipEx currentFrame:", MovieClipEx(e.target).currentFrame);
  }
  
  private function onComplete(e:Event):void 
  {
   trace("MovieClipEx Completed");
  }
  
  public function callback15():void 
  {
   mc.fps = 12;
   //mc.stop();
  }
  
  
  public function callback14(mc:MovieClipEx):void {
   trace("callback from frame id "+mc.currentFrameLabel.frame+" with label:"+mc.currentFrameLabel.name);
   
  }
  
 
MovieClipEx can be used also with animations imported from swf and swc.

 Not tested but I think it would work, if you concat new Vector textures( Character have received new fighting moves) to the current textures or add new Vector of textures (morphing or adding new armor of the Character).

See the video how the MovieClipEx is used in practice.

  Update 26.05.13: onTick function add so you can sync MovieClipEx with outside ticker. Download

No comments:

Post a Comment