我試圖創建一個將某些文本繪製到屏幕的Actor。該演員在屏幕內。我的主類是簡單的:當我運行該程序的遊戲剛剛崩潰在Libgdx的屏幕內爲場景繪製字體
package com.culture.jamiefearon;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class IntroScreen implements Screen {
final Culture game;
OrthographicCamera camera;
private int viewWidth = 800;
private int viewHeight = 480;
private Stage stage;
public class MyActor extends Actor {
public void draw(SpriteBatch batch, float parentAlpha){
batch = game.batch;
game.font.draw(batch, "Culture", viewWidth/2, viewHeight/2);
}
}
public void create() {
stage = new Stage();
MyActor myActor = new MyActor();
stage.addActor(myActor);
}
public IntroScreen(final Culture gam) {
game = gam;
camera = new OrthographicCamera();
camera.setToOrtho(false, viewWidth, viewHeight);
}
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
game.batch.setProjectionMatrix(camera.combined);
stage.draw();
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
:
package com.culture.jamiefearon;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Culture extends Game {
public SpriteBatch batch;
public BitmapFont font;
public void create() {
batch = new SpriteBatch();
font = new BitmapFont(); // Use LibGDX's default Arial font.
// Start the introScreen.
this.setScreen(new IntroScreen(this));
}
public void render() {
super.render();
}
public void dispose() {
batch.dispose();
font.dispose();
}
}
而且我的屏幕類定義爲。
是否有錯誤訊息?如果是這樣,你可以在這裏發佈嗎? – clearlyspam23