Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: marypotter3 on Thu 22/09/2011 22:59:04

Title: Animated backgrounds!
Post by: marypotter3 on Thu 22/09/2011 22:59:04
Hey! How do I insert a animated background, but only if the player click on the hotspot first? And, after showing that animated background, how I change for the next room?

My code:
function hHotspot2_Look()
{
  if (change_bg)
  SetBackgroundFrame(0);
  if (change_bg2)
  SetBackgroundFrame(1);
  if (change_bg3)
  SetBackgroundFrame(2);
  if (change_bg4)
  SetBackgroundFrame(3);
  if (change_bg5)
  SetBackgroundFrame(4);
  else player.ChangeRoom(8);
}


function room_AfterFadeIn()
{

  SetBackgroundFrame(0);

Thanks!
Title: Re: Animated backgrounds!
Post by: Adrian on Fri 23/09/2011 10:28:43
As Khris already mentioned, please check the manual:
http://www.adventuregamestudio.co.uk/manual/SetBackgroundFrame.htm

In room before fade in you set the Frame to 0, as you already did:

SetBackgroundFrame(0);

Then in function hHotspot2_Look() you set the background rotation back to normal behaviour by passing the frame as -1:

SetBackgroundFrame(-1);
Title: Re: Animated backgrounds!
Post by: Khris on Fri 23/09/2011 14:35:47
Also note that you don't need 5 variables for this job.
Just change the type of change_bg to int, then store the number in there (since you're using frames 0-4, give it a default value of -1).

Now instead of setting change_bg2 to true, do this:
  change_bg = 1;

When it comes to setting the background:

  if (change_bg > -1) SetBackgroundFrame(change_bg);

Welcome to the wonderful world of variables :=
Title: Re: Animated backgrounds!
Post by: pcj on Fri 23/09/2011 14:36:46
But if you're already using the animated background feature to switch between versions of a background, you'll be unable to switch back to animating the background without it looking weird (since you only have 5 frames to work with).  At which point it may be better to use separate rooms for each background, or objects where needed instead of animated backgrounds.

Also, if you want to change the background for a room the character isn't presently in, you'll need to use a global variable and check it when the character loads that room.