Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | kaboom1212 | |
Old Version | Published before Godot 3 was released. |
I’ve done a fair amount of research on the scripting in this engine and have taught myself a whole bunch of different things.I am currently making my first program which is a simple platformer where a man hops around as well as runs around. For this project I made a series of pixel animations, with four specific animations, a Left idle (as in facing left), a Right idle, a Left walk cycle, and a right walk cycle. I have each of these animations keyed up and working in the animation player. I can run each one, but I now have to figure out a way to play each one. I made a basic code which I thought would work.
var move_speed = 150
var anim
func _process(delta):
.
anim = get_node(“AnimationPlayer”)
.
.
.
if Input.is_key_pressed(68): #68 = D
set_axis_velocity(Vector2(move_speed,0))
anim.play(“Right Walk”)
It’s a simple enough code, it handles walking and playing an animation at the same time. However, I didn’t realize that this code refreshes multiple times per second. So I looked up a few different solutions and figured out, the easiest way to go about play the animation is to only play something when the animation changes.
‘Ray Koopa’ - " As you check the input in _fixed_process, you call anim_player.play() several times a frame, which always seems to restart the animation, and thus, keeps the very first frame of the animation visible all the time.
As soon as you release the key, anim_player.play() stops resetting the animation back to start, and it can actually proceed to play the following frames.
A simple straight-forward solution would be to remember the last animation you played, and only call play() as soon as it changes."
This is great. The problem is I don’t know how to do this. I’ve been able to figure things out thus far but I’m stumped on how to do this. I know what I want to do, and how to do it, but I don’t know what codes to use. If anybody can help it would be fantastic.
If there is a decent resource to use for GDscripting (as in being taught the script not just the information Godot provides) it would also be very much appreciated. That way I don’t run into any more cases like this.