What is more efficient, Sprites, Custom Draws or Polygon2D?

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

I want to make a game where the shape of the main character is random.
It is in pixelart so I thought that generating squares would be right, but now I don’t know if it’s better to use Sprites, Custom Draws or Polygon2D to make every pixel.

They don’t have to use physics since I want that the father of all them make this job.
Sorry if my english is not perfect, and thanks for answer it.
:slight_smile:

:bust_in_silhouette: Reply From: Zylann

IMO the best would be a Sprite with a generated ImageTexture. Don’t draw every pixel manually every frame, it will be very slow. And obviously, pixel-art means plenty of squares, not fit for a polygon.

What you should do is to keep an Image around, in which you do set_pixel(x, y, color) for the pixels you want to customize. Then, once you are done changing the image, upload it to the graphics card using an ImageTexture:

var texture = ImageTexture.new() # You only need this the first time
texture.create_from_image(image, 0)

Then you can use that texture on your sprite by assigning the texture property. When you need to modify the existing texture, modify your image again and reupload it by only doing texture.create_from_image(image, 0).

Note: the 0 parameter means no flags will be applied (no filter, no repeat etc)

Okay.
Thank you :slight_smile:

TitoVice | 2020-04-01 23:05