Newbie | How to code manual animation frame selection triggered by onscreen button?

Godot Version

GLES3

Question

I’m completely new to coding and I’m trying to showcase different version of a character (sprite ig?) with onscreen buttons. I’ve gotten the buttons to work the way I want them to but they’re not connected to anything. I know how to connect them, however I have no idea what code to write for them to do what I want them to.

I started with multiple sprites and tried to switch between them but couldn’t figure out how to do it and saw the suggestion to do it through an animated sprite instead.

so that was my next test. I honestly came pretty close I think. This is my code:

extends AnimatedSprite

onready var _animated_sprite = $animatedsprite

func _on_GlassesButton_On_pressed():
	if Input.is_action_pressed("ui_select"):
		$animatedsprite.frame 3

I get the error "error(7,26) : Expected end of statement after expression, got Constant instead.

I imagine that’s because my statement is technically not finished but idk how to finish it. I’m not sure this is even the easiest way to do this lol. Any help is appreciated.

I believe the error is the last line of code, there’s no = sign. also, through UI focus you shouldn’t need to see if the enter key was pressed.

Change the title to animation frame. Because the title suggests delta frame. First there’s a lot of confusion between code for the AnimationPlayer or AnimationTree. Which one are you working with? In code you need two strings. animation.play() and animation.advance(any value in time length like 0.5). Then there’s also animation.seek(any value in time length like 0.5, update=false) Update true will attempt to normalise transform from position a to position b. If you’re using hard transforms for animation. In the industry we only use that for engine pistons. This also makes a big difference if you don’t use reset_on_save(). Because the track will become a problem. It may not play a 3 second animation if loaded later and is actually finished.

Here’s what it’s supposed to look like;

animation.play(walk)
animation.advance(0.5)

This is for skipping the middle of the animation.

animation.play(walk)
animation.seek(0.5, update=false)

I know. It doesn’t refer to the animation as the frame. It only refers to it as the time on the que. It’s okay. It’s not even strange for system engineers that they refer to their OS as the “fight in flight”.

Any other suggestions you may come across is probably from people who didn’t understand the await commands. And, what it actually means to skip the middle of the animation in the mix. Like so;

func animals():
await animation.play(walk)
animation.play(walk)
animation.seek(0.75, update=false)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.