while loop graphic effects

Started by MagikiDashiki, Mon 24/11/2003 06:58:50

Previous topic - Next topic

MagikiDashiki

Im trying to use the AGS engines internal graphic routines to make background effects in my game... for instance here is relativelty simple one that doesn't work.

function charglow(int min, int max)
{
int mint = min;
while(min != max)
{
min+=1;
SetCharacterTransparency(GetPlayerCharacter(),min);
if(min == max)
min = mint;
}
}

im trying to make the character flash in and out of transparency in a simple pattern -- but it doesn't work... I can't figure out what to do.

then - after importing it into the header- I'll call it in a script and get an error when I test it that says the engine is "hung in a loop" or something.

I've tried similar concepts with the flashlight plugin to make light darkness/hue changes, but for some reason you have to insert a Wait(1); into the script so the changes refresh- giving the effect of animation-

is there a way to have internal graphic routine based animations that run in the background and don't effect the actuall game play?

you could also use the draw commands to make effects --  but for some reason I can't figure out how to do this within the actual game

Gilbert

I think you want it to be executed over and over in game without interrupting the game's progress, but then you need to put it in rep-exec script. A minor change can be made to make it work for once (blocking the game) though (I'm too lazy to make an unblocking one at the moment):

function charglow(int min, int max)
{
int mint = min;
while(min != max)
{
min+=1;
SetCharacterTransparency(GetPlayerCharacter(),min);
Wait(1);
//if(min == max) -- commented to avoid infinite loops
//min = mint;
}
}

MagikiDashiki

Thats kind of what I was saying... I don't think you can do that in AGS without blocking the game.

Kweepa

See for example After's code in the parabolic movement thread - you need a "setup" function, and a repeatedly_execute block.
But then, if something else blocks the game, your graphical effect won't update. To do something like that you'd need a plugin I think.

Steve
Still waiting for Purity of the Surf II

Scorpiorus

Yeah, or just simply avoid blocking functions or make your own that call the repeatedly_execute routine:

function MoveCharacterBlockingButCallRepeatedlyExecute(int CharId, int x, int y) {

MoveCharacter(CharId, x, y);
while (character[CharId].walking) {
repeatedly_execute();
Wait(1);
}
}


~Cheers



CB..

#5
wouldn't some thing like this do the trick?

blinking object view animation

//at room load

SetTimer(1,200);
SetTimer(2,300);

//repeatedly execute

if (IsTimerExpired(1)==1)
{SetObjectFrame(0,7,0,0);
SetTimer(1,200);}
if (IsTimerExpired(2)==1)
{SetObjectFrame(0,7,0,1);
SetTimer(2,300);}


Gilbert

Alright, here's an example to make a nonblocking function for it (tested).

On top of global script:
int cgmin, cgmax, cgcurrent, cgdir;
export  cgmin, cgmax, cgcurrent, cgdir; //for them to be used in rooms


in rep_exec of global script:
if (cgdir) {
cgcurrent+=cgdir;
if (cgcurrent>=cgmax){
cgcurrent=cgmax;
cgdir=0-cgdir;
} else if (cgcurrent<=cgmin){
cgcurrent=cgmin;
cgdir=0-cgdir;
}
SetCharacterTransparency(GetPlayerCharacter(),cgcurrent);
}


In a room where you want to use that function, on top of the room's script:
import int cgmin;
import int cgmax;
import int cgcurrent;
import int cgdir;


When you want to start the glowing, just decide what min, max, current value you want to use for the transparency factor, and for cgdir, positive means towards invisible, negative means teh other way round (hint: use larger magnitude can make the glows faster, eg, cgdir = 5), and set the variables correspondingly, the glow would start automatically, eg:

cgmin=0;
cgmax=60;
cgcurrent=0;
cgdir=2;


When you want the effect to stop, just set:
cgdir=0;

SMF spam blocked by CleanTalk