-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.lua
More file actions
27 lines (24 loc) · 814 Bytes
/
background.lua
File metadata and controls
27 lines (24 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Background = {
backgrounds = nil,
scrollSpeed = 2
}
BackgroundBuilder = createClass(Background, Updatable)
function Background:new()
currentHeight = love.graphics.getHeight()
for i=1, #self.backgrounds do
currentHeight = currentHeight - self.backgrounds[i].image:getHeight()
self.backgrounds[i].y = currentHeight
end
end
function Background:update()
for i=1, #self.backgrounds do
self.backgrounds[i].y = self.backgrounds[i].y + self.scrollSpeed;
if self.backgrounds[i].y >= love.graphics.getHeight() then
if i == 1 then
self.backgrounds[i].y = self.backgrounds[#self.backgrounds].y - self.backgrounds[i].image:getHeight() + self.scrollSpeed
else
self.backgrounds[i].y = self.backgrounds[i-1].y - self.backgrounds[i].image:getHeight()
end
end
end
end