~extremepopcorn/dhlib/dhlib_ep

« back to all changes in this revision

Viewing changes to lib/ui/anim/lib/Simple.ahx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
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.
 
4
 * </license> 
 
5
 */
 
6
package ui.anim.lib;
 
7
 
 
8
/**
 
9
 * A very simple Actor for demonstration purposes.
 
10
 *
 
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
 
14
 *
 
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.
 
18
 */
 
19
DEFACTOR(Simple)
 
20
 
 
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.
 
24
         */
 
25
                
 
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 )
 
29
        
 
30
        // The `ONINIT' handler is optional and it will be called whenever the Actor is first initalized --
 
31
        // part of the contructor
 
32
        ONINIT()
 
33
        {
 
34
        }
 
35
        
 
36
        
 
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 )
 
40
        
 
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)
 
45
        {
 
46
                //we could setup variables here.
 
47
        }
 
48
        ONSTEP()
 
49
        {
 
50
                //nothing is needed while stepping since we are "Still"
 
51
        }
 
52
        
 
53
        SEQUENCE(Rotate,NONE)
 
54
        {
 
55
        }
 
56
        ONSTEP()
 
57
        {
 
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;
 
62
                
 
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
 
66
                taintDraw();    
 
67
        }
 
68
        
 
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)
 
74
        
 
75
        // this will be called anytime the actor needs to be redrawn, either decided by the framework
 
76
        // or when tainted with "taintDraw"
 
77
        ONDRAW()
 
78
        {
 
79
                //the "gfx" variable contains the GraphicsX of our drawing surface.
 
80
                gfx.clear();
 
81
                
 
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 ) ) );
 
84
                gfx.moveTo( 0, 0 );
 
85
                gfx.lineTo( Math.cos( angle ), Math.sin( angle ) );
 
86
        }
 
87
        
 
88
ENDACTOR()
 
 
b'\\ No newline at end of file'