Rather than having each bitmap register its own enterFrame callback, let's just set these guys up as tickable and let the central Ticker handle it.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@977 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Mike Thomas
2010-08-11 20:10:25 +00:00
parent 407af70322
commit 78391781ab
2 changed files with 19 additions and 4 deletions
@@ -26,6 +26,7 @@ import flash.geom.Point;
import flash.geom.Rectangle;
import com.threerings.display.DisplayUtil;
import com.threerings.miso.client.Tickable;
import com.threerings.util.DirectionCodes;
import com.threerings.util.Log;
@@ -34,6 +35,7 @@ import com.threerings.util.Log;
* about in a scene.
*/
public class CharacterSprite extends Sprite
implements Tickable
{
private static var log :Log = Log.getLog(CharacterSprite);
@@ -62,6 +64,13 @@ public class CharacterSprite extends Sprite
updateActionFrames();
}
public function tick (tickStamp :int) :void
{
if (_framesBitmap != null) {
_framesBitmap.tick(tickStamp);
}
}
/**
* Called after this sprite has been initialized with its character
* descriptor and character manager. Derived classes can do post-init
@@ -221,9 +230,11 @@ public class CharacterSprite extends Sprite
DisplayUtil.removeAllChildren(_mainSprite);
if (_aframes != null) {
_aframes.getFrames(_orient, function(frames :MultiFrameBitmap) :void {
_framesBitmap = frames;
_mainSprite.addChild(frames);
});
} else {
_framesBitmap = null;
updateWithUnloadedSprite();
}
}
@@ -277,6 +288,9 @@ public class CharacterSprite extends Sprite
* orientation. */
protected var _aframes :ActionFrames;
/** The currently active set of bitmaps for this character. */
protected var _framesBitmap :MultiFrameBitmap;
/** The offset from the upper-left of the total sprite bounds to the
* upper-left of the image within those bounds. */
protected var _ioff :Point = new Point();
@@ -24,9 +24,11 @@ import flash.display.Sprite;
import flash.events.Event;
import com.threerings.miso.client.Tickable;
import com.threerings.util.StringUtil;
public class MultiFrameBitmap extends Sprite
implements Tickable
{
public function MultiFrameBitmap (frames :Array, fps :Number)
{
@@ -35,16 +37,15 @@ public class MultiFrameBitmap extends Sprite
_frameRate = fps / 1000.0;
addChild(_bitmap);
setFrame(0);
addEventListener(Event.ENTER_FRAME, enterFrame);
}
public function enterFrame (event :Event) :void
public function tick (tickStamp :int) :void
{
if (_start == 0) {
_start = (new Date().time);
_start = tickStamp;
}
var elapsedTime :int = (new Date().time - _start);
var elapsedTime :int = (tickStamp - _start);
var frameIndex :int = Math.floor(elapsedTime * _frameRate);
var totalFrames :int = _frames.length;
if (frameIndex >= totalFrames) {