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 / Simple Buttons for newbies

Author
Message
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 21st Jun 2008 16:39 Edited at: 21st Jun 2008 16:54
Hey, Im pretty new to Dark GDK, but ive just made a couple of functions that work well for making simple game buttons (e.g. for game menus and stuff). It uses DGDK sprites to make the buttons.

* I have attached a Demo to show how it works

It is very untidy (no indents and stuff), im busy fixing it.

This is certainly not the way experts would do it, but it might be usefull to newbies. So I thought I would share it.
Any ideas would be helpful.

Just put this outside of the game funciton:



This first 3 values you can change to suite your need:

#define MaxButtons 50

- this is the max number of buttons that you can use in your
game (default is 50) - that does not mean you have to use all of them, it just tells the program how many buttons it might possibly have to run.

#define ButtonSpriteIndex 1

- The program will look for free sprites to use, this is the number from which it will start looking for free sprites. You can make this something like 1000 if you want to be sure that it does not effect your game.

#define ButtonInterval 10

- This is the timer for the buttons to guard agains repeated clicks



To make a button:



buttonID - The Button's Id
ButtonPriority - The Button's Sprite Priority
x, - The Button's X position
y, - The Button's Y position
buttonSound, - The Button's sound (make it 0 for no sound)
buttonNormal - The Button's Normal Image
buttonOver - The Button's Mouse over Image
buttonPressed - The Button's pressed Image


Important:
In your game loop you have to put RunButtons();

Other functions:

IsButtonDown(int buttonID)
- Returns 1 if the button is pressed and 0 if not.
e.g.


IsMouseOverButton(int buttonID)
- Returns 1 if the mouse is over the button and 0 if not.
e.g.



ShowButton(int buttonID)
- Shows a button if it is hidden

HideButton(int buttonID)
- Hides a button, hidden buttons are inactive


Other stuff:

Button[buttonID].exists - will be false if the button does not exists and true if it does

Button[buttonID].visible - will be false if the button is hidden and true if it is visible

Button[buttonID].sprite - use this to refer to a button's sprite ID

________________

I am still new to C++ but I hope this is useful to someone

See demo attached

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-09-30 01:39:07
Your offset time is: 2024-09-30 01:39:07