我希望屏幕上的游戏出现在条件语句中,下面的代码不会产生错误或白色字母。它应该采用白色文本并在黑色背景上显示,但它不起作用。我甚至通过使用Vector3确保坐标正确。
package com.mygdx.game;
import java.util.Random;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Input;
//import com.mygdx.game.IsFinished;
import com.badlogic.gdx.Screen;
import java.util.Random;
import java.util.Timer;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.mygdx.game.*;
class GameOverScreen implements Screen{
Label gameoverstring;
private Stage stage;;
SpriteBatch spritebatch;
int placex=0, placey=0;
@Override
public void show() {
stage = new Stage();
BitmapFont white = new BitmapFont(Gdx.files.internal("new.fnt"), false);
LabelStyle headingStyle = new LabelStyle(white, Color.WHITE);
gameoverstring = new Label("game ovaaaa!", headingStyle);
gameoverstring.setFontScale(3);
stage.addActor(gameoverstring);
}
@Override
public void render(float delta) {
Vector3 placeholder = new Vector3(placex, placey, 0);
show();
//gameoverstring.setPosition(0, 0);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gameoverstring.setPosition(placeholder.x, placeholder.y);
stage.act(delta);
stage.draw();
System.out.println(gameoverstring.getX()+" "+gameoverstring.getY());
}
答案 0 :(得分:0)
清理完代码后,它的工作原理与我的字体一样。
相关代码:
private Stage stage;
// Called automatically once for init objects
@Override
public void show() {
stage = new Stage();
stage.setDebugAll(true); // Set outlines for Stage elements for easy debug
BitmapFont white = new BitmapFont(Gdx.files.internal("new.fnt"), false);
LabelStyle headingStyle = new LabelStyle(white, Color.WHITE);
Label gameoverstring = new Label("game ovaaaa!", headingStyle);
stage.addActor(gameoverstring);
}
// Called every frame so try to put no object creation in it
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
stage.act(delta);
}
请注意,标签应该在左下角可见。
因此,如果您仍然无法看到文字,那么我猜您的字体有问题。也许你的* .png中的字体是黑色的,那么我认为libGdx不能将字符着色为白色并且它们保持黑色。猜测libGdx通过乘以值来对它们进行着色,0*x
总是0
。要测试它,您可以将Gdx.gl.glClearColor(0, 0, 0, 1);
更改为绿色或其他内容。
另外,您可以查看setDebugAll(true)
方法中的绿色边界线是否可见。