ScrollingBackground
Posted: Wed Jan 04, 2023 12:46 pm
Hello everyone !
I'm new to Love2D, but I know a little bit about Lua (because I used roblox studio for nearly 3 years)
I'm trying to make a background that scrolls endlessly but at the moment as I test, it sadly doesn't move
I don't have any error on my script, I just can't figure out how to move the background
I want the miniBackground to move with a speed of 2.5
I also want to move the front background, if someone can tell me if I have to use other variable or not, at a speed of 5
Here is the code:
--background
miniBackground = {}
miniBackground.posX = 0
miniBackground.img = love.graphics.newImage("assets/MiniBackground.png")
frontBackground = love.graphics.newImage("assets/FrontBackground.png")
BlueFront = love.graphics.newImage("assets/BlueFront.png")
BlueBack = love.graphics.newImage("assets/BlueBack.png")
--assets
player = love.graphics.newImage("assets/Fish.png")
Title = love.graphics.newImage("assets/FishyJourneyTitle.png")
PlayButton = love.graphics.newImage("assets/PlayButton.png")
OptionButton = love.graphics.newImage("assets/OptionButton.png")
function love.draw()
love.graphics.draw(miniBackground.img,0,250)
love.graphics.draw(BlueBack)
love.graphics.draw(frontBackground)
love.graphics.draw(BlueFront)
end
function love.update(dt)
miniBackground.posX = miniBackground.posX - (5 * dt)
if miniBackground.posX < -1280 then
miniBackground.posX = miniBackground.posX + 4360
end
end
I'm new to Love2D, but I know a little bit about Lua (because I used roblox studio for nearly 3 years)
I'm trying to make a background that scrolls endlessly but at the moment as I test, it sadly doesn't move
I don't have any error on my script, I just can't figure out how to move the background
I want the miniBackground to move with a speed of 2.5
I also want to move the front background, if someone can tell me if I have to use other variable or not, at a speed of 5
Here is the code:
--background
miniBackground = {}
miniBackground.posX = 0
miniBackground.img = love.graphics.newImage("assets/MiniBackground.png")
frontBackground = love.graphics.newImage("assets/FrontBackground.png")
BlueFront = love.graphics.newImage("assets/BlueFront.png")
BlueBack = love.graphics.newImage("assets/BlueBack.png")
--assets
player = love.graphics.newImage("assets/Fish.png")
Title = love.graphics.newImage("assets/FishyJourneyTitle.png")
PlayButton = love.graphics.newImage("assets/PlayButton.png")
OptionButton = love.graphics.newImage("assets/OptionButton.png")
function love.draw()
love.graphics.draw(miniBackground.img,0,250)
love.graphics.draw(BlueBack)
love.graphics.draw(frontBackground)
love.graphics.draw(BlueFront)
end
function love.update(dt)
miniBackground.posX = miniBackground.posX - (5 * dt)
if miniBackground.posX < -1280 then
miniBackground.posX = miniBackground.posX + 4360
end
end