Использование нескольких анимаций для Phaser 3 - PullRequest
0 голосов
/ 28 октября 2018

Как сделать анимацию тела вещества Phaser 3?В идеале я хотел бы переключаться между несколькими анимациями.

Пока мне только удалось дать ему статическое изображение:

function preload ()
{
    this.load.image('human', 'assets/sprites/x2kship.png');
}

function create ()
{
    human = this.matter.add.sprite(300, 400, 'human');
}

Я подготовил файлы из старого проекта: атласа.png, atlas.json, animations.json.И он успешно загружается:

this.load.atlas('sheet', 'data/atlas.png', 'data/atlas.json');

Пример из animations.json:

{
    "animations": [
        {
            "name": "human-walk",
            "frames": [
                "human1.png",
                "human2.png",
                "human3.png",
                "human4.png"
            ],
            "frameRate": 100
        },
        ...

Ссылочные файлы "human1.png" и т. Д. Находятся в atlas.json:

    "human1.png": {
        "frame": { "x": 1137,"y": 1030, "w": 182, "h": 195 },
        "rotated": false,
        "trimmed": false,
        "spriteSourceSize": { "x": 0,"y": 0, "w": 182, "h": 195 },
        "sourceSize": { "w": 182, "h": 195 },
        "pivot": { "x": 0.5, "y": 0.5 }
    },

Как я могу соединить эти части вместе, чтобы заставить человека сделать что-то вроде human.animations.play('human-walk')?И тогда может быть human.animations.play('human-stand-still')?

1 Ответ

0 голосов
/ 30 октября 2018

Настройка формата анимации Я получил его для работы так:

function preload ()
{
    this.load.image('human', 'assets/sprites/x2kship.png');    
    this.load.atlas('sheet', 'data/atlas.png', 'data/atlas.json');
}

function create ()
{
    var humanWalk = {
        key: 'human-walk',    
        frames: [
            {key: "sheet", frame: "human1.png"},
            {key: "sheet", frame: "human2.png"},
            {key: "sheet", frame: "human3.png"},
            {key: "sheet", frame: "human4.png"},
        ],
        frameRate: 6,

        repeat: -1
    };

    this.anims.create(humanWalk);

    human = this.matter.add.sprite(100, 100, 'human');
    human.anims.load('human-walk');
    human.anims.play('human-walk');
}
...