Scaled my game but the mouse coordinates have a problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
InfamousMakundo
Prole
Posts: 3
Joined: Sun Aug 28, 2016 3:54 am

Scaled my game but the mouse coordinates have a problem

Post by InfamousMakundo »

So I scaled my game graphics, everything I drew so that the game could fit in all resolutions based on an aspect ration. As a result of this the game could fit in all devices, however the problem is that i used a button code that works if the area inside of the buttons are pressed. After I scaled the graphics the buttons are scaled to a smaller or bigger size based on the resolution but the size and location of area of the inside of the button that triggers it stays the same.

How can I get the coordinates of the button area to "scale" as well.

This is my button code

Code: Select all

function love.mousepressed(mx,my,button)
	bax = 15
	bay = 15
	bx = 615
	by = 415
	x = 500
	y = 250
    mx = love.mouse.getX()
	my = love.mouse.getY()
  if button == 1
   and mx >= x and mx < x + play:getWidth()
   and my >= y and my < y + play:getHeight() and click == false then
     click = true --stuff to do when your image has been clicked
	else if button == 1 
	and mx >= bx and mx < bx + brexit:getWidth()
	and my >= by and my < by + brexit: getHeight() and click == false then
	love.event.quit()
	else if button == 1
	and mx >= bax and mx < bax + back:getWidth()
	and my >= bay and my < bay + back:getHeight() and click == true then
	click = false
	start = true
	
      end
	end
end
end
Yes named my exit button "brexit" don't judge :awesome:
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Scaled my game but the mouse coordinates have a problem

Post by pgimeno »

Easiest way is probably to apply the inverse transformation to the mouse position prior to comparing. Subtract the origin and divide by the scale.

For example, if the scale is sx, sy and the origin is ox, oy:

Code: Select all

mx = (love.mouse.getX() - ox) / sx
my = (love.mouse.getY() - oy) / sy
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest