Skip to content

简介 ​

Phaser Editor v5 · 英文原文

Sprite animations是Phaser游戏中最常使用动画字符的选项,这种动画技术的原则是显示一个图像的序列(帧),以给定的“速度”或帧速率.

Animation:

Eagle animation.

动画框架 :

Eagle animation frames.

在Phaser v3中,动画是作为全球物体的created,在animations manager中:

您可以创建单动画 :

javascript
this.anims.create({
    "key": "acorn",
    "frameRate": 12,
    "repeat": -1,
    "frames": [
        {
        "key": "atlas",
        "frame": "acorn-1"
        },
        {
        "key": "atlas",
        "frame": "acorn-2"
        },
        {
        "key": "atlas",
        "frame": "acorn-3"
        }
    ]
});

或多动画:

javascript
this.anims.fromJSON(
    "anims": [
        {
            "key": "acorn",
            // ....
        },
        {
            "key": "player",
            // ....
        }
    ]
);

在练习中,您可以在游戏中一次创建所有动画, 很可能是在预装机场景中。 然后, 您可以在将动画键传递到 play() 方法的 spirite 对象上播放动画 :

javascript
mySprite.play("acorn");

创建动画的另一种方法是将它们全部装入一个JSON文件,并使用this.load.animation(..)方法加载文件:

javascript
this.load.animation("my-anims", "assets/animations.json");

Phaser编辑器提供动画编辑器,以创建动画JSON文件。所以,工作流程非常简单:

在下一节中,我们将涵盖动画编辑部的所有方面。

Animations Editor


社区翻译