Code: Select all
push = require 'push'
VIRTUAL_WIDTH = 384
VIRTUAL_HEIGHT = 216
WINDOW_HEIGHT = 720
WINDOW_WIDTH = 1280
WALK_SPEED = 40
function love.load()
push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT,{
fullscreen = false,
vsync = true,
resizable = true
})
Ctexture = love.graphics.newImage('entities.png')
Cquads = GenerateQuads(Ctexture,16,16)
posX = VIRTUAL_WIDTH/2
posY = VIRTUAL_HEIGHT/2
love.keyboard.keyPressed = {}
canvas = love.graphics.newCanvas()
end
function love.keypressed(key)
love.keyboard.keyPressed[key] = true
end
function love.keyboard.wasPressed(key)
return love.keyboard.keyPressed[key]
end
function love.update(dt)
if love.keyboard.wasPressed('escape') then
love.event.quit()
end
if love.keyboard.isDown('up') then
posY = posY - WALK_SPEED * dt
end
if love.keyboard.isDown('down') then
posY = posY + WALK_SPEED * dt
end
if love.keyboard.isDown('left') then
posX = posX - WALK_SPEED * dt
end
if love.keyboard.isDown('right') then
posX = posX + WALK_SPEED * dt
end
love.keyboard.keyPressed = {}
end
function love.draw()
push:start()
love.graphics.setCanvas{canvas,stencil = true}
--love.graphics.setCanvas(canvas)
love.graphics.stencil(function()
love.graphics.rectangle('fill',VIRTUAL_WIDTH/2 - 40,VIRTUAL_HEIGHT/2 - 10, 60,60)
end,'replace',1,false)
love.graphics.setStencilTest('gequal',0)
love.graphics.draw(Ctexture,Cquads[1],posX,posY)
love.graphics.setStencilTest()
love.graphics.setCanvas()
--love.graphics.draw(Ctexture,Cquads[1],posX,posY)
push:finish()
end
function GenerateQuads(atlas,tileWidth,tileHeight)
local sheetWidth = atlas:getWidth()/tileWidth
local sheetHeight = atlas:getHeight()/tileHeight
local sheetCounter = 1
local spriteSheet = {}
for y = 0, sheetHeight - 1 do
for x = 0, sheetWidth - 1 do
spriteSheet[sheetCounter] = love.graphics.newQuad(x * tileWidth, y * tileHeight,
tileWidth, tileHeight, atlas:getDimensions())
sheetCounter = sheetCounter + 1
end
end
return spriteSheet
end
In the above code I have tried to do exactly what I want, I want that when character enters the area defined by the rectangular area inside stencil function does not render to the screen. I have other alternative, in program I can set a flag for this, but I want to use stencil for this. Can you please help.