@adamprocter or @Gamma
Can this be expanded on?
Do I have to put it in a sprite everytime it updates?
Option 1
local BUFFER_TILES = 20
local TILES_ON_SCREEN = 15
local tiles = gfx.imagetable.new('assets/tilesprite') -- Getting Tiles
local map = gfx.tilemap.new() -- Creating Tilemap
map:setImageTable(tiles)
map:setSize(TILES_ON_SCREEN, BUFFER_TILES)
function initializeTiles()
for row = 1, BUFFER_TILES do
for column = 1, TILES_ON_SCREEN do
local block = math.random(1,2)
map:setTileAtPosition(column, row, block) -- Assigning tiles to tilemap
end
end
end
function playdate.update()
local tileSprite = gfx.sprite.new() -- Creating a sprite to put the tilemap
tileSprite:setTilemap(map)
tileSprite:setZIndex(1000)
gfx.sprite.update()
end
Or can I put the tiles in a sprite then use that throughout the game?
Option 2
local BUFFER_TILES = 20
local TILES_ON_SCREEN = 15
local tiles = gfx.imagetable.new('assets/tilesprite') -- Getting Tiles
local map = gfx.tilemap.new() -- Creating Tilemap
local tileSprite = gfx.sprite.new() -- Creating sprite for tiles
map:setImageTable(tiles)
map:setSize(TILES_ON_SCREEN, BUFFER_TILES)
function initializeTiles()
for row = 1, BUFFER_TILES do
for column = 1, TILES_ON_SCREEN do
local block = math.random(1,2)
map:setTileAtPosition(column, row, block) -- Assigning tiles to tilemap
end
end
tileSprite:setTilemap(map) -- Assigning tilemap to sprite
tileSprite:setZIndex(1000)
end
function playdate.update()
gfx.sprite.update()
end
With option 1 I feel like I'm needlessly creating a sprite every frame which feels wrong.
With option 2, it feels like ok now the tiles are associated with a sprite, but now how do I manipulate the tileset? I don't see a sprite.getTileset() or anything so....
Can you please help me understand this a bit more?