Using code to access specific quads in .png file and assign it to sprite

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hsjaaa

Can I use code to access specific quads in a .png file, for example, a quad at point (64, 64) height 32 and width 32 in the png image, and assign it to sprite when game is running?
Thanks!

:bust_in_silhouette: Reply From: volzhs

you can do it with region_enabled and region_rect
here is a sample code.

var sprite = Sprite.new()
sprite.texture = load("res://icon.png")
sprite.region_enabled = true
sprite.region_rect = Rect2(32, 32, 32, 32)
add_child(sprite)
sprite.position = Vector2(100, 100)

Thanks! I found TileSet will work too, just need to define the tiles in a scence, convert it to TileSet and use create_tile.

hsjaaa | 2019-01-30 07:02