how to switch screens?
after i added the backgroundsprite and button sprites (start, tutorial). im trying to code the tutorial button but i don't how to code its function and go to the tutorial screensT^T
after i added the backgroundsprite and button sprites (start, tutorial). im trying to code the tutorial button but i don't how to code its function and go to the tutorial screensT^T
Please post your project so I can see the code and help you do what you need. Also please link your project.
I think I know what your saying. What you should do is make a variable with what screen your on (eg: backdrop = "menu") something simple like that. Now once you have that working you can use a function like this
clicking = function(x,y,h,w)
return touch.touching and
mouse.x > x - w/2 and
mouse.x < x + w/2 and
mouse.y > y - h/2 and
mouse.y < y + h/2 end
To check if your clicking a certain spot. So like
if clicking(0,0,20,20) then
backdrop = "tutorial"
end
Now that you did that you have to in the draw function put all the drawing of the tutorial in an if function like this
if backdrop == "tutorial" then
//draw backdrop
end
This hopefully should help with your problem!
(there are probably better clicking functions out there)
here's my approach at calculating the click if mouse.pressed then if mouse.x < this.xpos+(this.width/2) and mouse.x > this.xpos+(this.width/-2) and mouse.y < this.ypos+(this.height/2) and mouse.y > this.ypos+(this.height/-2) then return 1 end end
Both do the same thing.
huhu thank you all for replying. im still having a hard time coding our game for our project, iz someone willing to help me? T^T
Here’s the code I have for buttons: button = function(x,y,w,h,textSize,text) isHover = abs(mouse.x-x)<w/2 and abs(mouse.y-y)<h/2 isPressed = mouse.press or touch.press
if (isHover and isPressed) then screen.fillRoundRect(x,y,w,h,2,"#D2D2D2") screen.drawText(text,x,y,textSize,"#000000") return true else screen.fillRoundRect(x,y,w,h,2,"#808080") screen.drawText(text,x,y,textSize,"#000000") return false end end sbutton = function(x,y,w,h,sprite) isHover = abs(mouse.x-x)<w/2 and abs(mouse.y-y)<h/2 isPressed = mouse.press or touch.press
if (isHover and isPressed) then screen.drawSprite(sprite,x,y,w,h) return true else screen.drawSprite(sprite,x,y,w,h) return false end end
Normal button has text while sbutton is a sprite