Draw Text and detect click on it
Screen.drawText - i know, but how to detect click on it ?
Screen.drawText - i know, but how to detect click on it ?
You can add this library in to your game and use button function https://microstudio.dev/i/gilles/imgui/
Without a library, you need some way to measure the size of your text. You can use something like:
myText="Hello there"
myWidth=screen.textWidth( myText, 20 )
myHeight=20 // as far as I know, there is no screen.textHeight function
myTextX=0
myTextY=0
draw your text normally in your draw function: screen.drawText(myText,0,0,20,"#fff")
and in your update function:
if mouse.pressed then
if mouse.x > myTextX-myWidth/2 and mouse.x<myTextX + myWidth/2 and mouse.y>myTextY-myheight/2 and mouse.y<myTextY + myHeight/2 then
// mouse hit!
end
end
This calculation assumes that your drawAnchor is set to 0,0, which is the default
Keep in mind that this is totally untested!