Atlastexture, tileset or individual graphics for a roguelike?

Godot Version



So if I have a big graphics sheet like Kenney made:

(1-Bit Pack · Kenney)

And I’m setting up a game. Do I load it as a tileset for making tilemaps? And load it as an atlastexture for NPCs and items in the game? Or do I load it as a texture with an editable region for each Sprite2d? Or do I find a program to save the big sheet as 1,078 individual pngs and go from there?

The roguelike community prefers to work off a single sheet, but it seems Godot prefers individual pngs you can just load into sprites, buttons, etc…?

Finally, if you’re working off an individual sheet, how exactly do you use Rect2 to say your graphic should only be a subset of the whole sheet? I run into all sorts of errors trying to get Rect2 to work. For instance:

var item_texture = load("res://art/DungeonCrawl_ProjectUtumnoTileset.png")
item_texture = Rect2(96, 192, 32, 32)

The above doesn’t seem to work or this:

item_texture.region_rect = Rect2(96, 192, 32, 32)

Any ideas would be appreciated.

I use a mixed bag tileset/sprite sheet like this.
Part of the sheet is tiles and the rest I use as sprites.
I do it through the editor.
To cut out a sprite:
Add a Sprite2D control.
Drag the spritesheet into the Texture property in the inspector.
Select Region/Enabled On.
Then click on Edit Region.
The Region Editor window will pop up.
Find your image and drag a rect around it.
Click close and your sprite image should be visible.

On gaining size and complexity, you will likely want to separate out tiles from sprites and then separate sprites into reasonable categories.
So you will end up with a few sheets in theory.

1 Like

Hi Sancho2,

Thanks for the response. I agree that we can always individually load and define each sprite with edit region, but I was hoping there was a way to automate it so I could have a database of monsters/NPCs/items and then use the database coordinates to define the exact texture for each Sprite2d, i.e. texture = rect2(96,132). I feel like the code is there because everything you do in the editor can be replicated with code. However, I just don’t know the exact code to use.

Hi all,

For anyone else struggling with this, I just figured it out. If you create a Sprite2D and load a big graphics sheet into it, you can then change the portion of the sheet that is displayed with region_rect. Here’s the code for a Sprite2d named thing after I loaded the dungeoncrawl tileset image into it:

$thing.region_rect = Rect2(1120,288,32,32)

And here’s how you would do it without a preloaded image in Sprite2d:

	var image = Image.load_from_file("res://art/DungeonCrawl_ProjectUtumnoTileset.png")
	var texture = ImageTexture.create_from_image(image)
	$thing.texture = texture

So it looks like you use .get_region for images and .region_rect for textures.

Hope that helps someone else.