0 votes

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?

in Engine by (74 points)

1 Answer

0 votes
Best answer

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)
sprite.position = Vector2(100, 100)
by (9,760 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.