@AesynthGrey said:
@TwistedTwigleg said:
Ah I see, my bad then! I misunderstood the intent.
You may be able to export the SpriteFrames resource in code, and then change it that way. Something like this:
extends AnimatedSprite
export (SpriteFrames) var happy_frames
export (SpriteFrames) var bruised_frames
func _process(_delta):
if Input.is_action_just_pressed("ui_accept") == true:
if frames == happy_frames:
frames = bruised_frames
else:
frames = happy_frames
Though I have not tried it myself, so I'm not sure if it will work or not.
Okay. Exporting the SpriteFrames is awesome. But I have a question: How can I make it so that it changes the SpriteFrames resource on collision with an Area2D (keep in mind I have a function for that part [on_body_exited]) and the collision part works (I've tested that with printing).
Awesome. For changing on collision, it should be the same as the example above, but instead of checking for input in _process
, you instead change after collision in the on_body_exited
or on_body_entered
function. You can also make a function and then call it from the Area2D node, something like this:
func change_frames(frames_name):
if (frames_name == "happy"):
$AnimatedSprite.frames = happy_frames
elif (frames_name == "bruised"):
$AnimatedSprite.frames = bruised_frames
else:
print_debug("ERROR - unknown frame name passed to change_frames function!")
Then you can just call change_frames("happy")
or change_frames("bruised")
from the Area2D.