-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.lua
More file actions
56 lines (43 loc) · 1.12 KB
/
Tile.lua
File metadata and controls
56 lines (43 loc) · 1.12 KB
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
47
48
49
50
51
52
53
54
55
56
Tile = {}
function Tile:new(x, y, id)
local t = {}
assert(x and y and id, "ERROR: Tile:new(x, y, id), There is a nil argument")
t.id = id
t.img = love.graphics.newImage(t.id)
t.imgSize = t.img:getWidth() -- OK
t.x = x
t.y = y
--t.animation = nil
setmetatable(t, self)
self.__index = self
return t
end
function Tile:load(data)
local t = {}
t.id = data.id
t.img = love.graphics.newImage(data.id)
t.imgSize = t.img:getWidth() -- OK
t.x = data.x
t.y = data.y
if data.animation then
t.animation = Animation:loadFromTable(data.id, data.animation)
end
setmetatable(t, self)
self.__index = self
return t
end
function Tile:draw(tileSize, dt)
if self.animation then
dt = dt or love.timer.getDelta()
self.animation:update(dt)
self.animation:draw(self.x, self.y)
else
love.graphics.draw(self.img, self.x, self.y, 0, tileSize / self.imgSize)
end
end
-- function Tile:animate(width, height, duration, loop, start, ox, oy)
-- self.animation = Animation:new(self.img, width, height, duration, loop) -- The animation takes 0.5 seconds and loops
-- if start ~= false then
-- self.animation:start()
-- end
-- end