首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有纺织包装/ LibGDX的动画-渲染错误

带有纺织包装/ LibGDX的动画-渲染错误
EN

Stack Overflow用户
提问于 2014-02-20 02:46:05
回答 1查看 621关注 0票数 0

我试图用libGDX制作一个简单的18帧动画(其他信息: Eclipse,Windows 8)。

我得到了以下LogCat错误,再加上我的安卓测试设备上的一个黑屏幕:

代码语言:javascript
复制
02-20 09:26:15.229: E/AndroidRuntime(23444): FATAL EXCEPTION: GLThread
02-20 09:26:15.229: E/AndroidRuntime(23444): java.lang.NullPointerException
02-20 09:26:15.229: E/AndroidRuntime(23444):    at com.tester.test.TestGameClass.render(TestGameClass.java:71)
02-20 09:26:15.229: E/AndroidRuntime(23444):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:499)
02-20 09:26:15.229: E/AndroidRuntime(23444):    at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
02-20 09:26:15.229: E/AndroidRuntime(23444):    at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)

LogCat错误似乎指向了我的游戏类的呈现部分:

代码语言:javascript
复制
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
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.utils.Array;

public class TestGameClass implements ApplicationListener {

AssetManager manager = new AssetManager();
Texture grey_background;
Texture tell_arrow;
Texture test_anni_1;
Music test_intro;
Music test_play;
Sound menu_select;
OrthographicCamera camera;
SpriteBatch batch;
TextureAtlas spriteSheet;
private Array<Sprite> test;
private int currentFrame;
private float frameLength;
private float animationElapsed;

@Override
   public void create () {

    Texture.setEnforcePotImages(false);
    grey_background = new Texture(Gdx.files.internal("grey_background.png"));
    tell_arrow = new Texture(Gdx.files.internal("tell_arrow.png"));
    test_intro = Gdx.audio.newMusic(Gdx.files.internal("test_intro.mp3"));
    test_play = Gdx.audio.newMusic(Gdx.files.internal("test_play.mp3"));
    menu_select = Gdx.audio.newSound(Gdx.files.internal("menu_select.wav"));

    test_intro.setLooping(true);
    test_intro.play();

     camera = new OrthographicCamera();
     camera.setToOrtho(false, 480, 640);

    spriteSheet = new TextureAtlas( Gdx.files.internal( "spritesheet.txt" ));
    test = spriteSheet.createSprites("test");

     for(int i=0; i<test.size; i++){
         test.get(i).setSize(3.0f, 3.0f);
     }

     float dt = Gdx.graphics.getDeltaTime();
     animationElapsed += dt;
     while(animationElapsed > frameLength){
         animationElapsed -= frameLength;
         currentFrame = (currentFrame == test.size - 1) ? 0 : ++currentFrame;
     }

    }

   @Override
   public void render() {
       Gdx.gl.glClearColor(0, 0, 0.2f, 1);
          Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

       camera.update();
       batch.begin();
       test.get(currentFrame).draw(batch);
       batch.end();
       }

   public void resize (int width, int height) { 
   }

   public void pause () { 
   }

   public void resume () {
   }

   public void dispose () { 
       grey_background.dispose();
       menu_select.dispose();
       test_intro.dispose();
       test_play.dispose();
       tell_arrow.dispose();
       batch.dispose();
   }
}

我的纺织包装者png图像和文本文件引用每个测试框架为test1,test2,test3等。

我以前收到的错误指向与OpenGL相关的行,以及与相机设置相关的行。我好像解决了这些问题,但也许这是有关系的?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-20 03:44:10

您没有初始化批处理。插入

batch = new SpriteBatch();

在create()方法中。

除了这个,你的代码

float dt = Gdx.graphics.getDeltaTime(); animationElapsed += dt; while(animationElapsed > frameLength){ animationElapsed -= frameLength; currentFrame = (currentFrame == test.size - 1) ? 0 : ++currentFrame; }

应该放在render()中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21897064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档