Animated background delay

Started by Kinoko, Mon 02/02/2004 09:54:57

Previous topic - Next topic

Kinoko

Is there any way to control the delay for each individual frame of an animated background?

Gilbert

#1
Yes, but to have full control of them, you probably need to use text scripting to control them.

Here's some example code, say in a room with 3 bg frames, you want the frames to stay for 8, 10, 7 game loops respectively:

1. put on top of that room's script:
int bgtimer,curbg;
int bgdelay[3];


2. Put in "first time player enters screen" script:
bgdelay[ 0 ]=8;
bgdelay[1]=10;
bgdelay[2]=7;
curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];


3. Put in "repeatedly execute" script:
bgtimer--;
if (bgtimer==0) {
curbg++;
if (curbg>2) curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
}


EDIT:
* Gilbot V7000a  kills the smileys
EDIT2:
Should be fixed now.

Kinoko

It's telling me it "Cannot assign value to entire array" in regards to bgdelay--;

Ishmael

3. Put in "repeatedly execute" script:
bgtimer--;
if (bgtimer==0) {

curbg++;
if (curbg>2) curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
}

Me thinks...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Gilbert

hehe yeah, me bad, I got the variable names mixed up myself. I'll edit the codes to fix it.

Kinoko

Well, the code seems to be fine now. The only problem is that the background doesn't animate :)

Gilbert

Strange, I tried and it worked for me.

Can you post your exact codes for these parts here for reference?

Kinoko

       At the top of the script for that room:

// room script file
int bgtimer,curbg;
int bgdelay[3];

    Then:

function room_c() {
 // script for room: First time player enters screen
bgdelay[0]=8;
bgdelay[1]=10;
bgdelay[2]=7;
curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
 
}

    Then:

function room_d() {
 // script for room: Repeatedly execute
bgtimer--;
if (bgtimer==0) {
curbg++;
if (curbg>2) curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
}
 
}

Gilbert

Strange, it's just identical to my original code.

What did you mean by the bg not animating? Was it stuck at frame 0 without changing?

How many frames do you have for that room background?

Kinoko

I originally had 5 but I'm trying it with 3 right now just so I can use your code exactly. Everything else that's supposed to happen in that room works fine (animation, etc) but the background is stuck on the first original frame. If I use the "fullscreen preview" it works but only as it used to, with the normal delays.

Gilbert

That's a scripting thing, it won't show in full-screen preview. Did you really tried testing the game?

One possibility I can think of, was that the events in the interaction editor had somehow been removed. Check from the room's interaction editor, are there really "run script" operations for the events " First time player enters screen" and "Repeatedly execute"?

Kinoko

I checked and rechecked that everything was in the right place in the interaction editor, and it's all fine. I tried testing and retesting the game, starting in that room and then going to that room from another.... it's the same everytime. I can't think of anything that would be affecting it, if the script's all correct.

Thanks for helping me as much as you have.

Gilbert

Try one more thing to test, try commenting some of the lines in repeatedly execute:

function room_d() {
 // script for room: Repeatedly execute
bgtimer--;
//if (bgtimer==0) {
curbg++;
if (curbg>2) curbg=0;
SetBackgroundFrame(curbg);
bgtimer=bgdelay[curbg];
//}
 
}

Normally it will mean that there'll be a frame change each game loop (so they'll run like crazy), but if the bg frame is still stalled, it may be something that kept the above content in repeatedly execute to not run for some reasons.


Kinoko

I tried it, and it was still the same.

I also started up a new game, created the room again and put that code in - worked perfectly.

I think I'm gonna try recreating this room again from scratch and seeing if that cleans it up. There's something in my existing game that's blocking this and I might just bypass it if I start over with the room.

Thanks for all your help, I really appreciate it.

Gilbert

#14
In that case, try removing the 2 interactions from the room (BACKUP your room first!), readd them, and put the codes there and see if it works.

EDIT: also, check if there're any suspicious code in the global script (it may be possible that ther's some SetBackgroundFrame() lines in it, or some other things that prevents the scripts in the room to get processed).

Kinoko

Ok, little update. I created a new room, setup the bg code - it worked fine.
I transferred across my "before fadein" code - it worked fine.
I transferred across my "after fadein" code - stops working.

I took out everything from my "after fadein" code, except for what it begins with - Wait(100); and it still doesn't work, but after 100 game cycles ... voila!

Sooo, my guess is that the background animation can only run when it isn't being blocked by other script functions - but how can I solve this? It's essentially a cut scene so I need to have blocking functions in the rest of the code. Is there something I can do to keep this bg animation running while the rest of the script carries on?

Gilbert

#16
Ah in that case, there's a dirty way to do this (there're better ways I think, but this method's simple to archive):

Just change the Wait(100); line to:

int waitimer=100;
While (waitimer){
Wait(1);
room_d(); //change it if your repeatedly execute script is not of this name
waitimer--;
}

Kinoko

That's fine for my Wait(100); line but I have many more functions going on after that. Should I use that formulae for every one of them individually?

Gilbert

Depends on what functions they are, if there're no blocking functions (eg. Wait() and MoveCharacterBlocking() are examples of blocking functions), you don't need to do that anymore, but if there're some blocking functions, you may need to do so then.

Kinoko

OK, I'll have to try it all later because I've gotta take a break from this right now ^^

Thanks for sticking with me through my stupid problems!

SMF spam blocked by CleanTalk