- Godot Engine Game Development Projects
- Chris Bradfield
- 182字
- 2021-06-18 18:51:27
Choosing animations
Now that the player can move, you need to change which animation the AnimatedSprite is playing based on whether it is moving or standing still. The art for the run animation faces to the right, which means it should be flipped horizontally (using the Flip H property) for movement to the left. Add this to the end of your _process() function:
if velocity.length() > 0:
$AnimatedSprite.animation = "run"
$AnimatedSprite.flip_h = velocity.x < 0
else:
$AnimatedSprite.animation = "idle"
Note that this code takes a little shortcut. flip_h is a Boolean property, which means it can be true or false. A Boolean value is also the result of a comparison like <. Because of this, we can set the property equal to the result of the comparison. This one line is equivalent to writing it out like this:
if velocity.x < 0:
$AnimatedSprite.flip_h = true
else:
$AnimatedSprite.flip_h = false
Play the scene again and check that the animations are correct in each case. Make sure Playing is set to On in the AnimatedSprite so that the animations will play.
- 火格局的時空變異及其在電網防火中的應用
- Dreamweaver CS3網頁設計與網站建設詳解
- Visual C# 2008開發技術實例詳解
- 城市道路交通主動控制技術
- 80x86/Pentium微型計算機原理及應用
- 觸控顯示技術
- 高維聚類知識發現關鍵技術研究及應用
- Kubernetes for Serverless Applications
- MCGS嵌入版組態軟件應用教程
- R Data Analysis Projects
- 電氣控制與PLC原理及應用(歐姆龍機型)
- Hands-On Dashboard Development with QlikView
- WOW!Photoshop CS6完全自學寶典
- 3ds Max造型表現藝術
- 人工智能云平臺:原理、設計與應用