Hey Zylann. So to explain the set up i have, have a scene with character running around, and as soon as character jumps and catches the light, it changes the light (sprite).
So there is a scene that holds the environment (root node). A player (character) is child of this root. And the light (saved separately as xml file) is also child of this scene. Now within the light file itself i added this code to have a little animation and also do area2d.
So as soon as the character touches area2d it should substitue with a different sprite. Was wondering if i should keep the sprite(new texture that should pop up in place of old one) in light.xml or scene.xml?
Preview of code from light.xml :
extends Node2D
#for small lights, get 1 point
export var light_value = 1
func on_touched_by_thing():
var texture = preload("res://InsideHouse_lvl01/c2_lightLED.png")
sprite.set_texture(texture)
func _ready():
print (get_owner().get_name())
if get_owner() != null:
get_owner().lights_total += light_value
#connect the area2d with node using code, connect function. Say 'self' cos its referring to light node
get_node("Area2D").connect("body_enter", self,"_change_lights")
func _change_lights( body ):
body.on_touched_by_thing()
Will be appreciated if you can help. I have managed to make the light disappear, where instead of body.ontouchedbything() i simply put "queuefree()"