Hi, 3dgs friends!
I made a break in my work. But best break for a programmer is to program something else
![](/ubbthreads/images/graemlins/grin.gif)
So, this is the small contribution - animated mouse pointers (I saw questions about this in "starting with 3dgs" and decide to do it as snippet).
Prepare big image with frames for your mouse pointer (like animated sprite). Make frames in this order: LeftClick, MiddleClick, RightClick, MouseMoving, MouseHolding.
This is thumbnail for my simple image, click on it to get real sized image (download and convert it to 32bit tga with alpha, i uploaded PNG because ImageCave rejected TGA):
Change script below to reflect your image settings (read comment in code to do this).
This script animates cursor 'forever'. If you want 'once' animation, like for a single click, you have to play with on_left,...on_right handlers.
This contribution is just an simple, may be errornous, example to show one way from many possible for beginners.
Code:
//LionTs: prepare big image (like for an animated sprite)
// with height = Height(Mouse_Map) and width = Width(Mouse_Map) * MouseMapFrames;
// place frames in order:
// LeftClick, MiddleClick, RightClick, MouseMoving, MouseHolding
BMAP MouseMap = "MouseMap.tga";
define MouseMapFrames, 25; //total number of frames in MouseMap image
//number of frames to animate in each 'mouse state'
define FramesInSeq, 5;
//delay between frames
define MouseAnimDelay, -0.1;
//just for us - readable constants
define stMouseLeft, 0;
define stMouseMiddle, 1;
define stMouseRight, 2;
define stMouseMoving, 3;
define stMouseHolding, 4;
//mouse states
var MouseState = stMouseHolding;
var MouseOldState = stMouseHolding;
var MouseMapsLoaded = Off;
BMAP* TmpMouseBmap; //temp bitmap
var MouseMaps[MouseMapFrames]; //frames array of mouse maps
function LoadMouse_startup //load mouse maps into array of frames
{
var f1;
var i = 0; var j = 0; var k; var n; var l;
var p; var a;
var MouseFrameWidth; var MouseFrameHeight;
MouseFrameHeight = Bmap_Height(MouseMap);
MouseFrameWidth = Bmap_Width(MouseMap) / MouseMapFrames;
f1 = bmap_lock(MouseMap, 0);
while (i < MouseMapFrames) {
TmpMouseBmap = bmap_createblack(MouseFrameWidth, MouseFrameHeight, f1);
bmap_preload(TmpMouseBmap);
MouseMaps[i] = handle(TmpMouseBmap);
f1 = bmap_lock(TmpMouseBmap, 0);
j = MouseFrameWidth * i;
l = MouseFrameWidth + j;
n = 0;
while (j < l) {
k = 0;
while (k < MouseFrameHeight) {
p = pixel_for_bmap(MouseMap, j, k);
pixel_to_bmap(TmpMouseBmap, n, k, p);
k += 1;
}
n += 1;
j += 1;
}
bmap_unlock(TmpMouseBmap);
i += 1;
}
bmap_unlock(MouseMap);
bmap_purge(MouseMap);
wait(1);
MouseMapsLoaded = On;
}
function AnimMouse_startup //animate mouse pointer
{
var MouseCurrentFrame;
var MouseStartingFrame;
var MouseEndingFrame;
MouseState = stMouseHolding;
MouseOldState = MouseState;
MouseCurrentFrame = MouseState * FramesInSeq;
Mouse_Map = curs_map;
while !(MouseMapsLoaded){
wait(1);
}
while(1) {
if (Mouse_Mode > 0) { //if mouse is visible
if MouseState != MouseOldState {
while (MouseCurrentFrame > MouseStartingFrame) {
Mouse_Map = ptr_for_handle(MouseMaps[MouseCurrentFrame]);
MouseCurrentFrame = max(MouseCurrentFrame - 1, MouseStartingFrame);
wait(MouseAnimDelay);
}
}else{
MouseStartingFrame = MouseState * FramesInSeq;
MouseEndingFrame = MouseStartingFrame + FramesInSeq;
Mouse_Map = ptr_for_handle(MouseMaps[MouseCurrentFrame]);
MouseCurrentFrame = cycle(MouseCurrentFrame + 1, MouseStartingFrame, MouseEndingFrame);
}
}
wait(MouseAnimDelay);
}
}
function Mouse_startup //reflect mouse state for animation proc
{
while (1){
if (Mouse_Mode > 0) { //if mouse is visible
Mouse_Pos.X = Pointer.X; //move the pointer
Mouse_Pos.Y = Pointer.Y;
if Mouse_Left { //and reflect 'mouse state'
MouseOldState = MouseState;
MouseState = stMouseLeft;
} else {
if Mouse_Middle {
MouseOldState = MouseState;
MouseState = stMouseMiddle;
} else {
if Mouse_Right {
MouseOldState = MouseState;
MouseState = stMouseRight;
} else {
if Mouse_Moving {
MouseOldState = MouseState;
MouseState = stMouseMoving;
} else {
MouseOldState = MouseState;
MouseState = stMouseHolding;
}
}
}
}
}
wait(1);
}
}
function mouse_tgl //simple mouse toggler
{
if (Mouse_Mode == 0) {
Mouse_Mode = 2;
}else{
Mouse_Mode = 0;
}
}
on_space = mouse_tgl; //show the mouse pointer on space key
function main
{
max_loops = 200000; //don't forget to set maxloops!
.............
That's all. Have to go to drink some beer.
PS.
Without handle() and ptr_for_handle engine crashes sometimes. Works, but crashes, i don't know why.