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 Discussion / how do u make a menu screen

Author
Message
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 25th Feb 2004 00:16
can somone help i need to make a menu screen where u click on play mission and it plays my game or click on training and you train pls help

*=========**=================*
*.-steve-.**.-slipknot rule-.*
*=========**=================*
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 25th Feb 2004 01:03
I'm not going to write the code for you, as you need to learn how to do it yourself, but I will explain how to do it.


Firstly, you need to draw your menu...
You can either do this in a paint program and then load it into DB as an image, or you can just make one using the Box and Line commands in DB.


Next, you need to know where the buttons are on the screen...
The way you do this will depend on how you set up the menu visually in step 1.
Either way, you will create an array to store the positions of the buttons for ease of access. The array will be set up as;
Dim buttons(maxbuttons,4)
Where maxbuttons is the amount of buttons you have in the menu, and 1 -> 4 are the left, top, right, and bottom positions of the buttons respectively. ( We will use the 0 index later on as a check )

If you created the menu in a paint program, just open it up, move the cursor to the left side of the first button, and look at what the pixel position is, and this then becomes the value of buttons(1,1) then look at the top position, and this becomes the valeu of butons(1,2) and so on.

If you use this method of creation of the menu, you mut take into account the position you will put the image on-screen. Ie, if you load the image in, and position it at 20,100 then all of the left and right positions will be out by -20 pixels, and the top and bottom ones will be out by -100 pixels. To remidy this, simply adjust all the array values acordingly.

If you create the menu in DB using Box's etc, then the left, top, right, and bottom positions are simply the positions you used to create the box's in the first place.


Next, you need to do a Mouse Position check...
To do this, you simply get the mouse position, using MouseX() and MouseY() and check that against the array values for each button.

If the mouse is over the button, then set the value of buttons(butnum,0) to 1. Then you can use this check when checking if the mouse has been clicked.
If the mouse isn't over the button, and the value of buttons(butnum,0) = 1 Then set it back to 0.


Finally, you have to check if the mouse is clicked...
Use the MouseClick() command to check this.
Then, if the mouse has been clicked, use a For...Next loop to loop through the array values checking buttons(butnum,0). If it is equal to 1, then the mouse is over the button, and the button has been clicked, so you act accordingly.


Hopefully this will get you off to a start, and you can learn some more code in the process.


Hope I Helped...
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Debbie McDowell
21
Years of Service
User Offline
Joined: 14th Oct 2003
Location: Florida
Posted: 25th Feb 2004 08:01 Edited at: 25th Feb 2004 08:09
Look at exam 13.dba
look for a browser.bmp image file

you will find both in this directory path
c:program files-dark basic software-dark basic-help-examples-basic3d

This will show and tell exactly how it is done.
Probably most important for you would be the bottom buttons and
the related code if you wish to keep things basic.

Sort thru it untill you put together what works for you.
It took time and effort to make such examples for users to learn from and
spending time first with each example, sometimes even basic as it seems
and you will find many things which will help you at one time or another.

I suggest all DB beginners start by poking around in the DB files, take some of
the sample demos and change a few things to see what happens.
Thats what they are there for.

It is of coarse important that you first make a copy of the
file you are going to modify in case you change something and cant remember how to undo it.

For what you can't figure out there are very considerate and helpful people
in the forums who will gladly add to your effort but first they want to see that you
have at least tried on your own.

They could show you this stuff every day and still you will not really have learned
why it's done a certain way and ultimately how it's done.
If doing this they have not really helped you but have actually done it for you.
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 25th Feb 2004 22:11
hi

while using arrays is a very good way to make buttons for a menu, i find an easier way is to load your pictures of buttons as sprites and position them where you want.

then make a small sprite the size of your mouse pointer, hide it, then make it have the same co-ordinates as the mouse point at all times meaning the sprite command has to be in the main loop

now just check to see if the mouse has been clicked when the hidden sprite is colliding against any buttons

Note i would not use this method if your program requires maximum performance when menu's are displayed or if the buttons on your menu are very large

hope i helped
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Feb 2004 03:05
That is also a good method, but, as you said, If you have multiple sprites on screen at one time, and you start checking for collision and moving the sprite with the mouse, you may lose many FPS...

irish fool, you have enough information now to construct a pretty good menu in a number of different ways... Good luck.

Hope I Helped...
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 26th Feb 2004 16:24
Yeah, but if you're going to cut corners like that all the time, then how will you learn the code...?

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
DARKGuy
21
Years of Service
User Offline
Joined: 28th Nov 2003
Location:
Posted: 26th Feb 2004 18:03
yeah, Jess is right, better learn for yourself rather than using that sort of programs...also if you make your own menu you'll have FULL control of the interaction, graphics, sound and all...

