GameMaker: Studio

GameMaker: Studio

View Stats:
ZombiDev Jun 25, 2016 @ 5:13am
The GUI layer and the cursor
So, I want a sprite on my gui layer to change when the mouse is over it, but the sprite doesnt change. I've tried placing a controller object into the room to control the sprite but nothing happens.

can anyone help?
Last edited by ZombiDev; Jun 25, 2016 @ 5:58am
< >
Showing 1-15 of 23 comments
woodsguide Jun 25, 2016 @ 2:47pm 
something like ?

if mouse_x and mouse_y are within x1,x2, y1,y2 then draw_sprite(x,y.spr_blah)
ZombiDev Jun 25, 2016 @ 3:02pm 
Originally posted by woodsguide:
something like ?

if mouse_x and mouse_y are within x1,x2, y1,y2 then draw_sprite(x,y.spr_blah)

not really, what I'm trying to do is build a HUD. I've tried using objects before and they don't work, they're never still so I have to use sprites drawn onto the GUI layer.
I've tried some options before but now I'm trying to use a controller object to control the buttons on the HUD base.

when they should change image_index, what they should do. but nothing is working.
no one else has been able to give me a solution to this problem.
woodsguide Jun 26, 2016 @ 1:05am 
im not saying to use objects.. but the process is similar...
draw your hud in the draw gui step as normal.. then in the end step i believe .. if mouse is in x1x2y1y2 area draw other sprite

idk ')
Oyakiiv Jun 26, 2016 @ 3:06am 
:odpbox:
try this:

if point_in_rectangle(mouse_x,mouse_y,x1,y1,x2,y2)
{
//sprite change code here
}

you will have to do this for all the sprites/sections of your hub that you want your mouse to affect.

for more information on this, as well as other shapes to check for a collision in, check movement and collisions, under references in the help file.

Hope this helps! :goalsmile:

edit:
lol sorry it is very late, didnt realize this was said already, still hope this helps. But if not, please give us a clearer picture of what you are trying to do.
Last edited by Oyakiiv; Jun 26, 2016 @ 3:09am
ZombiDev Jun 26, 2016 @ 8:55am 
Originally posted by Oyakiiv:
:odpbox:
try this:

if point_in_rectangle(mouse_x,mouse_y,x1,y1,x2,y2)
{
//sprite change code here
}

you will have to do this for all the sprites/sections of your hub that you want your mouse to affect.

for more information on this, as well as other shapes to check for a collision in, check movement and collisions, under references in the help file.

Hope this helps! :goalsmile:

edit:
lol sorry it is very late, didnt realize this was said already, still hope this helps. But if not, please give us a clearer picture of what you are trying to do.

Hi I'll try this way, but where should I set the x1, y1, x2, y2 variables?
and is their a certain way I should set them?
ZombiDev Jun 26, 2016 @ 12:45pm 
Originally posted by The Argonian Alcoholic:
Originally posted by Oyakiiv:
:odpbox:
try this:

if point_in_rectangle(mouse_x,mouse_y,x1,y1,x2,y2)
{
//sprite change code here
}

you will have to do this for all the sprites/sections of your hub that you want your mouse to affect.

for more information on this, as well as other shapes to check for a collision in, check movement and collisions, under references in the help file.

Hope this helps! :goalsmile:

edit:
lol sorry it is very late, didnt realize this was said already, still hope this helps. But if not, please give us a clearer picture of what you are trying to do.

Hi I'll try this way, but where should I set the x1, y1, x2, y2 variables?
and is their a certain way I should set them?

I'll give a clearer picture of what I am trying to do:

I am trying to create a hud that is made out of sprites. I cannot use objects on the GUI layer because I can never ether get them to follow the view, or follow it to the point. it tened to have this delay on it when it had to catch up to the view.

I need to get the sprite to work right and also work with the states. its because of the states that I cannot use the draw code outside of the charicter object, as it will only give the "not set before reading" error.

