Autotile Helper Script

,

I spent some time over the past few weeks making a simple autotiling helper that uses a Tilemap for drawing. I decided to share it on GitHub so others could use it if they wanted: GitHub - GammaGames/Playdate-Autotile: A simple autotile helper class for the Playdate, written in Lua

preview1

A simple breakdown of how you could set it to some random noise:

import "autotile"

math.randomseed(playdate.getSecondsSinceEpoch())
local at = Autotile("monochrome-tilemap", width, height)
at:moveTo(200, 120)

-- Generate some noise
local noises = gfx.perlinArray(
    at.columns * at.rows,
    math.random(), 1,
    math.random(), 1,
    0, 0,
    0,
    1,
    0.5
)
-- Set each cell to SOLID or EMPTY
at:setCallback(
    noises, at.columns,
    function(val)
        if val > 0.5 then
            return STATE.SOLID
        else
            return STATE.EMPTY
        end
    end
)
2 Likes

I updated it, I tried to add some namespacing with Autotile.STATE instead of calling plain STATE. I'm not sure if that's doing namespacing correctly, I've just learned Lua so feel free to tell me if I'm wrong :smile:

1 Like