#What is the fastest way to draw pixels on a 2D screen or canvas
9 messages · Page 1 of 1 (latest)
Things that can draw arbitrary things on screen:
- Sprite2D, AnimatedSprite2D
- GPUParticles2D
- Line2D
- MeshInstance2D, MultimeshInstance2D
- Polygon2D
- TileMap
- ColorRect
- TextureRect
And finally
- Any Node2D's
func _draw()being overriden to use the variousdraw_xfunctions (draw_point, draw_line, draw_circle, etc)
depending on what your specific goal is, maybe you can use post processing and LUTS
wanna make a particle sim or just some automata game
so ill guess ill use a Node2D with a _draw function
you can either use draw_primitive to draw pixels directly by providing a single point
or you can create an image texture and use set_pixel() to set dots on it, then draw that texture with draw_texture(), or apply it to a sprite/texture rect. that might be more efficient
extends Node2D
const IMAGEFORMAT = Image.FORMAT_RGBA8
var image : Image
var texture : ImageTexture
@onready var SIZE : Vector2 = DisplayServer.window_get_size()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
image = Image.create(SIZE.x, SIZE.y, false, IMAGEFORMAT)
texture = ImageTexture.new()
texture.set_image(image)
func _process(delta: float) -> void:
queue_redraw()
func _draw() -> void:
image.set_pixel(0,0, Color.RED)
what am i doing wrong here, no pixel seems to draw
should i also add an texturerect node and assign the texture to it?