2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
9
* A very simple Actor for demonstration purposes.
11
* Note: Actors reside in ".ahx" files and must be processed by the preprocessor --
12
* the standard makefile does this. Otherwise the command is:
13
* $DHLIB_ROOT/m4/m4haxe.sh --out Simple.hx --prepend $DHLIB_ROOT/lib/ui/anim/ActorDef.ihx Simple.ahx
15
* The actor is just a very specialized haXe class which uses many macros to assist
16
* in its creation. Inside the `DEFACTOR/ENDACTOR' pair is a normal haXe class and thus
17
* any haxe code can be used.
21
/* Parameters are available at construction time and used to control the look and behaviour
22
* of the Actor. These are not (currently) alterable after instantion -- at least from the caller,
23
* the actor itself can do whatever with them.
26
// `PARAM' indicates a parameter, the first item is the name, the second one the type, and the
27
// third one the default value, an optional fourth parameter specifies help documentation
28
PARAM( speed, Float, 2.0, How fast we'll rotate )
30
// The `ONINIT' handler is optional and it will be called whenever the Actor is first initalized --
31
// part of the contructor
37
// `VAR's are used to track member variables. The use of a `VAR' as opposed to a normal
38
// haXe definition allows proper default initialization/control
39
VAR( angle, Float, 0 )
41
// `SEQUENCE's define the behaviours available to an actor. In this case we'll define
42
// a "Still" sequence. The `DEFAULT' keyword indicates this will be the sequence used by
43
// the actor upon instantiation
44
SEQUENCE(Still,DEFAULT)
46
//we could setup variables here.
50
//nothing is needed while stepping since we are "Still"
58
//we'll simply increase our rotation based on our speed
59
//notice that `VAR's are access directly, and `PARAM's are available in the "params" member
60
// "elapsed" indicates how much time has passed, a Float expressed in seconds
61
angle += params.speed * elapsed;
63
//since we need redraw in order for our change to be visualized we call taintDraw. This
64
//may seem obvious, but actors which combine other sprites, or use native Flash effects
65
//may not need to redraw themselves to have the change visualized
69
// the following construct indicates that our drawing surface will be scaled to the extents
70
// (0.5,0.5) which is useful since then we'll be 1 wide/tall and can easily center ourselves on
71
// (0,0) -- this is optional, if not specified an identity transform is used, in which case the
72
// actor size is available as the parameter "actorSize"
73
DRAWTRANSFORM_SCALE(0.5,0.5)
75
// this will be called anytime the actor needs to be redrawn, either decided by the framework
76
// or when tainted with "taintDraw"
79
//the "gfx" variable contains the GraphicsX of our drawing surface.
82
//we'll draw a cyan line from the center to the angle we're at
83
gfx.use( Pen.solid( 5, Color.rgb( 0, 1, 1 ) ) );
85
gfx.lineTo( Math.cos( angle ), Math.sin( angle ) );
b'\\ No newline at end of file'