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 / create simple button

Author
Message
AriEf
14
Years of Service
User Offline
Joined: 30th Nov 2009
Location: Indonesia
Posted: 22nd Jun 2010 09:35
hi all,

how to create a simple button for quit, single player, and option?

thanks.

Rank : Beginner Coder
Im Indonesian, and I cant speak english, i hope you understand
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 22nd Jun 2010 10:46
the simplest way would be:
1-create an image which will be your button (in photoshop or gimp or whatever)
2-load it (dbLoadImage)
3-show it on screen as a sprite (dbSprite(in a loop))

and if you want to take an action when the user clicks, you can either create another TRANSPARENT sprite, and keep positioning it over the mouse position, then check for collision between it and the button, or you can just check if the mouse is inside (SpriteX,SpriteY,SpriteX+SpriteWidth,SpriteY+SpriteHeight)

TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 22nd Jun 2010 13:10 Edited at: 22nd Jun 2010 14:49
The key feature in a button is the mouse-vs-area collision algo:

You can use any 2D/3D object to represent the button visually.

_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 22nd Jun 2010 14:45 Edited at: 22nd Jun 2010 14:46
I think the above has to be this:

if(mousex > buttonx && mousex < buttonx + buttonwidth && mousey > buttony && mousey < buttony + buttonheight)

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
TechLord
21
Years of Service
User Offline
Joined: 19th Dec 2002
Location: TheGameDevStore.com
Posted: 22nd Jun 2010 14:50
Thanks _Pauli_, I goofed my conversion from previous code. Fixed now.

AriEf
14
Years of Service
User Offline
Joined: 30th Nov 2009
Location: Indonesia
Posted: 26th Jun 2010 14:12
im sorry for late posting,
but i still cant understand and i didnt try my code
did you mean like this


Rank : Beginner Coder
Im Indonesian, and I cant speak english, i hope you understand
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 26th Jun 2010 14:46 Edited at: 26th Jun 2010 14:50
in the comment place, put something like this:


note that dbSpriteCollision takes two arguments, which are the IDs of the two wanted sprites, it checks collision between them, if they are colliding it returns true, otherwise false
in case you dont want a sprite over the mouse, and you want to use the actual mouse position for calculations, simply replace dbSpriteCollision with a mouse position check, for example you can write your own mouse collision function like this:


Login to post a reply

Server time is: 2024-11-19 20:44:27
Your offset time is: 2024-11-19 20:44:27