🎮 Tutorial Godot do Zero 2025 #4 – Animações via Código com AnimatedSprite2D

🎮 Tutorial Godot do Zero 2025 #4 – Animações via Código com AnimatedSprite2D

Implementing Player Animations in Game Development

Introduction to Player Animation

  • The video begins with a recap of the previous session, where the player animation for the idle state was created and adjustments were made to the screen layout.
  • The current focus is on enabling the player character to turn left while walking, as it currently only faces right.

Modifying Player Orientation

  • The presenter navigates back to the player scene, emphasizing that all modifications will occur within this dedicated area.
  • To flip the player's orientation, they explore properties in the Animated Sprite 2D settings, specifically looking at horizontal flipping (Flip H).

Coding Adjustments for Animation

  • Instead of using inspector settings directly, changes will be implemented through code by accessing specific node references.
  • A method for obtaining a reference to the Animated Sprite 2D node is demonstrated by dragging and dropping while holding control.

Understanding Variable Declaration

  • Explanation of variable declaration in GDScript includes defining a new variable type (AnimatedSprite2D), which allows manipulation of sprite properties via code.
  • The presenter clarifies how referencing nodes works within the game’s structure and emphasizes updating references if node names change.

Physics Processing Logic

  • An overview of physics processing reveals checks for whether the player is on solid ground or falling due to gravity.
  • Input handling is discussed; pressing left or right adjusts direction values (-1 for left, +1 for right), allowing movement control.

Direction-Based Animation Logic

  • The logic for determining player direction based on input values is outlined; zero indicates no movement.
  • A temporary coding solution is proposed to test functionality before refining it into a more robust version later.

Conditional Statements in Code

  • An if statement checks if direction values indicate movement; actions are taken based on whether it's positive or negative.
  • If moving right (positive value), Flip H remains false; if moving left (negative value), Flip H becomes true.

Testing Movement Functionality

  • After implementing directional checks, testing confirms that animations correctly reflect movement directions when pressing keys.

Adding New Animations: Walking and Jumping

  • With basic movement functioning correctly, attention shifts towards creating additional animations such as walking and jumping.
  • A new animation named "walk" is added by importing images from an existing asset package.

Configuring Animation Properties

  • Each frame's configuration involves setting up six frames horizontally with one vertical line for smooth walking animation playback.

Adjusting Frame Rate

  • Frame rates are adjusted to enhance animation speed; both walk and idle animations are set to 10 FPS for better visual fluidity.

Looping Animations

  • Infinite looping options are enabled for continuous animations like walking and idling but disabled for single-frame actions like jumping.

Integrating Animation Changes into Code

  • Code integration ensures that when moving right or left, corresponding animations play appropriately based on direction inputs.

Finalizing Jump Animation Setup

  • A jump animation setup follows similar steps as previous ones but focuses on a single image since it's not looped.

Implementing Ground Check Logic

  • Before executing jump-related actions in code, a check confirms whether the player character is grounded using is_on_floor.

Testing All Animations Together

  • Comprehensive testing shows successful transitions between idle, walking, and jumping states during gameplay interactions.

Conclusion & Next Steps

  • Viewers are encouraged to subscribe and stay tuned for future videos focusing on camera mechanics following player movements.

Turn any video into a summary like this

YouTube links, meetings, lectures. With transcripts, search, and chat.

Video description

Contribua com pix: rafaelforbeck@gmail.com No quarto vídeo da série Godot do Zero 2025, você vai aprender como controlar animações do personagem diretamente pelo código usando o AnimatedSprite2D. 📌 Neste vídeo, você vai aprender: Como virar o personagem para um lado e outro conforme ele caminha Como criar novas animações ("walk" e "jump") Como acessar o AnimatedSprite2D via script Como alternar entre animações com base na lógica do personagem Tudo explicado de forma prática, passo a passo, para você começar a dar vida ao seu personagem! 🛠️ Conteúdo do vídeo: 00:00 – Introdução 00:34 – Virando o personagem pelo inspector 01:40 – Pegando a referência Animated Sprite 03:13 – Revisão do código 05:49 – Virando o personagem via código 07:32 – Criando animação de caminhada (walk) 09:25 – Iniciando animação via código 10:55 – Criando animação de pulo (jump) 11:48 – Iniciando animação de pulo via código 12:52 – Resultado final 📌 Continue acompanhando a série e construa seu jogo completo com a engine Godot! Se inscreva no canal Rafael Forbeck | Game Dev e ative o sininho 🔔 para não perder os próximos vídeos! 🐧 Imagens utilizadas no projeto: https://grafxkid.itch.io/ 💾 GitHub – projeto no início do vídeo: https://github.com/RafaelForbeck/Godot-2025-Plataforma-2D-YouTube/tree/video-04-inicio 💾 GitHub – projeto no final do vídeo: https://github.com/RafaelForbeck/Godot-2025-Plataforma-2D-YouTube/tree/video-04-fim 💾 GitHub – principal (última versão): https://github.com/RafaelForbeck/Godot-2025-Plataforma-2D-YouTube 📎 Download da Godot: https://godotengine.org/ 🔖 Hashtags: #Godot #Tutorial #GameDev #GameDevelopment #DesenvolvimentoDeJogos