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

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.

主站蜘蛛池模板: 武清区| 遵义县| 株洲市| 喀喇沁旗| 昌平区| 泰顺县| 都昌县| 永宁县| 八宿县| 上蔡县| 东乡族自治县| 池州市| 浦东新区| 全州县| 兴安盟| 河曲县| 静乐县| 田东县| 瑞安市| 蕲春县| 桐乡市| 阳东县| 张家界市| 普陀区| 漠河县| 营山县| 萨嘎县| 玉田县| 苗栗县| 密云县| 嘉兴市| 三穗县| 平泉县| 赫章县| 五原县| 马山县| 正镶白旗| 磐石市| 贵南县| 剑阁县| 灵川县|