Godot Version
4.4.1
Question
What is the best way to make an drawing app for Android with best possible performance godot can achieve?
i have this:
func _ready() -> void:
Input.use_accumulated_input = false
var size = $CanvasLayer2/TextureRect.get_rect().size
selected_color = $CanvasLayer/Panel4/GridContainer/btnColor.color
brush_image.fill(selected_color)
drawing_image = Image.create(size.x, size.y, false,Image.FORMAT_RGBA8)
drawing_image.fill(Color(0,0,0,0))
drawing_texture = ImageTexture.create_from_image(drawing_image)
$CanvasLayer2/TextureRect.texture = drawing_texture
func make_brush_image_circle(size: int, alpha: float = 1.0) -> Image:
var img = Image.create(size, size, false, Image.FORMAT_RGBA8)
var center = size / 2.0
for x in range(size):
for y in range(size):
var dx = x - center
var dy = y - center
var dist = sqrt(dx * dx + dy * dy)
if dist <= center:
img.set_pixel(x, y, Color(1, 1, 1, alpha))
else:
img.set_pixel(x, y, Color(0, 0, 0, 0))
return img
func _input(event: InputEvent) -> void:
if (mode == Mode.DRAW):
if (event is InputEventMouseMotion):
if event.pressure > 0.0:
if last_position:
_draw_brush(last_position, event.position - $CanvasLayer2/TextureRect.global_position)
last_position = event.position - $CanvasLayer2/TextureRect.global_position
else:
last_position = null
func scaled_alpha(pressure: float, min_pressure: float = 0.10, max_pressure: float = 0.99) -> float:
if pressure < 0.01:
return 0.0
else:
return clamp((pressure - min_pressure) / (max_pressure - min_pressure), 0.001, 0.05)
func _draw_brush(start_pos: Vector2, end_pos: Vector2) -> void:
var points = Geometry2D.bresenham_line(start_pos, end_pos)
var brush_colored = brush_image.duplicate() # Copia da imagem base
for x in range(brush_colored.get_width()):
for y in range(brush_colored.get_height()):
var alpha = brush_colored.get_pixel(x, y).a * drawForce
brush_colored.set_pixel(x, y, Color(
selected_color.r,
selected_color.g,
selected_color.b,
alpha
))
for point in points:
var brush_pos = Vector2(point) - Vector2(brush_colored.get_width(), brush_colored.get_height()) * 0.5
drawing_image.blend_rect(brush_colored, Rect2(Vector2.ZERO, brush_colored.get_size()), brush_pos)
drawing_texture.set_image(drawing_image)
Currently the performance is OK but i am thinking if i can get more from godot?