state = "menu"
start_button = love.graphics.newImage("start.png")
dx = 228
dy = 398
image_height = start_button:getHeight()
image_width = start_button:getWidth()
scalex = 795
scaley = 720
window_width = love.graphics.getWidth()
window_height = love.graphics.getHeight()
function love.load()
end
function love.draw()
love.graphics.scale(window_width /scalex,window_height / scaley)
if state =="play" then
love.graphics.print("The Game Has Started",200,200)
end
if state =="menu" then
love.graphics.draw(start_button,dx,dy)
end
end
function love.mousepressed(x,y,button)
if x > dx and x < dx + image_width and y > dy and y < dy + image_height then
state = "play"
end
end
How to scale like this and keep my love.mousepressed to work.HELP
-
- Prole
- Posts: 25
- Joined: Sat Aug 03, 2019 11:56 am
How to scale like this and keep my love.mousepressed to work.HELP
How to scale like this and keep my love.mousepressed to work. when i click on the start(is an image button) button it dont work.but when i remove the love.graphics.scale() it works. but i want to keep the love.graphics.scale(). it works great on mobile
Re: How to scale like this and keep my love.mousepressed to work.HELP
When doing a scaling operation your coordinates and dimensions of the input image scale as well. In your case the point in rectangle calculation is wrong, because you scaled dx, dy and the image dimensions by using love.graphics.scale.
In order to obtain the correct values you would need to scale dx, dy and the dimensions, too.
Like that for all the other values.
In order to obtain the correct values you would need to scale dx, dy and the dimensions, too.
Code: Select all
local dsx = dx * (window_width /scalex)
-
- Prole
- Posts: 25
- Joined: Sat Aug 03, 2019 11:56 am
Re: How to scale like this and keep my love.mousepressed to work.HELP
can you show me an example bro?
Re: How to scale like this and keep my love.mousepressed to work.HELP
Code: Select all
function love.mousepressed(x,y,button)
--getting the scale factor
local sx = window_width /scalex
local sy = window_height / scaley
--corrected translation according to scale
local dsx = dx * sx
local dsy = dy * sy
--new image boundaries
local iw = image_width * sx
local ih = image_height * sy
if x > dsx and x < dsx + iw and y > dsy and y < dsy + ih then
state = "play"
end
end
-
- Prole
- Posts: 25
- Joined: Sat Aug 03, 2019 11:56 am
Re: How to scale like this and keep my love.mousepressed to work.HELP
THANKS SLEEPY. You answer my question. im just now seeing this but thanks bro this worked.
Who is online
Users browsing this forum: Bing [Bot] and 0 guests