-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscene.lua
46 lines (44 loc) · 1.42 KB
/
scene.lua
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local scene = {
create = function()
local s = {
bgImageTable = Gfx.imagetable.new('images/bg.gif'),
bgImageIndex = 1,
skyImage = Gfx.image.new('images/sky.png'),
clouds1Image = Gfx.image.new('images/clouds1.png'),
clouds2Image = Gfx.image.new('images/clouds2.png'),
clouds1X = 0,
clouds2X = 0,
animationTimer = nil,
setup = function(self)
self.animationTimer = playdate.timer.new(500, function() self:nextFrame() end)
self.animationTimer.repeats = true
end,
nextFrame = function(self)
self.clouds1X = self.clouds1X + 0.24
self.clouds2X = self.clouds2X + 0.51
if self.clouds1X > 800 then
self.clouds1X = 0
end
if self.clouds2X > 800 then
self.clouds2X = 0
end
self.bgImageIndex = self.bgImageIndex + 1
if self.bgImageIndex > self.bgImageTable:getLength() then
self.bgImageIndex = 1
end
end,
draw = function(self)
self.skyImage:drawIgnoringOffset(0, 0)
self.clouds1Image:drawIgnoringOffset(math.floor(self.clouds1X) - 800, 0)
self.clouds1Image:drawIgnoringOffset(math.floor(self.clouds1X), 0)
self.clouds2Image:drawIgnoringOffset(math.floor(self.clouds2X) - 800, 0)
self.clouds2Image:drawIgnoringOffset(math.floor(self.clouds2X), 0)
local bgImage = self.bgImageTable:getImage(self.bgImageIndex)
bgImage:drawIgnoringOffset(0, 0)
end
}
s:setup()
return s
end
}
return scene