For my fnaf fan game project. I coded a prototype. But I've got problem for the scrolling, I've tried to stop it but I can't. So if someone can help it could be great !
That's the code (only update and draw functions)
function love.update(dt)
player.x, player.y = love.mouse.getPosition()
if reduce_back == 300 then
reduce_back = reduce_back + 0
end
if player.x > 700 then -- If the X position is over than 700 screen's pixel
reduce_back = reduce_back + 25 -- There will have a scroll to the right
elseif player.x < 60 then -- If the X position is less than 60 screen's pixel
reduce_back = reduce_back - 25 -- There will have a scroll to the left
end
end
function love.draw()
love.graphics.scale(1)
-- Draws the background
for i = 0, love.graphics.getWidth() / background:getWidth() do
for j = 0, love.graphics.getHeight() / background:getHeight() do
love.graphics.draw(
background,
i * background:getWidth() - reduce_back, -- reduce_back is the variable I use for setting the camera to the middle and I also use it for scrolling
j * background:getHeight()
)
end
end
-- love.graphics.print(player.x, 1080 / 2, 0)
-- love.graphics.print(player.y, 1080 / 2, 15)
if bonnie.layers:getLayer() == 1 then
love.graphics.scale(0.18)
love.graphics.draw(bonnie.image, 0, 0)
player:setLife()
end
if not player.isAlive then
bonnie:playScream()
end
love.graphics.print(reduce_back)
end
If you need all my code I can send it if you desire.
if your trying to make an movable background(camera), then you should use an library for it, like hump (love2d hyper utility for massive progression).https://github.com/vrld/hump