Current Projects: F-16 Gold Wings
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 1st Mar 2004 21:42 Edited at: 1st Mar 2004 21:44
jess i need help again sorry ive got the bitmap up on screen and put dim buttons(maxbuttons,4) or somthing like that but ime sorry i dident get what to do next like the value of buttons 1,1 and 2,2 i dont get it could you help pls heres my code just to show what ive done
do
load bitmap "menuscreen.bmp"
set current bitmap 0
Dim buttons(maxbuttons,4)
loop

*=========**=================*
*.-steve-.**.-slipknot rule-.*
*=========**=================*
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 2nd Mar 2004 09:29
Sorry mate, I am not going to jump when you say...

I'm not going to write your code for you, but, I am happy to explain the concept behind it again... If you quote the part that you are unsure about, I'll explain it better.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 2nd Mar 2004 11:50
Jessticular, I think he means he doesnt understand what to store in the array. You must store the pixel co-ordinate of each corner of each button. In for example, (1,1) you store the top left co-ordinate, (1,2) must be the top right, (1,3) the bottom left and (1,4) the bottom right.

P.S. That code you posted is VERY wrong. Your loading the bitmap and declaring the buttons array once every single loop, effectively duplicating it over and over until the program exits. This sort of code should only be done before the loop.

Currently thinking of a new company name
Sticking to a project idea for once
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 2nd Mar 2004 22:27
thanks moonshine and jess thats what i meant i dident want you to write the code for me sorry if i gave the wrong impression but theres still one thing how do i store them do i put value
(1,1 = 12,34) or somthing i dont know

*=========**=================*
*.-steve-.**.-slipknot rule-.*
*=========**=================*
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 3rd Mar 2004 01:04
Alrighty, thanks MoonShine

irish fool...

butons(1,1) = left most pixel of the button
butons(1,2) = top most pixel of the button
butons(1,3) = right most pixel of the button
butons(1,4) = bottom most pixel of the button.

eg.
butons(1,1) = 20
butons(1,2) = 20
butons(1,3) = 100
butons(1,4) = 80

That would be for a button that it's top left coords would be 20,20
And the bottom right coords would be 100,80

Hope That Cleared it up...
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 3rd Mar 2004 20:04 Edited at: 3rd Mar 2004 20:07
thanks sorry to be a bother but now its sayin array accessed out of bounds have i done it wrong this is what i put
do
load bitmap "menuscreen.bmp"
set current bitmap 0
Dim butons(maxbutons,4)
butons(1,1) = 36
butons(1,2) = 32
butons(1,3) = 201
butons(1,4) = 58
loop

*=========**=================*
*.-steve-.**.-slipknot rule-.*
*=========**=================*
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 3rd Mar 2004 20:39
Youve not told it what the integer value 'maxbutons' is worth. And none of that code should be in a loop. In fact, theres no reason whatsoever to have a loop here at this time, so remove do, and loop.

Your error is because it doesnt know how big to make your array, so insert a maxbutons= then put the number of buttons you have, in this case probably just the one.

Sorry to write the code for you, but believe me i didnt want to. Thats the only way youd understand.

Just post if you have any more problems.

Currently thinking of a new company name
Sticking to a project idea for once
steve c
21
Years of Service
User Offline
Joined: 30th Jan 2004
Location: united kingdom
Posted: 5th Mar 2004 18:37
it still sais it aray accessed out of bounds this is what i put
load bitmap "menuscreen.bmp"
set current bitmap 0
Dim butons(maxbutons,4)
maxbutons=1
butons(1,1)=36
butons(1,2)=32
butons(1,3)=201
butons(1,4)=58

*=========**=================*
*.-steve-.**.-slipknot rule-.*
*=========**=================*
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 5th Mar 2004 21:45
btw maxbutons=1 has to be put before the array to make it work

so your code would be

load bitmap "menuscreen.bmp"
set current bitmap 0
maxbutons=1
Dim butons(maxbutons,4)
butons(1,1)=36
butons(1,2)=32
butons(1,3)=201
butons(1,4)=58


can i ask u a question, and dont take any offense to this but have u even bothered reading tutorials,playing around with tutorial or example code,or even tried to make small little projects/games?

because it seems you dont know the basics yet like your computer will read code from the top of the screen to the bottom, thats why maxbutons=1 has to be placed before the array, cos the computer hasnt got a value for maxbutons yet so it does not make the array, so giving maxbutons a value after you've tried to make the array will do nothing

the best advice i can give you is learn the basics first from tutorials etc and dont always ask for help straight away when u have problem try to solve it yourself- then if your really stuck then ask

please dont be offended by this and i hoped i helped u

Login to post a reply

Server time is: 2025-05-23 14:43:05
Your offset time is: 2025-05-23 14:43:05