Page 1 of 1

How to scale like this and keep my love.mousepressed to work.HELP

Posted: Thu Feb 06, 2020 8:46 pm
by Donut-Dezz
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


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

Re: How to scale like this and keep my love.mousepressed to work.HELP

Posted: Fri Feb 07, 2020 12:03 pm
by sleepy
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.

Code: Select all

local dsx = dx * (window_width /scalex)
Like that for all the other values.

Re: How to scale like this and keep my love.mousepressed to work.HELP

Posted: Fri Feb 07, 2020 2:08 pm
by Donut-Dezz
can you show me an example bro?

Re: How to scale like this and keep my love.mousepressed to work.HELP

Posted: Fri Feb 07, 2020 2:30 pm
by sleepy

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 
Depends on what your goal is you might need to structure your code accordingly.

Re: How to scale like this and keep my love.mousepressed to work.HELP

Posted: Fri Feb 14, 2020 1:22 pm
by Donut-Dezz
THANKS SLEEPY. You answer my question. im just now seeing this but thanks bro this worked.