The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have an array of terrain types that are represented by numbers (0 = water, 1 = land, etc.)
I need each terrain type to show as a different coloured pixel.
I am currently using an ImageTexture but the createfromimage function is too slow as I want to update the image constantly. I have heard that maybe I should use a shader?

My current slow method:

extends Sprite

var terrain_image =
var terrain_texture =

func create_texture(width, height, terrain_array, depth_array):
    var color

    terrain_image.create(width, height, false, Image.FORMAT_RGBA8)

    for y in range(height):
        for x in range(width):
            var current_material = terrain_array[y][x]
            var current_depth = depth_array[y][x]
            if  current_material == 0:
                color =  # water
                color = color.darkened(abs(current_depth))
            elif current_material == 1:
                color = Color.yellow  # land
                color = color.darkened(current_depth)
            elif current_material == 2:
                color =
                color =  # error
            terrain_image.set_pixel(x, y, color)

    terrain_texture.create_from_image(terrain_image, 0)

func draw_terrain(width, height, terrain_array, depth_array):
    create_texture(width, height, terrain_array, depth_array)
    self.texture = terrain_texture
Godot version 3.2.3
in Engine by (21 points)

I ended up using sprites for anything that needed quick updating

1 Answer

0 votes

Neither shaders nor ImageTextures are very efficient way of storing and updating a world, so in this case I'd just stick to using what Godot provides; the TileMap node. You can either create the TileSet manually or by code if you so whish.

by (40 points)

Modifying a TileMap is still slow, though

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.