GUI animation problems

Started by AdamM, Fri 07/05/2010 03:25:11

Previous topic - Next topic

AdamM

I decided to redesign my interface more than the old walk-look-interact mouse cursors, and I've started by converting my default LucasArts-style conversation system into a Sierra-style portrait system with interaction buttons alongside it. Kind of like in Jagged Alliance 2 (if anyone except me has played that game).

The easiest way to do this is of course a GUI. I wanted the GUI to have a start-up animation, so it does something snazzy when it first pops up, but this doesn't seem so easy. The only thing you can animate on a GUI is a button, and even then it doesn't block! My function-in-progress looks like this, designed to resize the button so it is the size of the GUI and then animate:

Code: ags
function StartTalkSystem(Character *chartalkto, Dialog *chardialog)
{
  gTalkSystem.BackgroundGraphic=572;
  gTalkSystem.Visible=true;
  TSAnimateButton.Visible=true;
  TSAnimateButton.Height=66;
  TSAnimateButton.Width=169;
  TSAnimateButton.Animate(70, 0, 3, eOnce);
  TSAnimateButton.Visible=false;
  TSAnimateButton.NormalGraphic=572;
}


Of course when I tested it out, nothing appeared to happen. This is of course because button.Animate(); was not blocking and the lines of code after were being run immediately, causing the button to disappear. Commenting them out makes the animation visible, but even then I have no idea of knowing when the animation is finished, and therefore I can't write any more code for it.

Why is this the case, and what should I do?

Dualnames

#1
 TSAnimateButton.NormalGraphic=572;

The case is this line. The Animate function destroys the button's normal,mouseover and pushed images.
Therefore something like this in the
Code: ags

int check;
function repeatedly_execute_always() {
if (TSAnimateButton.PushedGraphic!=whateverhaveyouwhenthegamestarts) {
if (check!=80) {
check++;
return;
}
TSAnimateButton.NormalGraphic=572;
//mouse over graphic
//pushed 
}
}

}

EDIT: Okay, right there Khris.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Khris

Wow dualnames, why did you roll back to senselessly quoting the complete previous post?

AdamM, since you know exactly how long the animation is going to take, why not put a Wait() after .Animate()?

AdamM

I do? Well I'm not very good at converting such things; how do I convert animation frames to game loops?

And even if I did use Wait(), that's a bit sloppy isn't it? It's a hard-coded solution instead of allowing the game to do the necessary calculations itself.

AdamM

Well, I've just gone with

Code: ags
while (TSAnimateButton.Graphic!=581) {Wait(1);}


where 581 is the sprite number of the last frame of the animation. I still don't understand why there isn't a BlockingStyle enumerated type for this function.

AdamM

I have a new problem. After my GUI pops up I want a black-and-white static effect to appear on the portrait for a few seconds or so. I could use an animation, but that's repetitive to the eye, so I wrote a DrawStaticOnButton function that draws a randomly generated mixture of black and white pixels on a DynamicSprite. To test it I called DrawStaticOnButton at the end of my function that starts up the conversation GUI, but nothing appears to happen. After some debugging, I've discovered that the DrawStaticOnButton function actually runs as expected, but as the function finishes and the script hits the next line of code, the button that it has been drawing onto (TSLeftPortrait) has its sprite number reset to 0. Any ideas why this is happening?

Code: ags

function DrawStaticOnButton(int StaticDSX, int StaticDSY, Button *theButton)
{
  DynamicSprite *StaticDS = DynamicSprite.Create(StaticDSX, StaticDSY);
  DrawingSurface *StaticDSsurface = StaticDS.GetDrawingSurface();
  int StaticDSpointX = 0;
  int StaticDSpointY = 0;
  while (StaticDSpointY<StaticDSY+1) {
    while (StaticDSpointX<StaticDSX+1) {  
      if (Random(1)==1) {StaticDSsurface.DrawingColor = 15;} else {StaticDSsurface.DrawingColor = 0;}
      StaticDSsurface.DrawPixel(StaticDSpointX, StaticDSpointY);
      StaticDSpointX++;
    }
    StaticDSpointY++; StaticDSpointX=0;
  }
  StaticDSsurface.Release();
  theButton.NormalGraphic=StaticDS.Graphic;
}

function StartTalkSystem(Character *chartalkto, Dialog *chardialog)
{
  TSMouseX=mouse.x-(gTalkSystem.Width/2);
  TSMouseY=mouse.y-(gTalkSystem.Height/2);
  while ((TSMouseX+gTalkSystem.Width)>=System.ScreenWidth) {
    TSMouseX--;
   }
  while ((TSMouseY+gTalkSystem.Height)>=System.ScreenHeight) 
  {
    TSMouseY--;
   }
  gTalkSystem.X=TSMouseX;
  gTalkSystem.Y=TSMouseY;
  gTalkSystem.BackgroundGraphic=572;
  gTalkSystem.Visible=true;
  TSAnimateButton.Visible=true;
  TSAnimateButton.Height=66;
  TSAnimateButton.Width=169;
  TSAnimateButton.Animate(70, 0, 3, eOnce);
  while (TSAnimateButton.Graphic!=581) {Wait(1);}
  TSAnimateButton.NormalGraphic=572;
  gTalkSystem.BackgroundGraphic=581;
  TSAnimateButton.Visible=false;
  mouse.Mode=eModeWalkto;
  DrawStaticOnButton(49, 60, TSLeftPortrait);
}

AdamM

Quote from: Ashen on Sun 28/01/2007 15:35:03
If the problem is just that the Button doesn't change graphic, then as I understand it DynamicSprites declared in a function (e.g. a Button's Control function, or the on_key_press condition that opens the Load Game GUI) are only good in that function - once it finishes running the DymanicSprite is deleted, and all uses are cleared.

How was I supposed to know this?!!

SMF spam blocked by CleanTalk