I hope this give a clearer picture of what I need to do. if you know a better way to do the HUD then please tell me
Oyakiiv Jun 26, 2016 @ 1:54pm 
the x1, y1 represents the top left corner of the rectangle that defines the area that you want to check for collisions and x2, y2 is the bottom right corner. both sets of x and y create the rectangle.

you should be able to use the point_in_rectangle() command in the draw gui event. Worst case scenario is that it doesnt recognize the mouse positions on the screen, because the gui layer uses it's own x and y values. But I'm sure there is a workaround for that if that is the case.

okay, I think I understand better now, but just to be sure, are you going for a drag-and-drop effect? or do you just want to recognize the mouse to use buttons?

edit:

sorry if this makes it confusing, but I just want to correct myself on a small thing. It doesnt actually check for a collision, it "Checks to see whether a given point falls within the defined rectangular area".
Last edited by Oyakiiv; Jun 26, 2016 @ 1:59pm
ZombiDev Jun 26, 2016 @ 1:59pm 
Originally posted by Oyakiiv:
the x1, y1 represents the top left corner of the rectangle that defines the area that you want to check for collisions and x2, y2 is the bottom right corner. both sets of x and y create the rectangle.

you should be able to use the point_in_rectangle() command in the draw gui event. Worst case scenario is that it doesnt recognize the mouse positions on the screen, because the gui layer uses it's own x and y values. But I'm sure there is a workaround for that if that is the case.

okay, I think I understand better now, but just to be sure, are you going for a drag-and-drop effect? or do you just want to recognize the mouse to use buttons?
the latter. I want the buttons to recognise the mouse when its over it, I know that the GUI layer has its own x and y values, but what are the values variables?
Oyakiiv Jun 26, 2016 @ 2:13pm 
I'm not sure there are any variables for this, just checked the manual briefly. The x and y values for the gui layer are determined by the size of the application surface.

though, now that I have given it some thought, the worst case scenario, most likely wont even occur. But we wont really know till you try.
ZombiDev Jun 26, 2016 @ 2:21pm 
Originally posted by Oyakiiv:
I'm not sure there are any variables for this, just checked the manual briefly. The x and y values for the gui layer are determined by the size of the application surface.

though, now that I have given it some thought, the worst case scenario, most likely wont even occur. But we wont really know till you try.

I did do this a while back, but I never knew how to use it
https://www.youtube.com/watch?v=HnYsJWE6-3c

would this help? given that I'm using sprites?
Oyakiiv Jun 26, 2016 @ 3:08pm 
okay, I got fed up with the waiting game and tested it myself.

THE WORST CASE SCENARIO DOES HAPPEN. the mouse coordinates are determined by its location in the room, not the screen.

but I did watch about 10 minutes of your video and your solution to the coordinate problem will work and is actually the workaround that I had briefly mentioned before (just not in any detail).

So yes, the point_in_rectangle() function does work. I would post what I have done in the workshop for example...but it is the broken version and I cant be bothered to fix it right now as I have chores to do...
ZombiDev Jun 26, 2016 @ 3:20pm 
Originally posted by Oyakiiv:
okay, I got fed up with the waiting game and tested it myself.

THE WORST CASE SCENARIO DOES HAPPEN. the mouse coordinates are determined by its location in the room, not the screen.

but I did watch about 10 minutes of your video and your solution to the coordinate problem will work and is actually the workaround that I had briefly mentioned before (just not in any detail).

So yes, the point_in_rectangle() function does work. I would post what I have done in the workshop for example...but it is the broken version and I cant be bothered to fix it right now as I have chores to do...

Ok, I have a better understanding of how this works. Its esseintially a little invisible box that when the mouse is inside, an interaction can happen. so I'm building a button object myself in a way.

but how do I place it in the room? I know how to make the rectangle with x1,y1-x2,y2 but how does it know where the sprite is?

