-
Notifications
You must be signed in to change notification settings - Fork 0
resolution.lua
resolution.lua helps you to easily handle your game's resolution. It also handles love.mouse and love.touch events.
local resolution = require "grove.resolution"
local config = {
width = 640,
height = 480,
aspectRatio = true,
centered = true,
clampMouse = true,
clip = true,
replace = {}
}
function love.load()
resolution.init(config)
end
function love.keypressed(key)
if key == "space"
-- Changes are updated dynamically
config.aspectRatio = not config.aspectRatio
end
endConfigures how the resolution should be applied.
config (table): A table containing the configuration values. The accepted fields are:
width(number): The target width.
height(number): The target height.
aspectRatio(boolean): Whether the scaling should respect the aspect ratio between the width and height.
centered(boolean): Whether the resolution should be centered on the screen.
clampMouse(boolean): Whether the mouse position should be clamped inside the selected screen resolution.
clip(boolean): Whether the area outside from the selected screen resolution should be cleared.
replace(table): A table containing the strings"graphics","mouse"and/or"touch".If
"graphics"is present, thenresolution:start()andresolution:stop()will be applied to yourlove:draw()automatically.If
"mouse"is present, then the mouse position fromgetX(),getY()andgetPosition()in thelove.mousemodule will be transformed to match the resolution scaling. The mouse position in thelove.mousepressed(),love.mousereleased()andlove.mousemoved()callbacks will be transformed as well.If
"touch"is present, then the touch position fromlove.touch.getPosition()will be transformed to match the resolution scaling. The touch position in thelove.touchpressed(),love.touchreleased()andlove.touchmoved()callbacks will be transformed as well.If the table is empty, then all effects above will be applied.
Any change in these fields (except in replace) will take effect immediately.
Start scaling the screen to selected resolution.
Stop scaling the screen.
Converts a screen point to match the resolution scaling.
x (number): X position of the point.
y (number): Y position of the point.
Does the inverse of
resolution.toResized().
x (number): X position of the point.
y (number): Y position of the point.
Same as
love.mouse.getX(),love.mouse.getY(),love.mouse.getPosition()andlove.touch.getPosition(id), but the position returned from them will be transformed to match the resolution scaling.