Sure! First, here’s the snippets from tilelayer.lua that are relevant:
Here’s how every tile is instantiated, as of when I got it:
local tile = display\_newSprite(imageSheets[sheetIndex], imageSheetConfig[sheetIndex]) tile:setFrame(tileGID)
What this does is make a sprite object using the tilesheet and specific GID using setFrame(). This means that we can change the frame to any other tile in the tilesheet! What I decided to do was add some custom properties that would let me know what other GIDs to use. For my purposes (specifically, opening a door by swtiching between “closed” and “open” states), I just want to specify one “alternateGID”. I tracked down the spot where properties are added in functions.lua, and added this code:
elseif key:match("^props:") then insertionTable = p.props k = key:sub(6) --insert check for animation here elseif key:match("^animation:") then insertionTable = p.props; k = key:sub(0); else
What this does is look for any property that starts with “animation:” (for my purposes, animation:alternateGID) and throws that into the tile’s .props table.
After the space marked – Add Properties and Add Tile to Layer, I added the following code:
-- Add animation -- Custom edit if(tile.props.animation) then if(tile.props.animation.alternateGID) then tile.props.animation.alternateGID = tonumber(tile.props.animation.alternateGID) + 1; --for some reason, the values of GIDs are off by 1 in Dusk tile.setAlternateGID = function(self) local currentGID = self.GID; self:setFrame( self.props.animation.alternateGID ); self.props.animation.alternateGID = currentGID; end end end
This adds a function, tile:setAlternateGID(), that lets me alternate between GIDs at will by accessing the property I added and calling :setFrame(). Other options might be to store a sequence of frames as a table and use that animation. (It could start when prompted by some trigger or just as soon as it the tile is created.)
I hope this helps!