[SOLVED]Making Button

Started by VegeTato, Sat 08/04/2017 16:17:01

Previous topic - Next topic

VegeTato

Hi,i want to make a game like "who want to be a millionaire" so the game is all about buttons.
My question is how to make a button in AGS ? and when i aim at that button it turns to green(for example)
i got the 2 pictures one is (Start game"red color") and i got another one (Start game"green color)
so how to create a button and when i aim on it how to change it to another picture(color). Thanks.

dayowlron

Set the buttons NormalGraphic property.

btnButton.NormalGraphic = 15;

where 15 is the sprite with the color of the button you want.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

VegeTato

i don't understand"Set the buttons NormalGraphic property."
i don't have a buttons.... this is my question how to create a buttons then animate them >.<

can you explain more ? :3

Cassiebsg

Create a GUI, add a button to it...
Or create an object in the room and give it the "start game" sprite number, then change it to the green sprite number...

Or give us more info about what you have done so far and how you want your button to be.
There are those who believe that life here began out there...

VegeTato

Quote from: Cassiebsg on Sat 08/04/2017 21:55:32
Create a GUI, add a button to it...
Or create an object in the room and give it the "start game" sprite number, then change it to the green sprite number...

Or give us more info about what you have done so far and how you want your button to be.

i have created an object in my game and i give it the "start game" sprite and it works fine,but i don't know how to animate it
because there is only (talk to object,interact,etc...) there is no option for "walk over object" or aim on the object.
so when i aim(my mouse) at the "start game" it turns to another sprite(green,start game)
any way to do that ? :/

a screen shoot for what i have done:
   

Snarky

In the AGS Editor, press the F1 button on your keyboard. The help file will pop up. It includes a tutorial with explanations of how to perform basic AGS tasks. Read it. The relevant sections here are under "Tutorial | Setting up the game | Animations" and "Other Features | Editing the GUIs", but you should have a look at the whole tutorial.

Slasher

#6
As per Snarky

In the objects events property panel click interact and a function will appear in the room script.

Just add something like this as an example:

Code: ags

function StartGame_Interact() // AGS Adds this Interact function
{
player.Walk(oStartGame.X,oStartGame.Y+10,eBlock,eWalkableAreas); // player walks to start game object
player.Loop=3; // face object

// Animate object this like:
oStartGame.SetView(10) // or whatever view it is you have made
oStartGame.Animate(0,4,eOnce,eBlock); // will play loop 0 only once

// Do this like start the game etc
{


At least it's a start


VegeTato

Quote from: slasher on Sun 09/04/2017 16:33:21
As per Snarky

In the objects events property panel click interact and a function will appear in the room script.

Just add something like this as an example:

Code: ags

function StartGame_Interact() // AGS Adds this Interact function
{
player.Walk(oStartGame.X,oStartGame.Y+10,eBlock,eWalkableAreas); // player walks to start game object
player.Loop=3; // face object

// Animate object this like:
oStartGame.SetView(10) // or whatever view it is you have made
oStartGame.Animate(0,4,eOnce,eBlock); // will play loop 0 only once

// Do this like start the game etc
{


At least it's a start

Thanks :D now when i press on Start game it turns to green :)
but i didn't know how to animate when i aim on the button

Example:
When i move my pointer on the button or object i want it to change to another color
When i aim it turns to yellow when i out the area it goes back to red.

is that possible to make ? :) (Aiming on button animate) Thanks.

Slasher

Right...

Are we talking gui control Button or an Object?

VegeTato

Quote from: slasher on Mon 10/04/2017 03:24:41
Right...

Are we talking gui control Button or an Object?
i am using object, because when i use gui button it keep showing that annoying background, i want my button to be png,
And in the event section there is only "click on button" option, there is no aim on button or mouse move on button Option.



But if you know how to delete the background in gui and how to animate the button in gui And how to position the button in GUI. then please tell me how :D

So i am now using Object(Start_button) and View3(animating Start_button) And character(player) and another character to talk to him(Dead)



This is the code for Menu room i used after you told me how to animate the button(Thanks again :))
Code: ags
function room_Load()
{
aKako.Play();  // play music
}
function Start_button_AnyClick()  // animate button
{
Start_button.SetView(3);
Start_button.Animate(0,25, eOnce);
player.ChangeRoom(2);
}


Cassiebsg

The easiest way is to make a GUI, with a transparent background.
Then create a button, in the button's properties you can then set the sprite numbers for "normal", "when mouse over" and "pushed/clicked"...  ;)
Use the button event to then code what happens when you push/click the button.
There are those who believe that life here began out there...

Slasher

#11
For reference

To set any gui to be transparent in its properties panel open up color and choose black or enter 0 in the color option for the background. The gui area will be magenta colour which is the transparency colour.

Snarky

You don't see the button properties because the properties pane has been set to the "events" tab. Click on the little list button next to the thunderbolt to switch it back to properties.

VegeTato

Thank you so much guys ^^ every thing is working fine now ;-D i have animated the button When aim on it, and animated it when i click :3

Now i got another 2 new problems :-X if they got solved ill be so thankful :cheesy: And i can start my project to the NEW GAME ! :D Please help me :)

Problem 1:
So after i made the button code when click(player change room)to room 2(i was in room 1)the problem is The button keep showing in room2 i thought it will only show in room1 but looks like it comes to all my rooms :-[ Any idea how to fix ?

Problem 2:
is there is any way to add an audio when i aim at the button ?
Because in the events section there is only "OnClick" option.
i want to add an audio when my mouse aim on the button Is that possible ? :-\

(Thanks for your time).

Slasher

#14
Check in help manual for: GetAtScreenXY

Examples in Global Rep Exec
Code: ags

}
  if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) ==Button3){  // If over a gui button
   aKNOCK.Play(); // will play this sound when mouse over
   
}
  if(player.Room==3 && Object.GetAtScreenXY(mouse.x, mouse.y) ==object[5]){ // if over a room object
    aKNOCK.Play(); // will play this sound when mouse over


If the button is an object in room one then it should only show in room one and not two..if they are objects..
objects only relate to the room the are in.



Khris

I don't know how you implemented the button, but if you used a GUI, just set it to invisible before sending the player to the next room.

As for playing a sound: you wouldn't want the sound to run over and over again. Here's how to set that up:

Code: ags
// above repeatedly_execute() in GlobalScript.asc
bool wasOverButton = false;

  // add this *inside* repeatedly_execute()
  bool isOverButton = GUIControl.GetAtScreenXY(mouse.x, mouse.y) == Start_button;
  if (isOverButton && !wasOverButton) btnSound.Play();
  wasOverButton = isOverButton;

dayowlron

If the button is showing in both rooms then it sounds like the button is on a gui. to make it disappear you need to make the gui invisible.

gGui.Visible=false;
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

VegeTato

Problem 1: Solved by adding this code to my room to invisible the button :D Thanks
Code: ags
Start_button.Visible=false;


Problem 2:didn't work :((i am using Gui button and what i want is to hear a sound(aPsh) when i move the mouse over the button)

i tired what you guys said and here is the result:

Quote from: slasher on Tue 11/04/2017 02:44:41
Check in help manual for: GetAtScreenXY

Examples in Global Rep Exec
Code: ags

}
  if(GUIControl.GetAtScreenXY(mouse.x, mouse.y) ==Button3){  // If over a gui button
   aKNOCK.Play(); // will play this sound when mouse over
   
}
  if(player.Room==3 && Object.GetAtScreenXY(mouse.x, mouse.y) ==object[5]){ // if over a room object
    aKNOCK.Play(); // will play this sound when mouse over


If the button is an object in room one then it should only show in room one and not two..if they are objects..
objects only relate to the room the are in.



I have tried that and the result is when i start the game the sound keep playing (and i didn't even aim my mouse at the button)the sound just keep playing again and again in all the rooms. here is the code i used:
Code: ags
function room_Load()
{
aKako.Play();  // play music
if(GUIControl.GetAtScreenXY(318, 157)){  // If over a gui button
aPsh.Play(); // will play this sound when mouse over
}
}

then i tired this code but when i run the game it gives me Error (line 4): undefined symbol 'button3'
Code: ags
function room_Load()
{
aKako.Play();  // play music
if(GUIControl.GetAtScreenXY(318, 157)==button3){  // If over a gui button
aPsh.Play(); // will play this sound when mouse over
}
}


Quote from: Khris on Tue 11/04/2017 10:39:37
I don't know how you implemented the button, but if you used a GUI, just set it to invisible before sending the player to the next room.

As for playing a sound: you wouldn't want the sound to run over and over again. Here's how to set that up:

Code: ags
// above repeatedly_execute() in GlobalScript.asc
bool wasOverButton = false;

  // add this *inside* repeatedly_execute()
  bool isOverButton = GUIControl.GetAtScreenXY(mouse.x, mouse.y) == Start_button;
  if (isOverButton && !wasOverButton) btnSound.Play();
  wasOverButton = isOverButton;

When i tired this code it gives me Error (line 4): Type mismatch: cannot convert 'GUIControl*' to 'GUI*' Here is the code i used:
Code: ags
function room_Load()
{
aKako.Play();  // play music
  bool isOverButton = GUIControl.GetAtScreenXY(314, 157) == Start_button;
  if (isOverButton && !wasOverButton) aPsh.Play();
  wasOverButton = isOverButton;
}

+i don't understand what bool code used for...

Any idea how to fix all this ? :undecided:

Information's about my project:
  • aPsh = The sound i want to play when i aim at the button.
  • I am using GUI button not object.
  • aKako.Play(); is just a code to play background music its working fine.
  • My GUI button name is Start_button

Please help in this final problem :~(

Slasher

Both I and Khris' code works.

Using Khris'

Code: ags

// in Global

bool wasOverButton = false; // Placed above function repeatedly_execute() 

function repeatedly_execute() {   

  bool isOverButton = GUIControl.GetAtScreenXY(mouse.x, mouse.y) == Start_button; // when the mouse is over Start_button
  if (isOverButton && !wasOverButton) aPsh.Play();  //   aPsh sound will play once each time whilst over Start_button
  wasOverButton = isOverButton;
}


Provided your GUI is not set to 'Pause Game when shown' then the sound will play.

This works...So make sure you add it correctly as shown...

Error (line 4): undefined symbol 'button3' means ags can't find button3 probably because it does not exist. My code only used button3 as an example.




dayowlron

I did notice you are putting ur code in room_Load and the code needs to be in repeatedly_execute.
Do you have some code in repeatedly_execute that is making the sound?
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

SMF spam blocked by CleanTalk