I can draw on the Canvas but I can not read it.

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

I am trying to make a tank/worms styled game with destructible terrain. I used the CanvasItem to draw some terrain.

The problem is I have no way of accessing the Canvas that I drew. I want to put tanks on it but I don’t know how I could. It seems all you can do it draw on it and look at it but not interact in any way. Is there another Node that I could use to draw on and read or is there some other way to read the Canvas that I am not thinking about?

Worms

:bust_in_silhouette: Reply From: Zylann

Drawing and collision detection are two very different things, which also don’t have to be always tied to each other. Drawing happens on the graphics card (far away from the CPU), which makes it very slow to read back pixels.

In Godot, if you want collision on the level you made, you have to use StaticBody2D and CollisionShape2D. See the docs about physics: Physics introduction — Godot Engine (3.0) documentation in English

If you want a Worms-like terrain, this is getting to another level. It’s possible to do it, but you will have to combine your understanding of the engine with custom solutions for your game in order to achieve this. Implementing destructible terrain would be a similar problem to solve with 2D marching squares, using a bunch of CollisionPolygon2D, or a completely custom physics code based on pixels (which Godot doesn’t provide because it’s too game-specific).