Clickable images
Blitz3D Forums/Blitz3D Beginners Area/Clickable images
| ||
I have a loop with 2 RectsOverlap commands each checking if a image has been clicked. The only problem is that only the first RectsOverlap check in the loop is checked and the other is ignored. How could I code it so they both work.startmenu=LoadImage("start.png") startbutton=LoadImage("startbutton.png") exitbutton=LoadImage("exitbutton.png") While start=0 DrawImage startmenu,0,0 DrawImage startbutton,100,100 DrawImage exitbutton,200,200 If MouseHit(1) Then If RectsOverlap( MouseX(),MouseY(),1,1,200,200,ImageWidth(exitbutton),ImageHeight(exitbutton)) Then DebugLog"exit" End End If End If If MouseHit(1) Then If RectsOverlap( MouseX(),MouseY(),1,1,100,100,ImageWidth(startbutton),ImageHeight(startbutton)) Then DebugLog"start" start=1 End If End If Flip Wend |
| ||
Stick 'em both inside the same If MouseHit... block. MouseHit, like KeyHit, clears the value so that it returns false next time it is called. If the mouse was clicked, the first block will pick it up and clear it so that the second never sees anything. |
| ||
If you absolutely have to do multiple checks, it can help you get clearer code if you store the mouse hit state for the current frame\loop cycle in an integer variable. You can use MouseDown's instead of MouseHit's as they allow you to keep a button pushed even if the mouse gets dragged outside the button (standard Windows GUI behavior, try it on any button). Then anytime you need to know the mouse state, you read the value in that variable: ;Pseudo. Global currentButton.Buttons ;Reference to the currently pushed-down button. Function checkButtons() Local mousePressed% = MouseDown(1) If mousePressed Then If currentButton = Null Then ;If no button is selected (else no need to check everyone). For b.Buttons = Each Buttons ;You could do well with a 'mouseOver()' function to check ;some 'Buttons' instance mouse-over state, returning True or False. If mouseOver(b) Then ;Set a flag to draw the button with its pushed-down graphic. b\state = 1 ;Pushed Else b\state = 0 EndIf currentButton = b ;Store a reference to the currently pushed-down button. Next EndIf Else If currentButton <> Null And mouseOver(currentButton) Then ;Activate whatever the button's for. EndIf currentButton = Null EndIf End Function ;[...] ;Draw the buttons in some other function exclusively purposed for rendering. Every button will have a '\state' field that you can query to draw an appropriate 'normal' or 'pushed-down' graphic.Can't get clearer than that! =) EDIT: Well the above did add another degree of complexity... EDIT2: My english sucks today. Last edited 2012 |
| ||
Ok, i got the buttons to work but I have another problem. Is there a way to display the mouse in full screen? |
| ||
Not the system mouse, no. You'll have to draw an image at the mouse coordinates. |
| ||
Yeah, Blitz3D's fullscreen is literally fullscreen so the system mouse is hidden. You can probably cheat by creating a graphics window that's the size of the desktop and removing the title bar with API commands. Graphics3D 1280,768,0,2 ;Graphic window the size of the desktop. ;Insert userlibbed, API commands to remove the window's title bar and borders. Last edited 2012 |