带有图集的Android Studio绘图

时间:2016-01-26 12:49:49

标签: java android 2d platform

我试图在我的屏幕上绘制精选的spritesheet但我得到了这个错误:

Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.flappybird.game.FlappyBird.create(FlappyBird.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:146)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)

这是我制作的代码。

package com.flappybird.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;

public class FlappyBird extends ApplicationAdapter {
private TextureAtlas textureAtlas;
private Sprite sprite;
public OrthographicCamera camera;
SpriteBatch batch;

@Override
public void create () {
    batch = new SpriteBatch();
    textureAtlas = new TextureAtlas(Gdx.files.internal("spritesheet.pack"));
    sprite = textureAtlas.createSprite("Background1");
    sprite.setPosition(sprite.getWidth(),sprite.getHeight());
    camera = new OrthographicCamera();
    camera.setToOrtho(false);
    camera.position.set(10,20,0);
}

@Override
public void render () {
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    sprite.draw(batch);
    batch.end();
}
}

有人可以帮我解决这个问题吗?我真的很感激:))

0 个答案:

没有答案