Reputation: 1441
The problem
I would like to have an area inside love2d
in which movable objects are drawn. The movement of the objects is not restricted by the area boundries but drawing is. Think of it as looking outside through a window. For example: a blue rectangle in an area, if it moves to the side its drawing should be truncated to the boundries of the area.
Before moving:
After moving (wrong):
After moving (right):
Restrictions and assumptions
Atempted solutions
I know I could stop drawing objects as soon as they 'touch' the boundries of the area, but that would cause them to suddenly disappear and then appear when they are wholly inside the area. I guess it takes some sort of layering system but I have no clue on how to include that in love2d
.
Upvotes: 3
Views: 435
Reputation: 4158
I think you are looking for love.graphics.setScissor
.
The scissor limits the drawing area to a specified rectangle.
Calling the function without any arguments (i.e. love.graphics.setScissor()
) disables scissor.
Example:
function love.draw ()
-- sets the drawing area to the top left quarter of the screen
local width, height = love.graphics.getDimensions()
love.graphics.setScissor(0, 0, width / 2, height / 2)
-- code to draw things
love.graphics.setScissor()
end
Upvotes: 4