I'm writing all this down btw so I never bother steam again with these HUD problems :)
Oyakiiv Jun 26, 2016 @ 3:44pm 
okay, I just did a double check with the point_in_rectangle() the x1,x2,y1,y2 coords also use the room coords so the workaround will have to be applied to those as well... good thing I checked.

so the workaround will have to be applied to that as well.

as far as it knowing where the sprite is, if you plan on having the sprites be stationary in the gui then you just place the rectangle overtop of it. but if the sprite will be in varied positions then it will be a tad more complicated, especially with the workaround being applied.

for the sprite you will need to create new variables to represent the x and y of the sprite, so that as these variables change, as does the position of the sprite.

then for the rectangle, because of the workaround to make the positioning compatible with the gui, you will need to create special variables for these as well.

sorry if I sound vague or complicated, I'm running out of time to complete my chores before my fiance gets home, so it will be about 2 ish hours before I can get back to you.

ZombiDev Jun 28, 2016 @ 4:30am 
Originally posted by Oyakiiv:
okay, I just did a double check with the point_in_rectangle() the x1,x2,y1,y2 coords also use the room coords so the workaround will have to be applied to those as well... good thing I checked.

so the workaround will have to be applied to that as well.

as far as it knowing where the sprite is, if you plan on having the sprites be stationary in the gui then you just place the rectangle overtop of it. but if the sprite will be in varied positions then it will be a tad more complicated, especially with the workaround being applied.

for the sprite you will need to create new variables to represent the x and y of the sprite, so that as these variables change, as does the position of the sprite.

then for the rectangle, because of the workaround to make the positioning compatible with the gui, you will need to create special variables for these as well.

sorry if I sound vague or complicated, I'm running out of time to complete my chores before my fiance gets home, so it will be about 2 ish hours before I can get back to you.

Hi been kind of busy so I couldn't try out the code before. I found an alternitive in the comments section of the video. instead of using the system ben showed to get the mouse position on the screen, I could just use:

window_mouse_get_x
window_mouse_get_y

only, the comment told me to place it in the x,y coordinites of the point_in_rectangle function. I thought that told the function where the button sprite was?

if thats in there, how would the function know where the button was to draw the rectangle?
ZombiDev Jun 28, 2016 @ 8:02am 
Originally posted by The Argonian Alcoholic:
Originally posted by Oyakiiv:
okay, I just did a double check with the point_in_rectangle() the x1,x2,y1,y2 coords also use the room coords so the workaround will have to be applied to those as well... good thing I checked.

so the workaround will have to be applied to that as well.

as far as it knowing where the sprite is, if you plan on having the sprites be stationary in the gui then you just place the rectangle overtop of it. but if the sprite will be in varied positions then it will be a tad more complicated, especially with the workaround being applied.

for the sprite you will need to create new variables to represent the x and y of the sprite, so that as these variables change, as does the position of the sprite.

then for the rectangle, because of the workaround to make the positioning compatible with the gui, you will need to create special variables for these as well.

sorry if I sound vague or complicated, I'm running out of time to complete my chores before my fiance gets home, so it will be about 2 ish hours before I can get back to you.

Hi been kind of busy so I couldn't try out the code before. I found an alternitive in the comments section of the video. instead of using the system ben showed to get the mouse position on the screen, I could just use:

window_mouse_get_x
window_mouse_get_y

only, the comment told me to place it in the x,y coordinites of the point_in_rectangle function. I thought that told the function where the button sprite was?

if thats in there, how would the function know where the button was to draw the rectangle?

I just tried this code, but nothing happened. can you see anything wrong with it?




if point_in_rectangle (window_mouse_get_x(), window_mouse_get_y() , 32, 32, 32, 32) && hovering = 0 {


with spr_badge_button {

image_index = 1
hovering = 1
}
}
else
{
image_index = 0
}
< >
Showing 1-15 of 23 comments
Per page: 1530 50

Date Posted: Jun 25, 2016 @ 5:13am
Posts: 23