Animating tiles with STI
Posted: Mon Sep 26, 2022 6:21 am
Hello! So, I am creating a game, and I've been trying to animate water with STI and Tiled, I tried many ways to do so and the closest I've ever gotten (I guess) is with the setLayerTile function:
And the tiles never actually get changed. What am I doing wrong?
Code: Select all
function map:update(dt)
self.waterTimer = self.waterTimer + dt
if self.waterTimer >= self.waterDuration then
self.waterTimer = 0
-- animate water tiles
for i, tile in pairs(self.waterTiles) do
if tile.gid == self.waterLastGID then
local gid = self.waterFirstGID
else
local gid = tile.gid + 1
end
local x, y = self.currentMap:convertPixelToTile(self:getTilePixelPosition(tile))
print(x, y)
self.currentMap:setLayerTile("water", x, y, gid)
end
end
end
function map:getTilePixelPosition(tile)
local x = self.currentMap.tilewidth * (tile.gid)
local y = self.currentMap.tileheight * math.floor((tile.gid) / self.currentMap.tilesets[5].columns)
return x, y
end