[Golist] Fuse-like parser in a few minutes!
Moses Gunesch
moses at goasap.org
Wed Feb 20 23:47:08 PST 2008
I will do a video tut on this topic soon.
My hope with Go was that the tween layer would typically stay OO in
nature, then people could build custom parsers to do Fuse syntax, XML
syntax or anything custom. Well, I gave it a shot and it worked just
fine! Having labored so long over Fuse myself, it was a little
shocking how easy this was.
First, I made a general multiple-property tween class that I called
BlockTweenMG. It has a method setProperty(name:String, value:Number)
and the constructor simply accepts two arrays like zigoengine used to:
(target:Object=null, props:Array=null, endVals:Array=null...). It's
versatile enough to start with, although it doesn't support filters or
other fanciness.
Next I created a parser class that I called BlockParserMG with a
static method called go() and one called sequence(), pluse one private
static method parseAction() that parses a generic fuse object and
returns a new BlockTweenMG.
public static function go(action:Object): BlockTweenMG {
var tween:BlockTweenMG = parseAction(action);
tween.start();
return tween;
}
While go() just parses & starts one tween, sequence() will parse any
number of actions using an open input (...actions). It was easy to
make it support arrays of objects for parallel tweens like in Fuse. It
builds & returns a SequenceCA instance.
parseAction() is amazingly lightweight. It makes the tween and loops
through the properties of the object. It goes, if
(tween.hasOwnProperty(prop)) then set the prop on the tween... this
takes care of all the basic tween props: delay, duration, easing, etc.
Otherwise assume it's a tween prop and use the addProperty() method on
the tween instance. This was all simply too easy, so I threw in one
bit of fanciness. Go's SequenceCA class supports Custom-Advance
options for sequencing so I added a conditional to look for the
property 'advance' and set it to the current SequenceStepCA.
I ran this sequence and voila, it worked without a hitch!
var targ:Sprite = addSquareSprite();
BlockParserMG.sequence({ target: targ,
x:200,
scaleX:5,
duration:2,
// custom-advance
before the action completes:
advance: new
OnDurationComplete(.5)
},
// a parallel-action
array
[{ target: targ,
y:200,
scaleY:5,
duration:1.5,
easing:Back.easeOut
},
{ target: targ,
rotation:180,
easing:Back.easeInOut
}]);
I'll have a tutorial up soon on this, but don't wait... Try this at
home!
If you're not into Fuse syntax, try inventing your own XML syntax for
condensing animation code, or surprise us with something totally new.
:)
- m
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://goasap.org/pipermail/golist_goasap.org/attachments/20080221/89172496/attachment.html
More information about the GoList
mailing list