Super-Animated backgrounds!

Started by Estaog, Thu 28/09/2006 16:30:23

Previous topic - Next topic

Estaog

Hey guys, is there any way to simulate an animation background with more than 4 frames? I don't know if I can do it with objects, I just wanted to get an opinion first.

Thanks :).
Think about the kittens man!

http://members.aol.com/johnk0/godkills.jpg

Khris

You can use timers and sprites.
// room script
int fs=101;Ã,  // first sprite
int ls=115;Ã,  // last sprite
int cs;Ã,  // current sprite
int animdelay=3;Ã,  // 3/40 seconds
// player enters screen (before fadein)
cs=fs;
SetTimer(1, animdelay);
// repeatedly execute
if (IsTimerExpired(1)) {
Ã,  cs++;
Ã,  if (cs>ls) cs=fs;
Ã,  RawDrawImage(0, 0, cs);
Ã,  SetTimer(1, animdelay);
}
Untested, might work. :=

Estaog

#2
Can you explain how the script works exactly?

Edit: Also, how do I import sprites without using the transparency feature?

Edit edit: The script gave an error about "unexpected 'cs' ".
Think about the kittens man!

http://members.aol.com/johnk0/godkills.jpg

Khris

about transparency:
add a single row of pixels to the sprites bottom using an unused color (e.g. pink), then when importing it, choose bottom-left for the transparency setting.
Now right-click the sprite and select "crop sprite edges".

about the error:
in room editor -> settings, click the {}-button, then insert the first portion directly at the top, outside any function.
Close the script editor.

The other two portions need to go into a RunScript interaction. Click the button with the red i, double-click the event (the comment above the code says which one), choose RunScript, click Edit, paste the code snippet into the window.

It works like this:
Some variables are defined to tell AGS which sprites are used.
cs, the variable that holds the current sprite, is initialised with the number of the first one, and animdelay is set. A gameloop i.e. one call to repeatedly_execute happens 40 times a second at default speed, I've set animdelay to 3 so I'll get ~15 frames per second.
Then timer 1 is started as soon as the player enters the room.

The code inside rep_ex constantly checks whether the times has expired.
If it has, it increments cs by one (next sprite), resets cs to the first frame if the last one was reached, then draws the background frame and resets the timer.

Estaog

Thanks, works now. Sorry for the question spamm, but how do i change the game default speed?
Think about the kittens man!

http://members.aol.com/johnk0/godkills.jpg

R4L

Did you look in the manual?

SetGameSpeed
SetGameSpeed (int new_speed)

Sets the maximum game frame rate to NEW_SPEED frames per second, or as near as possible to that speed. The default frame rate is 40 fps, but you can speed up or slow down the game by using this function. Note that this speed is also the rate at which the Repeatedly_Execute functions are triggered.
The NEW_SPEED must lie between 10 and 1000. If it does not, it will be rounded to 10 or 1000. Note that if you set a speed which the player's computer cannot handle (for example, a 486 will not be able to manage 80 fps), then it will go as fast as possible.

NOTE: Because the mouse cursor is repainted at the game frame rate, at very low speeds, like 10 to 20 fps, the mouse will appear to be jumpy and not very responsive.

NOTE: If you set the System.VSync property to true, the game speed will be capped at the screen's refresh rate, so you will be unable to set it higher than 60-85 (depending on the player's screen refresh).

Example:

SetGameSpeed(80);

will set the game speed to 80.
See Also: GetGameSpeed


Estaog

Alright thanks.

Now I'm trying to make an intro, but I don't want the main character to actually appear in the background. I was thinking of either spawning him off-screen (not sure if it's possible), or make it transparent. And I don't want to use the normal pop-up box to display non-character speech; I want to narrate the back-story as white speech in the middle of the screen.

Yea, I'm a noob :/.
Think about the kittens man!

http://members.aol.com/johnk0/godkills.jpg

Khris

Spawning the char off-screen/setting its transparency to 100 is both possible and can be useful, but there's a more simple way: in the room editor, tick the "hide player character" box.

Displaying narrator speech actually is achieved the most easy way by using a transparent character standing below the middle of the screen.

You could combine both and use the player to display narrator speech:
//player enters screen (before fadein)
int sc=player.SpeechColor;
player.SpeechColor=15;Ã,  Ã,  // white
// (after fadein)
player.Say("blah");
...
player.SpeechColor=sc;
player.ChangeRoom(x, y, 2);

SMF spam blocked by CleanTalk