Hello reader!
I'm having a small trouble with a inconsistence (Possibly i don't understand something). I'm instancing a node and calling a function, for some reason the variables are initialized from inside of node, but from outside spritenode is nil, if i use getnode instead the aparently initilized variable it works.
extends KinematicBody2D
export var speed = 0
var new_pos
# Nodes
onready var direction_node = get_node("Direction")
onready var sprite_node = get_node("Sprite")
func _fixed_process(delta):
#if (direction_node != null):
new_pos = (direction_node.get_global_pos() - get_global_pos()).normalized()
move(new_pos * speed * delta)
func _ready():
set_fixed_process(true)
func set_texture(var tex):
sprite_node.set_texture(tex)
# This works..
# get_node("Sprite").set_texture(tex)
func set_direction(var dir):
get_node("Direction").set_pos(dir)
func _on_VisibilityNotifier_exit_screen():
queue_free()
I'm calling set_texture() from Player.gd, instancing this way:
var bullet = preload("res://entities/bullets/Bullet.tscn").instance()
var bullet_texture = preload("res://resources/textures/pickups/special.png")
bullet.set_texture(bullet_texture)
get_node("../..").add_child(bullet)
I would appreciate help, thanks.
PD: I know my english is not perfect.