In SPGL, my Sprites are Animated, and have an Animation. The Animation is executed one tick at a time, following a sequence of Commands. Some Commands end the frame (ie. setting a new Image for the Sprite).
One of those Commands is an EventCommand, which sets a special general purpose integer to an arbitrary value.
For example, here's the Roving Eye from Alien Flux:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <animation name="roving_eye_shoot.animation" > <frame i="spriteimage.roving_eye0010" d="2" /> <frame i="spriteimage.roving_eye0011" d="2" /> <frame i="spriteimage.roving_eye0012" d="2" /> <frame i="spriteimage.roving_eye0013" d="10" /> <event id="1" /> <frame i="spriteimage.roving_eye0014" d="1" /> <frame i="spriteimage.roving_eye0015" d="2" /> <frame i="spriteimage.roving_eye0016" d="2" /> <frame i="spriteimage.roving_eye0017" d="7" /> <event id="1" /> <frame i="spriteimage.roving_eye0014" d="1" /> <frame i="spriteimage.roving_eye0015" d="2" /> <frame i="spriteimage.roving_eye0016" d="2" /> <frame i="spriteimage.roving_eye0017" d="7" /> <event id="1" /> <frame i="spriteimage.roving_eye0014" d="1" /> <frame i="spriteimage.roving_eye0015" d="2" /> <frame i="spriteimage.roving_eye0018" d="2" /> <frame i="spriteimage.roving_eye0019" d="2" /> <frame i="spriteimage.roving_eye0020" d="2" /> <frame i="spriteimage.roving_eye0021" d="2" /> <event id="2" /> </animation> |
The roving eye, once it has called sprite.setAnimation(shootAnimation), polls its event and takes appropriate action. Here's a snippet of the roving eye tick code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| switch (sprite.getEvent()) { case 0: break; case 1: fire(); sprite.setEvent(0); break; case 2: phase = PHASE_WOBBLING; sprite.setEvent(0); selectNewTarget(); sprite.setAnimation(wobbleAnimationResource); shadowSprite.setAnimation(wobbleShadowAnimationResource); break; default: assert false; } |
Cas
