java - 必须实现继承的方法ApplicationListener.render()

标签 java eclipse opengl libgdx

我不断收到此错误:

“MainMenu类型必须实现继承的抽象方法ApplicationListener.render()”

我的代码: 包 com.gdx.game.Screens;

import java.util.ArrayList;
import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenEquations;
import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gdx.game.Asteroid;
import com.gdx.game.TweenAccessors.SpriteTween;

public class MainMenu implements  ApplicationListener, Screen
{
//private Boolean isMain = false;                   //Boolean to check if the menu screen can exit
private Texture menuTexture;                    //Splash screen image
private Sprite  menuSprite;                 //Image manipulation
private SpriteBatch batch;                      //Container to bundle Sprites to speed up performance
private Asteroid game;              
private TweenManager manager;                   //Updates all tweens at once
private TweenCallback callBack;     

//SplashScreen constructor
public MainMenu(Asteroid game)
{
    this.game = game;
}

@Override
public void render(float delta) 
{

    Gdx.gl.glClearColor(0,0,0,1);                   //Set color to black
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);       //Clear the color
    manager.update(delta);
    //Begin drawing
    batch.begin();

    if((Gdx.input.isKeyPressed(Keys.ENTER)))
    {
        batch.dispose();
        //game.setScreen(gameClass(game));
    }

    menuSprite.draw(batch);

    //End drawing
    batch.end();
}

我仍然可以运行我的代码,但是当我尝试按 Enter 键时,它会终止并收到错误:

Exception in thread "LWJGL Application" java.lang.IllegalArgumentException: buffer not allocated with newUnsafeByteBuffer or already disposed
at com.badlogic.gdx.utils.BufferUtils.disposeUnsafeByteBuffer(BufferUtils.java:277)
at com.badlogic.gdx.graphics.glutils.VertexArray.dispose(VertexArray.java:71)
at com.badlogic.gdx.graphics.Mesh.dispose(Mesh.java:415)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.dispose(SpriteBatch.java:1094)
at com.gdx.game.Screens.MainMenu.render(MainMenu.java:50)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.gdx.game.Asteroid.render(Asteroid.java:24)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:202)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
AL lib: ReleaseALC: 1 device not closed

有什么想法吗?

最佳答案

这不是ApplicationListener中定义的render方法:

@Override
public void render(float delta)

real render method没有参数。

您的编辑器/编译器中应该会出现 @Override 注释触发的警告。

关于java - 必须实现继承的方法ApplicationListener.render(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13871434/

相关文章:

java - 如何在android中的父子 Activity 之间进行通信

java - 糖果机Java

java - 谷歌地图 - 我正在尝试更新当前位置,但我的应用程序一打开就关闭了。这是代码-

java - Eclipse 字体看起来很奇怪

c++ - OpenGL 球体顶点和 UV 坐标

java - 无法使用 JSON 解析器将网页中的图像显示到 android

eclipse - Eclipse 包中缺少类,帮助

java - 在 Eclipse 中导入 Metaio Creator(ADT - Android 开发者工具)

OpenGL - 尝试使用 VBO 会导致错误

linux - 与 Linux 上的 GLUT 共享上下文