Setting Tile Source at runtime question

When setting Tile Source at runtime, other tile maps already using the tile source need to be deleted before the change is visible. See below.

Is there a way to set the Tile Source without first deleting the other tile maps?

go.property("tile_source1", resource.tile_source("/main/1.tilesource"))
go.property("tile_source2", resource.tile_source("/main/2.tilesource"))

function init(self)

	go.set( "/tilemap2#tilemap2", "tile_source", self.tile_source2 ) -- Does nothing until tile map 1 has been removed.
	
	timer.delay(2, false, function()
		go.delete("/tilemap1") -- Tile source of tile map 2 changes
	end)
	
end

Minimal example: SetTileSource.zip (26.4 KB)

Experimenting more with this, it seems that if two tile maps have the same tile source defined in the editor:

31

Those two tile maps always have to share the same tile source, even if different tile sources are set at runtime. I’m sure there is a technical reason for this. It looks like I’m going to need two sets of identical tile maps, with different tile sources set in the editor, rather than setting them at runtime.

You should be able to change the tilesource of a tilemap.
Could you provide a minimal example where this doesn’t work?

In the example I posted above it works only after the first tile map is deleted. Changing the code to this should show the issue:

go.set( "/tilemap2#tilemap2", "tile_source", self.tile_source2 ) -- Does nothing until tile map 1 has been removed.
	
timer.delay(2, false, function()
	--go.delete("/tilemap1") -- Tile source of tile map 2 changes
end)

Here is a minimal example where changing the tilesource of the tilemap doesn’t work: SetTileSource.zip (43.1 KB)

It’s the same project included in the first post, but with the game object deletion commented out, for Friday Convenience ™.

1 Like

Created: https://github.com/defold/defold/issues/5015

2 Likes