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

Show off your games, demos and other (playable) creations.
Post Reply
Donut-Dezz
Prole
Posts: 25
Joined: Sat Aug 03, 2019 11:56 am

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

Post 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
User avatar
sleepy
Prole
Posts: 5
Joined: Tue May 28, 2019 9:45 am

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

Post 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.
Donut-Dezz
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

Post by Donut-Dezz »

can you show me an example bro?
User avatar
sleepy
Prole
Posts: 5
Joined: Tue May 28, 2019 9:45 am

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

Post 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.
Donut-Dezz
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

Post by Donut-Dezz »

THANKS SLEEPY. You answer my question. im just now seeing this but thanks bro this worked.
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests