Object to turn visible when hovering over hotspot and off when not?

Started by RosstheBoss0, Sun 30/08/2015 21:07:41

Previous topic - Next topic

RosstheBoss0


Hi, this is my first time posting but I have probably a very simple problem I cant for the life of me figure out the solution to.

I've been using the ags engine for a good 4 months straight or so but I've only now come to the point of creating a menu for my game
I'm trying to simply have a line display under the text the mouse hovers over and disappear when the mouse is no longer hovering over it.

I attempted using a hotspot that when I hovered over it I used the "mouse moves over hotspot" event "MouseMove" and then within that set the line which is an object to visible, however I cannot get it to dissapear when the mouse hovers off of it, it simply stays on screen.

Sorry if this has been posted before, I cant find a solution anywhere unless im searching for the wrong things.


Grok

One way you could do that is to do this in the function room_RepExec()

Code: ags

if (mouse.x>350 && mouse.x<400 && mouse.y>100 && mouse.y<150)
oLine.Visible=true;
else
oLine.Visible=false;


If the mouse cursors x value is between 350 and 400 and the y value is between 100 and 150 (to be exchanged for whatever values apply in your case), the object oLine is visible. Otherwise it is not.


Another way is to use a gui with a button and to have different images for mouseover and not-mouseover.

Monsieur OUXX

http://www.adventuregamestudio.co.uk/wiki/Object_functions_and_properties#Object.GetAtScreenXY
Code: ags

//Code below to be inserted in room function 'RepExec' (if you don't know how to create it, then ask):

Object* o = oTheObjectYouWantToSpot; //change to your own object here
if (Object.GetAtScreenXY(mouse.x, mouse.y) == o) {
   o.Visible=true;
} else {
   o.Visible=false;
}


Don't forget that you can iterate on every object of the room, to automate the process :
Code: ags

int n=0;
while (n<Room.ObjectCount)
{
    Object* o = object[n]; //this gets the n-th object in the room. Feel free to do any "overlapping" test on it.
    n++;
}

//Note: I'm not sure if it's object[n] or Room.object[n] or Game.object[n]
 

RosstheBoss0


Thank you both for replying, I am unsure how to create a repeat execute within a room, I looked in the help and it suggests it would be found in room events though I'm not seeing it?

Crimson Wizard

To be honest, this should probably be put into Global Script's function "repeatedly_execute".

You will want same effect for other rooms too, correct?

Grok

Quote from: RosstheBoss0 on Mon 31/08/2015 19:09:34

--- I am unsure how to create a repeat execute within a room, I looked in the help and it suggests it would be found in room events though I'm not seeing it?



If you need something that is going to be used in more than one (1) room a global solution might be more efficient (putting the code in the GlobalScript). But as I take it you are pretty new to this I think you might want to start with a solution for one room and move to the global stuff when you got the basics down. But that is just my opinion. 

RosstheBoss0



Aha! Perfect I got it working, thats awesome, thank you guys, I'd have been stuck in a confusion loop forever without your help.

Yeh right now its only for the one room which is I imagine for now the only room I'll need it in but its good to have an idea of how I might expand on that if I needed in the future.

Monsieur OUXX

Quote from: Crimson Wizard on Mon 31/08/2015 19:14:31
To be honest, this should probably be put into Global Script's function "repeatedly_execute".

Out of curiosity: object[] and Room.ObjectCount are accessible from there?
 

Snarky


SMF spam blocked by CleanTalk