There can be several reasons...
You should add some DEBUG lines for getting more information what happens (and what not...). This is a very important part of programming. "A lot of DEBUG lines" will save your time:
I show you what I mean:
Function MainMenu() ; Main Menu
PRINT "FUNCTION MAINMENU"
s_btnx = 420
s_btny = 600
start_btn = LoadImage("Media\Gui\btn_start.png")
DrawImage start_btn,s_btnx, s_btny
DrawImage MainMenubg,0,0
s_btnw =ImageWidth(start_btn)
s_btnh =ImageHeight(start_btn)
If ( MouseX() > s_btnx ) AND ( MouseX() < (s_btnx+s_btnw) )
If ( MouseY() > s_btny ) AND ( MouseY() < (s_btny+s_btnh) )
PRINT "MOUSE INSIDE"
over = True
Endif
Endif
PRINT "OVER=" + over
If MouseDown(1) And over = True
PRINT "MOUSE CLICK"
End
EndIf
PRINT "END FUNCTION"
Flip
End Function
Keep this PRINT lines in your code until the development has finished. You can comment them out, if temporary not needed, but keep them in the code...
When you now start your code, you can watch, what happens.
There are a lot of additional mistakes in your code:
- you load the image again and again each frame. The images should be loaded once before the function is called:
Global start_btn = LoadImage("Media\Gui\btn_start.png")
Function MainMenu()
PRINT "FUNCTION MAINMENU"
s_btnx = 420
s_btny = 600
DrawImage start_btn,s_btnx, s_btny
- You should define SUPERSTRICT at the top of your code to take care about the quality of the variable definitions you use. With this line every variable has to be defined GLOBAL or LOCAL
-You should first check, whether MouseDown() is true. Then check ,where the mouse is:
If MouseDown(1) = True
If ( MouseX() > s_btnx ) AND ( MouseX() < (s_btnx+s_btnw) )
If ( MouseY() > s_btny ) AND ( MouseY() < (s_btny+s_btnh) )
PRINT "MOUSE CLICK"
End
Endif
Endif
Endif
|