Animated Start Button (How To)

Started by PEONPORE, Mon 06/06/2022 02:35:55

Previous topic - Next topic

PEONPORE

Not to sure how to go around this. I've checked the manual but I honestly can't get it. How would I go about adding a start button that is animated? I was wanting it to load up/start then stop moving, and have a start button to press after it has done its little animation. Sorry if this is a basic question

eri0o

For adding an animated button, first you need a GUI, with this button, and a view with the animation for the button, you can do it like this:

1. First we are going to create a GUI, in the Editor, go to the Explore Project tree, right click the GUIs entry, and select "New GUI"
2. Give a name to this GUI, say gStartGUI, and then in the Properties pane, mark it's visibility state to false
3. With the GUI tab open, in the toolbar on the top there is a button with an "Add GUI Button" tooltip, click on it, and move the cursor on top of the GUI and draw your button there
4. Click on the button you just drew, and then on the Properties tab, find the property Name, and rename your button to something you remember, like button_start
5. Now, on the Explore Project tree, select Views and right click it, and select "New View".
6. Give it a name, like "VIEW_BUTTON_START"
7. With the View tab open, click "Create new loop" and add the necessary frames by clicking "Create New Frame". If your frame sprites are sequential you can add just the first, by double clicking and selecting it, and then when adding new ones, AGS Editor will add the next frames

Now, if you already have all of this, you can just animate the button. We are going to use Button.Animate. So you probably already made a room which is your title screen room, where the character you marked as player already starts. The general idea now is to do this:


  • In the room that is your title screen, we are going to use the After Fade-in event to show the GUI, and then run the animation once
  • And then the person playing the game is free to play the game

In the Room Editor, click on the lightning bolt to open the Room Events pane. There, select the "Enter room after fade-in" and double click it. It will write an script in the Room Script, link it to the room and load it in the script editor.

Code: ags
function room_AfterFadeIn()
{
  gStartGUI.Visible = true;
  button_start.Animate(VIEW_BUTTON_START, 0, /* delay */ 2, eOnce, eBlock, eForwards);  // the actual button animation
}


If your GUI is grayed out, go in the General Settings, scroll until the Visual category shows, and in the "When player interface is disabled, GUIs should" entry, select "Display normally".

PEONPORE

Sorry, I have another issue. I'm not really sure how to animate the button? I've done everything you've said, but I'm not sure what to do when it comes to 'button.animate'. I did the whole room_afterfadein thing, but I'm unable to see the animated gui (since I don't know how to animate it or have it so the view_button_start) and get this https://i.imgur.com/kbHjDDo.png

Crimson Wizard

#3
Quote from: PEONPORE on Mon 06/06/2022 06:34:38get this https://i.imgur.com/kbHjDDo.png

The eri0o's example refers to the upcoming AGS 3.6.0. If you are using 3.5.1, the call to Animate should be slightly different.

Code: ags

button_start.Animate(VIEW_BUTTON_START, 0, /* delay */ 2, eOnce);

PEONPORE

Makes sense! I went ahead to go on the new build to try this. It shows up now, but is in the corner and not clickable - I'm just not really sure where to go with this https://i.imgur.com/RWI4nfa.png

eri0o

You can control GUI position and the button position by modifying their X, Y variables, either in the GUI Editor or in script (if you need to do it dynamically. The button is positioned inside the GUI, so if you move the GUI, it will move too. The GUI itself, is positioned relative to the screen.

The coordinates go in X from 0 at left to your game screen width to the right, and in Y from 0 at the top to your game screen height to the bottom.

Rik_Vargard

Well that works nicely, Thanks for that.  (nod)

You could change the title into "Animate Any GUI Button!"  :P

Also, I have a problem trying something...?

I want the animation to repeat with a delay I set with a timer.

So in the room_load function I put

Code: ags
SetTimer(1, 160);


And in repExec I put

Code: ags
function room_RepExec()
{
  if (IsTimerExpired(1))
  {
    Button1.Animate(11, 0, 2, eOnce);
    SetTimer(1, 160);
  }
}


Any ideas?

Thanks!

Crimson Wizard

Quote from: Rik_Vargard on Mon 13/06/2022 11:03:56
Also, I have a problem trying something...?

Please, don't just say "I have a problem", tell what the problem is, what is happening.

Your code itself looks fine.
First of all double check that the functions are connected to room events and actually run.

Cassiebsg

Also make sure the GUI, where the button is, is visible and it isn't set to pause game when visible... If it is, then you might want to add your code to repeatedly_execute_always instead. ;)
There are those who believe that life here began out there...

Rik_Vargard

Quote from: Crimson Wizard on Mon 13/06/2022 11:30:35
Please, don't just say "I have a problem", tell what the problem is, what is happening.

Sorry I will not use that phrase again; I thought I explained it after that  :P

Quote from: Cassiebsg on Mon 13/06/2022 16:37:22
Also make sure the GUI, where the button is, is visible and it isn't set to pause game when visible...

Thank you that made it work  (nod)

Crimson Wizard

Quote from: Rik_Vargard on Fri 24/06/2022 20:56:08
Quote from: Crimson Wizard on Mon 13/06/2022 11:30:35
Please, don't just say "I have a problem", tell what the problem is, what is happening.

Sorry I will not use that phrase again; I thought I explained it after that  :P

It's not about the phrase itself, but the further explanation was not clear: as you posted your script but did not tell what were your intentions and what exactly happens instead. Sometimes it's possible to guess what the person means, but not always, and there are multiple possibilities (script does not compile, script does not work as expected, game stops with error, and so on).

Rik_Vargard

Quote from: Crimson Wizard on Fri 24/06/2022 21:52:40
It's not about the phrase itself, but the further explanation was not clear: as you posted your script but did not tell what were your intentions and what exactly happens instead. Sometimes it's possible to guess what the person means, but not always, and there are multiple possibilities (script does not compile, script does not work as expected, game stops with error, and so on).

Ah OK I understand better now, I'll remember that.
Thank you for taking the time to explain :)

SMF spam blocked by CleanTalk