Let me explain the project structure.
Now there is only TileMap realization and game object structure looks like:
Scene -> TileMap -> TileSet(multiple) -> Tile(multiple)
GameObject - is a base or root object.
Each object responsible to call update and draw functions of its child objects.
Here is the problem part of Tile.lua from Repository and branch: https://github.com/makubo/battle-city-w ... ee/oop-wip. (I deleted some junk-debug comments here in example)
Code: Select all
function Tile:draw(xPos, yPos)
if xPos == nil then
xPos = 0
end
if yPos == nil then
yPos = 0
end
if self.animation ~= nil then -- < Do not enter inside condition. looks like every tile doesn't have animation (but in update function i have different results)
print("Tile draw frame" .. self.frame) -- < So I can't see it
end
love.graphics.draw(self.texture, self.quads[self.frame], xPos, yPos)
end
function Tile:update(dt)
if self.animation ~= nil then -- < Enter inside condition as I expect
local frame = self.frame % #(self.animation) + 1
local durationSec = self.animation[frame].duration / 1000
if self.timer >= durationSec then
self.frame = self.frame % #(self.animation) + 1
print("Frame - " .. self.frame) -- < I see the frame updates here
self.timer = 0
end
local timer = self.timer + dt
self.timer = timer
end
end
PS: In the master branch you can see animation realization without OOP and it works
PPS: The Tile class also was inheritor of the GameObject class but I rewrite it as standalone class, because I thought I don't understand Lua inheritance realization correctly.