Libgdx桌面启动器空白

时间:2014-06-15 15:31:47

标签: java libgdx

刚刚开始Libgdx和java游戏开发。有一些代码尝试写一个精灵表移动动画人,刚启动它所以没有完成当我尝试运行它单个精灵绘图没有运行,没有什么是桌面应用程序只是黑色。

Desktop Launcher:

package com.mkgame.game1.desktop;

import com.MKgames.OptionScreen;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mkgame.game1.Game1;

public class DesktopLauncher extends Game1{
    public static void main (String[] arg) {
        LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
        cfg.title = "Game1";
        cfg.width = 960;
        cfg.height = 540;

        new LwjglApplication(new Game1 (), cfg);

    }
}

主java类'Game1':

package com.mkgame.game1;

import com.MKgames.FarmerAsset;
import com.MKgames.OptionScreen;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class Game1 extends ApplicationAdapter {

    public OptionScreen game_screen;

    public void create() {
        FarmerAsset.load();
    }
}

游戏画面:

package com.MKgames;

import sun.java2d.loops.DrawGlyphListAA.General;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class OptionScreen implements Screen{

    GameMain game;
    OrthographicCamera camera;
    SpriteBatch batch;

    int farmerX;

    public OptionScreen(GameMain game){
        this.game = game;

        camera = new OrthographicCamera();
        camera.setToOrtho(true, 1920, 1080);

        batch = new SpriteBatch();

        farmerX = 960-85;

    }


    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.95F, 0.95F, 0.95F, 0.95F);


        camera.update();
        generalUpdate();
        batch.setProjectionMatrix(camera.combined);

        batch.begin();
            batch.draw(FarmerAsset.farmer1, farmerX, 200);
        batch.end();


    }


    public void generalUpdate() {
        if(Gdx.input.isKeyPressed(Keys.A)||Gdx.input.isKeyPressed(Keys.LEFT)){
            farmerX -= 5;
        }
        else if(Gdx.input.isKeyPressed(Keys.D)||Gdx.input.isKeyPressed(Keys.RIGHT)){
            farmerX += 5;   
        }

    }


    @Override
    public void show() {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void hide() {

    }

}

1 个答案:

答案 0 :(得分:1)

更改

public class Game1 extends ApplicationAdapter {

public class Game1 extends Game {

在Game中创建OptionScreen的实例:

public OptionScreen game_screen;

public void create() {
    FarmerAsset.load();
    game_screen = new OptionScreen(this);
    setScreen(game_screen);
}

这应该是好的。