Here is my special code that i use for menus and gui's
SetDisplayAspect(0.66)
`This is portrait mode, select protrait mode when you make a new project
button1img = LoadImage("button1.png")
button2img = LoadImage("button2.png")
quitbutt = CreateSprite(button1img)
SetSpriteSize(quitbutt,20,10)
SetSpritePosition(quitbutt,40,45)
`Main loop
do
if GetPointerState()=1 and quitdown=0
if GetSpriteHitTest(quitbutt,GetPointerX(),GetPointerY())
quitdown=1
SetSpriteImage(qyutbutt,button2img)
`If you have your finger down and it is over quit, then set quitdown to 1
endif
endif
if GetPointerReleased()=1 and quitdown=1
end
`the user has just released their finger while it is over quit
endif
if GetPointerState()=0
quitdown=0
SetSpriteImage(quitbutt,button1img)
endif
loop
I'm not sure if this code works, I'm just writing it from memory, I hope you can see where I'm going with it. It isn't hard to add more buttons.
SetDisplayAspect(0.66)
`This is portrait mode, select protrait mode when you make a new project
quit1img = LoadImage("quit1.png")
quit2img = LoadImage("quit2.png")
start1img = LoadImage("start1.png")
start2img = LoadImage("start2.png")
quitbutt = CreateSprite(quit1)
SetSpriteSize(quitbutt,20,10)
SetSpritePosition(quitbutt,40,45)
startbutt= CreateSprite(start1)
SetSpriteSize(startbutt,20,10)
SetSpritePosition(startbutt,40,65)
`Main loop
do
state = GetPointerState()
released = GetPointerReleased()
x = GetPointerX()
y = GetPointerY()
`I have used variables so I don't have to call these function more than once (to save proccesing speed)
if state=1
if GetSpriteHitTest(quitbutt,x,y) and quitdown=0
quitdown=1
SetSpriteImage(quitbutt,quit2img)
`If you have your finger down and it is over quit, then set quitdown to 1
endif
if GetSpriteHitTest(startbutt,x,y) and startdown=0
startdown=1
SetSpriteImage(startbutt,start2img)
endif
endif
if released=1
if quitdown=1 then end
if startdown=1 then gosub game
`We will pretend that their is a label named game that has the gameplay: Note that this is a terrible coding style, but I coulden't be bothered to write all of the other code
if state=0
quitdown=0
SetSpriteImage(quitbutt,quit1img)
startdown=0
SetSpriteImage(startbutt,start1img)
endif
loop
It isn't exactly what you want, the buttons won't activate when you move you finger away from them, but it's better than using virtualbuttons. I'll try to get around to uploading an example of this soon. The problem with virtualbuttons is that if you tap one, then move your finger off it, and release your finger, it will still press it.
I've attached an example of this gui system. Click the red download button at the bottom right of this post.
There are 10 types of people, those who understand binary and those who don't
