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 / Making a menu button?

Author
Message
RoseOwnage
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 12th Dec 2011 17:10
ok, so i got now different buttons loaded! and they are all at the right place, but now i want that i can press on it, it doesn't goes very well with it searching a week on the forum or something. i think i got how to change the sprite if it got collision:



so i want to know that i can learn from it!
-how to press button with action?
-how to change sprite when collision?

Hi
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 13th Dec 2011 05:16 Edited at: 13th Dec 2011 05:18
All you have to do is check if the mouse cursor is in a specific set of coordinates. I made this a while back:



Put that in an IF statment in your main loop like this:



Where the integers iTopCorner, iBottomCorner, etc are the positions of each corner on the button in pixels, and szText is the text on the button. It will return a 1 if the button is pressed. This could easily adapted to use sprites and would be easier to make.
RoseOwnage
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 14th Dec 2011 18:31
can i make it more easy? because i already got an image, with text and its done. i only need to know how you easy can press the image, without that bool createbutton?

Hi
vitinho444
14
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 14th Dec 2011 21:05 Edited at: 14th Dec 2011 21:07
I think you should use Mr Biggles's function or else use this as my first game:


mX = dbMouseX(); //Use it inside the loop so its updated
mY = dbMouseY(); //Use it inside the loop so its updated

if(mX >= 300 && mX <= 500 && mY >= 300 && mX <= 350 && dbMouseClick())
{
//Button at 300, 300, with 200 width and 50 height was pressed
}

I think its not a bad system but a function always helps

@EDIT
I remmembered that if you have a sprite for the mouse you can simply turn that code over there into:

if(dbSpriteCollision(MOUSE_SPRITE_ID, BUTTON_SPRITE_ID) && dbMouseClick())
{
//clicked button
}

and dont forget, for this to work you also need the button to be external from the background of the menu...

Your choice =D

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5

Login to post a reply

Server time is: 2024-11-19 06:42:52
Your offset time is: 2024-11-19 06:42:52