libgdx 动画问题

Issue with libgdx animation

我在尝试为动画设置播放模式时遇到特定行的问题。

根据 this API 我有以下可能性:

然而,在做的时候:

import com.badlogic.gdx.graphics.g2d.Animation;
...
spriteAnimation.setPlayMode(Animation.LOOP_PINGPONG);

我得到 LOOP_PINGPONG cannot be resolved or is not a field。这是什么原因?正如我所见,它在 API?


编辑:

我应该声明我正在关注 guide 的 gamedev 和 libgdx。但是该指南已有一年多的历史,因此我无法在那里寻求太多帮助。

package com.guldbechnielsensolutions.gamehelpers;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class AssetLoader {

    public static Preferences prefs;

    public static Texture texture;
    public static TextureRegion bg, grass;

    public static Animation spriteAnimation;
    public static TextureRegion sprite, spriteDown, spriteUp;

    public static TextureRegion skullUp, skullDown, bar;

    public static Sound dead, flap, coin;

    public static BitmapFont font, shadow;

    public static void load() {

        texture = new Texture(Gdx.files.internal("data/texture.png"));
        texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);

        bg = new TextureRegion(texture, 0, 0, 136, 43);
        bg.flip(false, true);

        grass = new TextureRegion(texture, 0, 43, 143, 11);
        grass.flip(false, true);

        spriteDown = new TextureRegion(texture, 136, 0, 17, 12);
        spriteDown.flip(false, true);

        sprite = new TextureRegion(texture, 153, 0, 17, 12);
        sprite.flip(false, true);

        spriteUp = new TextureRegion(texture, 170, 0, 17, 12);
        spriteUp.flip(false, true);

        TextureRegion[] sprites = { spriteDown, sprite, spriteUp };
        spriteAnimation = new Animation(0.06f, sprites);
        spriteAnimation.setPlayMode(Animation.LOOP_PINGPONG);

        skullUp = new TextureRegion(texture, 192, 0, 24, 14);
        // Create by flipping existing skullUp
        skullDown = new TextureRegion(skullUp);
        skullDown.flip(false, true);

        bar = new TextureRegion(texture, 136, 16, 22, 3);
        bar.flip(false, true);

        dead = Gdx.audio.newSound(Gdx.files.internal("data/dead.wav"));
        flap = Gdx.audio.newSound(Gdx.files.internal("data/flap.wav"));
        coin = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));

        font = new BitmapFont(Gdx.files.internal("data/text.fnt"));
        font.getData().setScale(.25f, -.25f);
        shadow = new BitmapFont(Gdx.files.internal("data/shadow.fnt"));
        shadow.getData().setScale(.25f, -.25f);

        prefs = Gdx.app.getPreferences("Get Me Out");

        if (!prefs.contains("highScore")) {
            prefs.putInteger("highScore", 0);
        }       
    }

    public static void setHighScore(int val) {
        prefs.putInteger("highScore", val);
        prefs.flush();
    }

    public static int getHighScore() {
        return prefs.getInteger("highScore");
    }

    public static void dispose() {
        // We must dispose of the texture when we are finished.
        texture.dispose();

        // Dispose sounds
        dead.dispose();
        flap.dispose();
        coin.dispose();

        font.dispose();
        shadow.dispose();
    }

}

https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g2d/Animation.java

这是动画的源代码Class。

如您所见,枚举实际上被称为 "PlayMode" 所以不要这样做:

spriteAnimation.setPlayMode(Animation.LOOP_PINGPONG);

你应该这样做

spriteAnimation.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);

编辑:

由于您导入了以下内容:

import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;

你也可以使用这个:

spriteAnimation.setPlayMode(PlayMode.LOOP_PINGPONG);

我会尝试 PlayMode.LOOP_PINGPONG。我查看了 libgdx Github 目录,PlayMode 似乎是一个枚举。