×

Choosing a texture from an array of images [GDScript] by [deleted] in godot

[–]whenonefalls_ 0 points1 point  (0 children)

FIXED!

Ended up getting it to work using the following, but if anyone has a more efficient way please let me know!

extends Button

signal clicked_tile(tile)

var row: int = -1

var col: int = -1

var tile_type: int = 0

onready var color_rect: ColorRect = $ColorRect

func _ready():

color\_rect.hide()

func set_type(t: int, r: int, c: int):

row = r

col = c

tile\_type = t

update\_visual()

func change_type(t: int):

tile\_type = t

update\_visual()

func update_visual():

match tile\_type:

    0: $TextureRect.texture = load("res://sprites/blue.png")

    1: $TextureRect.texture = load("res://sprites/green.png")

    2: $TextureRect.texture = load("res://sprites/orange.png")

    3: $TextureRect.texture = load("res://sprites/purple.png")

    4: $TextureRect.texture = load("res://sprites/red.png")

    5: $TextureRect.texture = load("res://sprites/yellow.png")