【问题标题】:Animation is an abstract cannot be instantiated动画是抽象的,无法实例化
【发布时间】:2016-05-01 15:26:42
【问题描述】:

我在使用 libGDX 在 Android Studio 上工作时遇到此错误。

这是我的代码:

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.Animation;

public class MyGdxGame extends ApplicationAdapter {
private SpriteBatch batch;
private TextureAtlas shooterAtlas;
private Animation animation;
private float timePassed = 0 ;

@Override
public void create () {
    batch = new SpriteBatch();
  shooterAtlas = new TextureAtlas(Gdx.files.internal("shooter.atlas"));
    animation = new Animation(1/30f,shooterAtlas.getRegions());
}

@Override
public void dispose() {
    batch.dispose();

 }

 @Override
 public void render () {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    timePassed += Gdx.graphics.getDeltaTime();
    batch.draw(animation.getKeyFrame(timePassed,true),300,500);
    batch.end();

   }
 }

首先我有这个代码:

import javafx.animation.animation

代替:

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

但它给了我错误:

animation = new Animation(1/30f,shooterAtlas.getRegions());

那个: 动画是抽象的,无法实例化 但后来我导入了这个:

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

并删除:

import javafx.animation.animation

因为它给了我一个错误,你不能同时拥有这两种方法,并且使用 alt+enter 解决也不起作用。

但在编译时会报错:

Warning:[options] bootstrap class path not set in conjunction with -source 1.6

C:\Users\COMPUTER\Documents\new libgdx\core\src\com\mygdx\game\MyGdxGame.java 1 个警告 错误:任务 ':core:compileJava' 执行失败。

编译失败;有关详细信息,请参阅编译器错误输出。 信息:构建失败 信息:总时间:1.526 秒 信息:2个错误 信息:1 个警告 信息:在控制台中查看完整的输出

【问题讨论】:

    标签: java android android-studio libgdx


    【解决方案1】:

    最后一个错误是因为您正在使用以前的 jdk 版本编译代码,并且您有一个较新的尝试将源和目标都设置为您当前拥有的 jdk 版本。

    【讨论】:

    • 我也通过添加 import com.badlogic.gdx.graphics.g2d.Animation 解决了这个错误;但它在我描述的最后一个错误中给出了一个错误
    猜你喜欢
    • 2014-12-29
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2013-03-07
    • 2015-08-04
    • 1970-01-01
    • 2015-10-06
    相关资源
    最近更新 更多