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 Professional Discussion / Need help with an interactable image

Author
Message
Explosm69
15
Years of Service
User Offline
Joined: 22nd Jul 2010
Location:
Posted: 15th Dec 2010 07:45
I'm doing a menu type of thing right now, and it requires the use of clicking the image in order to advance to the next set of image, like a menu of course.

Here is my code, it isn't the actual thing, but this help could help me with making the menu
P.S. I made and used the image for FPSCreator, i just had to find something that will suit the code


Can you also make it print "Well Done" or something once the image is clicked? just to confirm that it is clicked

Cyanide & Happiness 4 Ever
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Dec 2010 08:41
I would suggest splitting the button into it's own image(s). So you'd have a backdrop image, plus a button image, and if you like, a mouse over image and a clicked image for the button. Then something like this:

load image "back.png",1,1
load image "button1.png",2,1
load image "button1_mouseover.png",3,1
load image "button1_clicked.png",4,1

Then a little menu routine, let's assume your button is 256x128 in size:

bx=300 : by=200
done=0
while done<>1

mx=mousex()
my=mousey()
mb=mouseclick()

but=2
if mx>bx and my>by and mx<(bx+256) and my<(by+128)
but=3
if mb=1 then but=4 : done=-1
else
if done=-1 then done=1 else done=0
endif

paste image 1,0,0
paste image but,bx,by,1

sync
endwhile


So... that will display image 1 and paste the relevant button image, depending on if the mouse is inside the button area and if it's clicked. When you click the button, DONE is set to -1, then when you release, it will set DONE to 1 and exit the loop, but only if the mouse is still inside the button area.
Personally, I would make the button display a function, where you pass the coordinates, and images to use, then have it return a 1 if the button is clicked. It depends on how many buttons you need etc.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-21 13:38:43
Your offset time is: 2026-07-21 13:38:43