I'm trying to create a Unit class that will hold unit information, such a strength, movement points, as well as a TextureRect containing the unit's position and texture. But I'm having trouble displaying the unit on the map. Here's my class initializaiton function. Maybe I'm not creating the TextureRect correctly? Or, more likely, I've messed up the syntax of load()? I confess I don't understand load() very well. Here's the code:
extends Object
class_name Unit
var unit_rect : TextureRect
... (other variable declarations omitted)
func _init(_str: int = 0, _move : int = 0, _size : int = FORMATION.ARMY, _col : int = 0,
_row : int = 0, _on_map : bool = true, _name : String = designation.G1,
_texture : String = "res://units/6th Armee.jpg", _unit_rect = TextureRect.new() ):
strength = _str
movement = _move
size = _size
col = _col
row = _row
on_map = _on_map
name = _name
texture = _texture
unit_rect = _unit_rect
unit_rect.texture = load(_texture)
Then, in a setup_units function elsewhere, I create new units:
func setup_units():
G6 = Unit.new(6, 5, Unit.FORMATION.ARMY, 1, 3, true,
$Unit.designation.G6, "res://units/6th Armee.jpg" )
G6.unit_rect.texture = load(G6.texture)
G6.unit_rect.rect_size.x = 64
G6.unit_rect.rect_size.y = 64
G6.unit_rect.rect_position.x = 300
G6.unit_rect.rect_position.y = 400
The code compiles and runs, but I never see a unit, regardless of where I put the load(texture) call. I got the texture string by right clicking on the image in the resources pane and clicking "copy path", then pasting it into the code. I'm pretty new to Godot, so I'd appreciate any help. Thanks.