Добавил простую обработку мыши с учётом масштаба

This commit is contained in:
Иван Кузьменко 2025-09-12 03:56:44 +03:00
parent 6e63814184
commit e629d0ffa4
2 changed files with 58 additions and 0 deletions

View file

@ -47,6 +47,48 @@ function love.load()
16 * 5
)
tilemap:random(10, 10)
end
-- 0: nothing
-- 1: holding LMB
-- 2: dragging with LMB held
local mouseState = 0
local mouseStartX = 0
local mouseStartY = 0
local mouseEndX = 0
local mouseEndY = 0
function love.mousepressed(x, y, button)
if button == 1 then
if mouseState == 0 then
mouseState = 1
mouseStartX = x
mouseStartY = y
end
end
end
function love.mousemoved(x, y, dx, dy)
if mouseState == 1 then
mouseState = 2
end
-- fallthrough
if mouseState == 2 then
mouseEndX = x
mouseEndY = y
end
end
function love.mousereleased(x, y, button)
if button == 1 then
if mouseState == 1 then
-- TODO: callback
elseif mouseState == 2 then
-- TODO: callback
end
mouseState = 0
end
end
function love.update(dt)
@ -84,6 +126,12 @@ function love.draw()
drawText('Hellorld!', 160, 100)
if mouseState == 2 then
love.graphics.setColor(0, 255, 255)
love.graphics.rectangle("line", mouseStartX, mouseStartY, mouseEndX - mouseStartX, mouseEndY - mouseStartY)
love.graphics.setColor(255, 255, 255)
end
love.graphics.draw(hamsterMouse, love.mouse.getX(), love.mouse.getY())
platform.drawEnd()