Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Help with function (timer issue?)

Author
Message
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 3rd Dec 2007 02:24
Alright so when a user clicks the mouse button, it calls a "flush" function which is suppose to display a simple little water animation:

if (dbMouseClick())
{
boxstate = 0;
menu_state = 4;
flush(); //water animation
}

The animation works great accept for the fact that it only plays when the mouse is being held down, here is the function:



void flush()
{
//this is suppose to flush the screen with water,
//however it only does it when the mouse click is held down
switch (flushing)
{
//reset everything
case 0:
water_x = 0;
flushing = 1;
break;
//bring the water out
case 1:
for (int x = 0; x <= 2; x++)
{
water_transparency++;

if (water_transparency >= 150)
flushing = 2;

dbSprite ( 4, water_x, water_y, 4 );
dbSetSpriteAlpha (4, water_transparency);
water_x--;
dbSprite ( 4, water_x, water_y, 4 );
}
break;

//settle the water back down
case 2:
for (int x = 0; x <= 2; x++)
{
water_transparency--;

if (water_transparency == 75)
sludge = 0;

if (water_transparency <= 0)
flushing = 0;

dbSprite ( 4, water_x, water_y, 4 );
dbSetSpriteAlpha (4, water_transparency);
water_x--;
dbSprite ( 4, water_x, water_y, 4 );
}
break;
}
}

I just want this to play once without the mouse needing to be held down, how can i do this? Thanks!
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 6th Dec 2007 07:27
Well, you could figure out how many cycles is needed for the animation to complete, then make a "for" loop for the animation itself. Say it needs 30 iterations to finish, say;

for( int l = 0; l <30; ++l )
{
blah, blah, animation code, blah...
}

Since it's a sprite, it should be pretty easy to get how many iterations you need. The since you don't want it to terminate early, you'd have to put a boolean trigger in there...I saw you had the variable "flushing", so make it when flushing == 1, start the loop, then at the end of the loop, set it back to 0;

for( int l = 0; l <30; ++l )
{
blah, blah, animation code, blah...
if( l == 29 )
{
flushing = 0;
}
}

Keep in mind, if you keep the flushing animation in a second function, you'll have to pass the flushing variable in by reference so you can change it's value.

Hope that helps!
Bishop


Tux is my guildmaster.

Login to post a reply

Server time is: 2024-09-29 05:22:55
Your offset time is: 2024-09-29 05:22:55