Mouse click on GUI [SOLVED]

Started by Kinoko, Mon 06/11/2006 18:10:24

Previous topic - Next topic

Kinoko

This is such a basic question, I almost want to shoot myself for asking, but here goes. I have a GUI in the corner of a scrollable screen, I simply want this code:

Code: ags

SetViewport(mouse.x*30,mouse.y*30);


to be used when the left mouse button is clicked on said GUI. Given my recent game project involved no mouse whatsoever, I have no idea how to do this. Which script do I write the code in? Global? The GUI's script? I'm not sure how to achieve, "if mouse click on GUI".

Maverick

#1
I do not know if this code will work with the latest version of AGS but the code goes into global script and assuming the GUI is called gSetviewp and you have a button on it = button 0 it would look something like this:

Code: ags


#sectionstart interface_clickÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button) {
Ã,  if ((interface == SETVIEWP) &&(button ==0)){
Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  SetViewport(mouse.x*30,mouse.y*30);
Ã,  Ã,  Ã,  Ã, }
Ã,  Ã, }


Take a look at THIS thread although it does not deal with your specific issue it will give you a lot of insight on how to handle a click event on a GUI.

EDIT:
As Ashen mentioned below, this has become redundant and although it still works fine its not the best way of doing it.


Khris

Don't use this. ^

-Select the GUI in the GUI Editor
-in the small window, double click the lowest property called "On click"
-use the default name or define your own, click "OK", this will add a function to the global script
-double clicking a blank spot on the GUI will take you to the newly created function, that's were your code goes

Ashen

Maverick's suggestion should still work in the newer AGS versions, it's just bad paractice. interface_click is obsolete as of 2.7.)

You could do someting similar using a button that fills the GUI and the Control Functions, but personally I'd use KhrisMUC's method. (As I was typing it up myself when he posted...)

It could also go in repeatedly_execute(_always), but those ways seem like they'd be easier.
I know what you're thinking ... Don't think that.

Kinoko

Thanks, that worked a charm ^_^

What can I use to find the X, Y coords of where the mouse was clicked on a GUI? At the moment, the GUI is the in top-left hand corner at 0,0 and I'm using mouse.x and mouse.y but this seems like it will be unreliable as it's only telling me where the cursor is as opposed to where the click was. I guess in theory it should work anyway but is there a more trustworthy/direct way?

The basics are that I have a map in the corner of the screen 1/30th the size of the room, and I want the player to be able to click on the map and have it take the screen to that corresponding place in the room.

Gilbert

Use something like this?

mouse.x - gMap.X
mouse.y - gMap.Y

SMF spam blocked by CleanTalk