Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Sprite hovering problem...

Author
Message
Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 6th Jul 2009 04:25
Hello all. I'm having a small issue with writing some code which will check if the mouse is hovering over a sprite within my game. The game i'm writing is a card game which deals with cards as sprites which are in stacks. I've developed the game so that when a player hovers over a small preview of the card on the table, a full size version of the card is shown in a preview window in the corner. The problem occurs with my hover checking code when two cards are stacked and only part of the card underneath is visible. I get flickering in the preview because the game is confused about which card to show since both are overlapping.

Does anyone have any ideas about a way to make a function which gets which card is underneath the mouse even if its only partially visible without it also returning all the cards beneath which are part of the stack of cards?

Thanks in advance guys, you always deliver!

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 6th Jul 2009 04:49
I don't know what your setup is like, but assuming you have a 'card' class which you can add attributes to:

Give each card in the stack a 'depth' attribute, say with the top card number 0, and increase the number as you go further down the stack. Then in your hover code, if there are multiple overlaps, just display the one with the highest depth.

Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 6th Jul 2009 04:55
Hmmm...that's interesting. Currently, i've got a class which represents the card objects on the table. In my main game loop i've put all the cards on the table in a vector and each game tick i'm simply looping through all the cards on the table to check if the mouse is over a card.

I'm wondering if there is a better method for updating the cards between frames. The only reason I mention it is that right now, i'm not quite sure how to check if the cards are overlapping one another. My current setup just checks to make sure the mouse is within the boundaries of a card.

Any ideas on a way to check if cards overlap or to optimize my solution to updating the cards?

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 6th Jul 2009 06:48
I think I would try to have stack objects which check within themselves for mouseovers on their cards, rather than checking through all cards at once.

That way the stack object can know which card is on top, and only pay attention to that one.

Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 6th Jul 2009 07:14
All of that sounds good except for the part about only paying attention to the card on the top of the stack. What I need is a way to check if the mouse is over the edge of a card even if other cards are on top of it. That way the preview will update and they won't have to move the card they want to see to the top of the stack. See what I mean?

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM
Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 6th Jul 2009 08:41
I guess I don't entirely understand what you are trying to accomplish ><

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Jul 2009 17:22
Quote: "In my main game loop i've put all the cards on the table in a vector and each game tick i'm simply looping through all the cards on the table to check if the mouse is over a card."


Is that vector ordered in drawing order? I'm sure you have a way of determining which sprites are drawn first and which are drawn last. Check them in reverse order of drawing (from top to bottom), and don't loop through all of them, but stop at the first one found.
IonFist
15
Years of Service
User Offline
Joined: 6th Jul 2009
Location:
Posted: 6th Jul 2009 19:02
Why don't you set a sprite as a mouse pointer and call dbSpriteCollision ( mouseSprite, 0). this will return return the sprite colliding with your mouse sprite. Additionally, I have noticed that the sprite return if the pointer is on top of more than one sprite will be the one drawn first.
Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 6th Jul 2009 21:07
@Phosphoer
Thanks anyways man. You helped me some.

@Mireben
Quote: "Check them in reverse order of drawing (from top to bottom), and don't loop through all of them, but stop at the first one found. "

Sounds good dude. I already have a break in the code in order to stop searching once a card is found, but never thought of checking the vector in reverse order for the drawing order. Good idea.

@IonFist
I've never used dbSpriteCollision before, sounds like a simple way to go about solving this problem. I'll give it a try. That may be a way around this whole issue.

I think i'm going to create a linked hash table to store all of the cards on the table. This way I can iterate through the list to update a hover event or I can quickly hash through the cards by using a keyword on a card in order to find out if it's there quickly. Thanks for the help guys, i'll be back soon to let you know if it worked or if I need more help. Cheers

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM
Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 8th Jul 2009 04:40
Ok guys, I tried the solutions you provided and while cunning it still didn't do what i'm looking for. I've provided a small illustration with this post to help you visualize what i'm trying to achieve.



Now, whenever I hover over the blue card, the engine thinks i'm hovering over the red card because it is only checking for the boundaries from the top left to the bottom right of each card. The only way for the game to show that i'm hovering over the blue card when they are on top of each other like this is for me to go all the way to the right side of the blue card so that the red card is no longer interfering. What I need to be able to do is check if the mouse is over the red card while they are stacked like this. I hope this helps, any ideas on how I can solve this would be greatly appreciated!

Thanks guys!

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM
Acolyte
18
Years of Service
User Offline
Joined: 3rd Feb 2006
Location:
Posted: 8th Jul 2009 05:59
Ok guys, after rethinking this and rethinking this, I tried to implement some suggestions from earlier and I think I finally wrapped my brain around the problem and figured out what I needed to change. I'm posting the solution to this so anyone who comes across this later can benefit from it.

Mireben got it right!

What I basically had to do is load all the cards into the game in one order, but in my update code for each game tick I had to check the status of the mouse hovering over them in reverse order. This eliminates the problem of the game getting confused from the bounding box collision code because it never has to worry about overlapping cards. Once you find the card that is underneath the mouse cursor you simply exit the loop which is searching for the card you're hovering over. Hope this helps!

Thanks guys for all your help and patience, and I hope you guys have an easier time than me in your coding endeavours! Cheers!

Windows XP Home Ed. SP/2 ---> GeForce FX 5500 - 256MB
160 GB HD ---> 1 Gig RAM

Login to post a reply

Server time is: 2024-11-25 06:55:46
Your offset time is: 2024-11-25 06:55:46