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.

DarkBASIC Professional Discussion / Big general question

Author
Message
Visvalor
15
Years of Service
User Offline
Joined: 29th Dec 2010
Location:
Posted: 29th Dec 2010 17:36
Hiya. I'm looking to make an interesting game and would like some suggestions on how to do this (and a little explanation )

First things first, I'm trying to figure out how to make a button. (Baby steps.)

I've looked through a few tutorials and found a way to draw an image and set bounds and etc etc. However that's a lot of work for each and every button (The game is mostly buttons) and I want to do this with a bmp image.

I'm looking to paste an image, define the bounds, onMouseOver (or whatever the equiv effect here is) to change to highlight, Mouseclick to change the bmp to a pushed down version and then have the effect of the button.

Any links to tutorials that tell me how to;

Paste an image
Change effect of the image when hovering
Change the image when pressed
Create effect when pressed (For now it can just be print, I'm still learning)

Overall, if you're curious as to what the game is going to be in the long run. It's a tabletop P&P assistant program.

"Tis better to die on your feet, than live on your knees" - Emilio Zapato
Visvalor
15
Years of Service
User Offline
Joined: 29th Dec 2010
Location:
Posted: 29th Dec 2010 18:37


So far this is what I have

"Tis better to die on your feet, than live on your knees" - Emilio Zapato
Blobby 101
20
Years of Service
User Offline
Joined: 17th Jun 2006
Location: England, UK
Posted: 29th Dec 2010 19:07
Welcome to TGC Now i'll say it before someone else does, You should start getting used to indenting your code well. In that snippet your indenting is very erratic. If I were you I'd indent in loops and if statements. This lets you easily tell different parts of code apart.

As for the code itself. You don't want to do your loading in a loop. If you do it will run through once and then crash. Instead, load your files before the loop and then only put actions you want repeated indefinitely inside the loop.

I don't know what you want the Xpos and Ypos variables for but I assume you want them set like that once (as there's no real point setting them to a fixed value over and over again, so that should also go outside of the loop.
Here, I fixed up your code a bit:



I left paste image inside the loop as i assume you want that for resetting the button when you're not clicking on it. If you want it like a toggle button then you'll need to set a variable when the button is clicked then use that to determine which state the button should be in.

dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 29th Dec 2010 19:28
Can you explain us about game, so we can help you more, maybe draw some image in paint or something. Anyway, checking the mousex, and mousey would do the job. If it's too hard for you to check every image, then make a function, you can find that function that someone reply to my thread, I just finialize it. I think you can also find that image in TGC snippet page.

Then you can just call function when ever you need, it will fast your process of coding, and will use much less codes.

[Its just me - and my opinion]
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 29th Dec 2010 19:55 Edited at: 29th Dec 2010 19:59
Hi Visvalor,

The best way to implement buttons, is by using a function. A function can take parameters, and can return one value (all optional). For example:


can be called using


Any variables that are used within a function, are not visible to code outside of that function (unless it is made global or an array - not that important for now). In our FuncSum() function, C# is such a variable.

In your case, the function would need 4 parameters: X, Y, Img and ImgHover. In pseudo code, your function would look like this:



I hope it helped,
Sven B

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 29th Dec 2010 20:56
Quote: "However that's a lot of work for each and every button (The game is mostly buttons) and I want to do this with a bmp image. "

keep thinking like this! Usually if you have a bunch of repetitive, similar code, then you should probably be using functions, for loops, while loops, arrays, and/or a different method.
Those are all things you'll get familiar with by going through tutorials though.

Visvalor
15
Years of Service
User Offline
Joined: 29th Dec 2010
Location:
Posted: 30th Dec 2010 00:12
Ok to explain the game (As dn5 asked).

The game is a D&D style (Dungeons and Dragons) roleplay PnP (Pen and Paper) assistant. It will basically contain character sheet information (spells, equipment, skills etc) and do all the math automatically.

It will also hold all the monster/opponent information and run the battle scripts.

It will hold images such as maps and whatnot and display them as needed.

It will need to connect to some sort of database (SQL?) to retrieve game information such as items, monsters, places, etc.

It's going to be a laptop oriented multiplayer game with no chat function (As the game is played IRL and in person) so it will need to communicate between different computers, but no chat box is required.

Lots of things it'll do and I'm still trying to figure out how to make a button

Thanks for all the help so far, and now I'm wondering how once changes "screens"

For example, you have a button on page 1 and you click it to create a character sheet. This should bring you to page 2 where you can make the sheet.... how does all of this even work? My only experience before has been with php/css/html and it's quite different heh

"Tis better to die on your feet, than live on your knees" - Emilio Zapato
enderleit
19
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 30th Dec 2010 01:22
I made a quick example of how this could be done to accommodate any number of buttons. I have commented the code, but it might be a tad to "advanced" for you.

Just let me know if you have any questions.



Enjoy!

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 30th Dec 2010 02:16
@enderleit - nice piece of code, something I can learn with.
Thanks!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Dec 2010 17:17
Agreed.

With minor changes it works with 3D objects on screen as well.

Login to post a reply

Server time is: 2026-07-18 09:01:27
Your offset time is: 2026-07-18 09:01:27