Routines in animation programming
Routines make things happen. The first routine run is called Start. It is case-sensitive.
The structure of a routine is basically a list of things to do.
Routines are run in response to events that you attach to user actions, sprites, or
alterations. Routines can also be called by other routines.
4 special variables exist in a routine:
- _sprite represents the sprite that called this routine through an event. Consider it to be the default sprite for future instructions.
- _clone refers to the clone most recently created in the routine
- _repeat contains a number representing which iteration of a "repeat" that this routine is (see below)
- _none will deactivate an event, ie: click=_none
create routine as MyProc
var vSprite=arg.1
if (vSprite.name="cliff")
exit
elsif (vSprite.name="dog")
return "happy dog"
else
update sprite s1 where xscale=2.5
endif
open url "http://upwithabang.com/" into "upwithabangWindow"
run routine OtherProc where repeat=5
end
- as {string}
- name assigned to routine - required
- set mousein={routine}
- set a routine to run when mouse enters the canvas.
- set mouseout={routine}
- set a routine to run when mouse exits the canvas.
- set mousemove={routine}
- set a routine to run when mouse moves on the canvas.
- set click={routine}
- set a routine to run when mouse is clicked on the canvas.
- set parent={sprite}
- set a sprite to be the parent of all sprites launched hereafter. Set this value to _none to remove the default parent.
- set keypress={routine}
- set a routine to run when a key is pressed and released. Deactivate with _none.
- set keydown={routine}
- set a routine to run when a key is pushed down. Deactivate with _none.
- set keyup={routine}
- set a routine to run when a key is released. Deactivate with _none.
- set offset={x,y}
- offsets the coordinates of the canvas origin but the given amount.
- set _sprite={sprite}
- set _sprite to a different default sprite to be used in subsequent run calls.
- launch {sprite}
- add the given sprite to the canvas
- log()
- displays the given value in an HTML div section with an id="log". If you'd
like to specify a differently named div, then use the trace command defined below.
- insert into {sprite} where alt={alteration}
- applies a named alteration to the sprite. Sprite can be a sprite name, _sprite, _clone, or a data value.
- insert into {sprite} where children={(sprite names)}
- makes the listed sprites children of the given "into" sprite. If there is more than one child then list the children inside parentheses, else list a single child without parentheses.
- insert into {sprite} where attach={(sprite names)}
- Like 'children' except the child position will remain at some screen location after attachment.
- remove from {sprite} where alt={alteration}
- remove the named alteration from the named sprite. Use _all to remove all alterations from a sprite.
- remove from {sprite} where type=_all
- remove all alterations from a sprite
- remove from {sprite} where children={(sprite names)}
- remove the named children from the named sprite. _all is also supported.
- remove from {sprite} where detach={(sprite names)}
- removed children remain at same screen location after detachment
- var {name}={value}
- create a variable that will only exist inside this routines. Parameters passed into a routine should be saved to a local variable with this instruction.
- update var {name} add={number}
- adds any number to the named variable
- update var {name} subtract={number}
- subtracts any number from the named variable
- update var {name} set={number}
- set any number to the named variable
- update var {name} reset
- restores a variable to its creation settings variable
- update sprite {name} detach
- detaches a child sprite from its parent, but it stays at same screen location.
- update sprite {name} where image={image file}
- changed the image of the sprite to the file given. This image may not be preloaded by the browser if you have not used the image previously.
- update sprite {name} where x={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where y={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where scale={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where xscale={number}
- changed the given value of the name sprite as indicated.
FireFox may fail to launch completion events if sprite
size reaches 0.0. Therefore, also set a minimum size of 0.01 or something
smaller if necessary.
- update sprite {name} where yscale={number}
- changed the given value of the name sprite as indicated
FireFox may fail to launch completion events if sprite
size reaches 0.0. Therefore, also set a minimum size of 0.01 or something
smaller if necessary.
- update sprite {name} where alpha={number}
- changed the given value of the name sprite as indicated
- update sprite {name} bringtotop
- brings the sprite to appear above all others
- update sprite {name} where angle={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where center={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where click={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where composition={value}
- changed the given value of the name sprite as indicated
- update sprite {name} where hflip={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where mouseup={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where mousedown={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where size={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where swipeup={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where swipedown={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where swipeleft={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where swiperight={routine name}
- changed the given value of the name sprite as indicated
- update sprite {name} where target={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where targets={number}
- changed the given value of the name sprite as indicated
- update sprite {name} where touchdrag={sprite name}
- make the sprite draggable by touch
- update sprite {name} where vflip={number}
- changed the given value of the name sprite as indicated
- update sprite {name} set {variable}={value}
- changed the given sprite variable to the value indicated
- update textsprite {name} where text={"string"}
- changed the text of the textsprite as indicated
- pause sound {name}
- pauses a sound that is playing.
- pause wait {name}
- pauses a wait alteration.
- unpause sound {name}
- unpauses a sound that is playing.
- unpause wait {name}
- unpauses a wait alteration.
- if ({expression}) {new lines of code } endif
- if the expression evaluates to true, do the lines of code below the current line but above endif, elsif, or else
- elsif ({expression}) {new lines of code } endif
- if the expression evaluates to true, do the lines of code below the current line but above endif, elsif, or else
- else {new lines of code } endif
- if the expression evaluates to true, do the lines of code below the current line but above endif.
- endif
- close an 'if' block
- drop {sprite}
- remove the named sprite from the canvas
- open url "{url}" into {"targetBrowserWindow"}
- open the given url in the named browser window
- run routine {name} where repeat={number}
- runs another routine (called a child routine) the number of times given by "repeat".
You must specify repeat to be at least 1. Two special variables are associated with routines.
_repeat is defined in the child routine and indicates which instance of the repeat it currently represents. _repeat=1 means this is the first time through. However if it is set to the name of a list (such as "repeat=data.MyList") then _repeat will represent which item in the list is being used (ie: _repeat=0 if no list items were used, or _repeat=5 if 5 list items have been used).
_sprite exists in all routines and indicates which sprite spawned this routine. You can use _sprite in replace of a sprite name.
- reset all
- remove all sprites from canvas
- clone from {sprite} as {name} [using {current|original}]
- makes a clone of the given sprite using either the original
definition of the sprite, or its current properties if it is already onscreen. You can change the sprite after cloning it
by using the special variable _clone. The _clone variable always refers to the most recently created clone
in the current routine.
- trace into {"id"} where value={value}
- displays the given value in an HTML div section specified by "id". This is
a valuable debugging tool.
- exit
- causes the current routine to stop processing any more commands and exits.
- return {value}
- causes the current routine to stop processing and returns the value.
- and
- Commands like 'update' normally only change one value per command. However you can change more than one if you separate each value with "and". If you omit
'and' then you must have a separate "update" for each value that you want to change.