- 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.
- Big Data Analytics with Hadoop 3
- UTM(統(tǒng)一威脅管理)技術概論
- 自動檢測與轉換技術
- MicroPython Projects
- Hybrid Cloud for Architects
- Enterprise PowerShell Scripting Bootcamp
- 人工智能:語言智能處理
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- ZigBee無線通信技術應用開發(fā)
- 大數(shù)據(jù):引爆新的價值點
- PowerPoint 2010幻燈片制作高手速成
- Windows 7來了
- Appcelerator Titanium Smartphone App Development Cookbook(Second Edition)
- 運動控制系統(tǒng)應用及實例解析
- Kubernetes Design Patterns and Extensions