官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 林西县| 易门县| 田东县| 杭锦旗| 巴楚县| 从江县| 汤阴县| 阳江市| 罗源县| 称多县| 泽库县| 山东省| 南雄市| 综艺| 沙坪坝区| 长春市| 喀喇| 阳原县| 建水县| 军事| 平邑县| 都昌县| 平度市| 荔波县| 三原县| 大丰市| 浦城县| 方正县| 调兵山市| 工布江达县| 正镶白旗| 丘北县| 嘉兴市| 麻江县| 凤阳县| 凌云县| 馆陶县| 梁山县| 桦南县| 庆安县| 岚皋县|