What do you mean your code is different?
What’s the exact problem you’re having with adding the animation to your script? Did you try and get any error?
If you want to stick with your current logic, you have to add another bool (e.g. var spawning = true) to check if your character is spawning. Assuming that you want to play this animation when you add player to the scene tree, you can embed this logic in the _ready() function instead of the _physics_process. You’ll need to make sure that the default animation doesn’t immediately override the spawning animation. Use the spawning bool to prevent this.
It’s a bit cleaner and easier to expand on if you refactor your animation switches using centralized transition rules akin to a state machine. However, if these are the only animations you’ll ever have in your game, do not bother.
Could you rephrase your question then? I’m not sure where you’re getting stuck. Don’t you know how to add spriteframes to an AnimatedSprite2D? Don’t you know how to play it? Or are you getting stuck in the programming logic?
well i am just a beginner and i know basics of godot like how to add nodes or spritesheet but i am confused in gdscript i dont know what to type or what to use i tried to find toturial on youtube but nothing helps me can you tell me where and what do i need to type
That’s not what I’m getting at. Programming is a huge part of game development. If you can’t control the flow of logic there’s really not that much that we can do to help you. Apart from writing whatever feature you try to implement for you that is. If I were to do that, it’s not helping your project. It’s just stitching another bit of code that you probably don’t fully understand to your project.
You can either learn to code yourself, or pay a software developer to do the work for you.
CS50 for a solid introduction to coding (in python). Or if you prefer to start in GDscript Learn GDscript from Zero.