title menu

Blitz3D Forums/Blitz3D Beginners Area/title menu

Agamer(Posted 2003) [#1]
how would i go around creating a title menu with some images as the buttons so how would i go abiut it


Warren(Posted 2003) [#2]
Write code to display the buttons and handle the user clicking on them ... ?


Agamer(Posted 2003) [#3]
yeh how do i do the handling bit


CS_TBL(Posted 2003) [#4]
; did this here in the reply-box, w/o testing, hope it works :)

try this:

;create a window, and 2 canvases named Menu1 and Menu2

repeat

waitevent()

if eventid()=$201 ; canvas click

if eventdata()=1 ; LMB
select eventsource()
case Menu1
blah() ; asuming you have a blah function
case Menu2
blah() ; asuming you have a blah function
end select
endif
endif

if eventid()=$803 quit=true

until quit
end



; btw... 5 terrabyte HD for what? :) That's *5* TB!


Agamer(Posted 2003) [#5]
it dosen't like anything in that pievce of code a what are blah functions


jhocking(Posted 2003) [#6]
The blah functions are what happens when you click the buttons. The thing about that piece of code is that it is for BlitzPlus only since it uses GUI functions. Plus it will look like a Windows window, whereas for most games you want your own images for the buttons.

Basically you use the drawing commands like DrawImage to draw your buttons on the screen and then check MouseHit() every frame (with a statement like "if MouseHit(1) Then...) to see if the user has clicked the mouse. If so check MouseX() and MouseY() to see where the mouse is located; if it is located over a button react to the click.


Rob Farley(Posted 2003) [#7]
I would suggest creating a little function like (totally untested and off the top of my head!):
function clickbox(image,x,y)
     drawimage image,x,y
     xw=imagewidth(image)
     yw=imageheight(image)
     if mousedown(1) and mousex()>=x and mousex()<=x+xw and mousey()>=y and mousey()<=y+yw then return true else return false
     end function
This way you'd then call:
if clickbox(start_game_image,20,20) then start_game
To take it a step further...
Function clickbox(off_image,on_image,x,y)
     xw=ImageWidth(on_image)
     yw=ImageHeight(on_image)
     If MouseX()>=x And MouseX()<=x+xw And MouseY()>=y And MouseY()<=y+yw
          DrawImage on_image,x,y
          If MouseDown(1) Then Return True
          Else
          DrawImage off_image,x,y
          Return False
          EndIf
End Function
This will then light up the image (on_image) if you run the mouse over it, and return true when it's clicked, otherwise it will display off_image and return false.

This sort of thing just makes drawing screens really easy and quick as you're drawing and checking all at the same time.

Of course all this can be optimised a lot, as I said this was all off the top of my head, you'd probably want drawblock instead of drawimage for example... anyway, I hope this helps.


Rob Farley(Posted 2003) [#8]
Okay... just wrote a bit of code that works!

Graphics 640,480,32,2

; make some graphics
Dim button(9,1)
Data "Start","Stop","Rewind","Fast Forward","Pause","Eject","Save","Load","Help","Blitz!"
For n=0 To 9
Read t$
button(n,0)=CreateImage(100,20)
button(n,1)=CreateImage(100,20)
Color 0,0,200
Rect 0,0,100,20,True
Color 160,160,160
Text 50,10,t,True,True
GrabImage button(n,0),0,0
Color 255,255,255
Text 50,10,t,True,True
Rect 0,0,100,20,False
GrabImage button(n,1),0,0
Next

SetBuffer BackBuffer()

Repeat

; draw the screen
For n=0 To 9
If clickbox(button(n,0),button(n,1),50+(n*30),20+(n*30)) Then Text 0,0,"Button "+n+" Clicked!"
Next

Flip
Cls
Until KeyHit(1)
End


Function clickbox(off_image,on_image,x,y)
     xw=ImageWidth(on_image)
     yw=ImageHeight(on_image)
     If MouseX()>=x And MouseX()<=x+xw And MouseY()>=y And MouseY()<=y+yw
          DrawImage on_image,x,y
          If MouseDown(1) Then Return True
          Else
          DrawImage off_image,x,y
          Return False
          EndIf
End Function



cyberseth(Posted 2003) [#9]
Don't forget that x+xw is one pixel more than the actual width of a rect/image. So for totally accurate checking:

If MouseX()>=x And MouseX()<x+w and MouseY()>=y and MouseY()<y+yw

Or, in shorthand:

If RectsOverlap( MouseX(), MouseY(), 1, 1, x, y, xw, yw )

Or:

If ImageRectOverlap( off_image, x, y, MouseX(), MouseY(), 1, 1 )


Rob Farley(Posted 2003) [#10]
This demonstrates how good this forum is...

I've been using blitz3D since you could buy it and I've never used either recsoverlap or imagerectoverlap... what damn handy commands! Cheers Seth!


Agamer(Posted 2003) [#11]
thanks for all the info this is so going to help