Jump to content

Recommended Posts

Posted

So, generally I have been using 

this.isHovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width
				&& mouseY < this.y + this.height;

for setting any of my custom buttons' hover status, but I noticed this won't really work if I have overlapping buttons. In my specific case, this is the issue:

  Reveal hidden contents

As you can see, the white keys extend under the black keys, meaning that the aforementioned method of setting a button's isHovered variable would not work, as it would return true for the first key (C) even if its the corresponding black key (C#) that is hovered, as long as it is within the width of the first key

  Reveal hidden contents

The green is the area that would return true using the method I mentioned above for the white key, and red for the black, but the blue area esults in both the white and black keys getting their isHovered variable set to true, while the desired behaviour is to only have the black key's isHovered value to be true, and the white key's false.

 

While I know I can use 2 different checks to check the white key in this manner, green first check and yellow second:

  Reveal hidden contents

I was wondering if there is a better method to do this, without having to hardcode the checks for every single key, as all have different indentations regarding black keys.

 

Thanks for taking the time to read this, and I am looking forward to see what you guys suggest.

Posted

One option would be to have it check if any black keys are hovered first, and if so, completely skip the check for white keys. You'd probably have to restructure the way you're performing checks whenever the user clicks, but it's certainly doable.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Posted
  On 4/21/2020 at 2:56 AM, imacatlolol said:

One option would be to have it check if any black keys are hovered first, and if so, completely skip the check for white keys. You'd probably have to restructure the way you're performing checks whenever the user clicks, but it's certainly doable.

Expand  

It's a nice idea, but how would I go about doing it? The white key in which I would need to check if a black key is being hovered does not have access to the black key, so I can't do that

 

For reference: Button class

  Reveal hidden contents

Screen class:

  Reveal hidden contents

 

Posted

Well there's a few options, but here's my initial idea. You could make a couple methods for adding black or white keys respectively and then have those methods call addButton and also place the keys in separate lists. Then, you could override the mouseClicked function of your screen and have it first iterate through the black keys and check the result of their mouseClicked function, then the white keys, and then fall back to the default behavior.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.