Open Prim Animator/Touch Ping Pong
Jump to navigation
Jump to search
//! @brief This is a utility script for OPA for cases when animation frames are meant to be viewed sequentially in both forward and "reverse".
/**
* @author SignpostMarv Martin
*/
//! The number of animation frames
integer count;
//! if TRUE then the "ping pong" is in effect and should not be interupted.
integer running=FALSE;
//! interval between animation frames
float interval = 1.0;
//!
integer at=1;
integer mod=1;
default{
state_entry() {
llMessageLinked(LINK_ROOT, -1, "XDrecordedSnapshots", NULL_KEY); // get the number of animation frames from the core OPA script.
}
link_message(integer s, integer n, string m, key i){
if(m == "XDrecordedSnapshots" && n >= 0){
count = n; // update the number of animation frames
}
}
touch_start(integer t){
if(!running){ // if we're not doing the "ping-pong",
running = TRUE; // set the flag to TRUE
llSetTimerEvent(interval); // then set the timer event away.
}
}
timer(){
if(count <= 0){
llSetTimerEvent(0); // stop the timer
}else{
at += mod; // add the modifier (which may be a negative integer)
if(at >= count){ // if we're at the end of the "ping-pong",
mod = -1; // change the mod to negative 1 in preparation of reversing the animation
llSetTimerEvent(0); // turn off the timer
running = FALSE; // set the running flag to FALSE so a user can touch the script.
}else if(at <= 1){ // if we're at the end of the "pong-ping",
mod = 1; // change them od to positive one in preparation of running the animation
llSetTimerEvent(0); // turn off the timer.
running = FALSE; // set the running flag to FALSE so a user can touch the script.
}
llMessageLinked(LINK_ROOT, at, "XDshow", NULL_KEY); // instruct the core OPA script to change the displayed animation frame.
}
}
}