所以我正在设计一个带有libgdx的应用程序,无论如何都是一个简单的应用程序。它是食谱指南应用程序。 什么是为所有食谱渲染选择屏幕的最佳方式,我正在考虑创建一个表格并显示食谱并使其可点击/可触摸。但是我不知道在libgdx中开始这样做的第一种方式,或者他们是一个更好的选择。
好的,我实际上试图让这项工作我收到错误,我知道错误意味着我只是很难找到什么是空的;
更多的眼睛比一个更好。错二。
这个类是RecipeScreen
private TextureAtlas atlas;
private Sprite sprite;
private OrthographicCamera camera;
private AssetManager assets;
private SpriteBatch batch;
int[] blockMenu = new int[100];
public RecipeScreen(){
}
public void create(){
camera = new OrthographicCamera(720,1280);
assets = new AssetManager();
if (Gdx.app.getType() == ApplicationType.Android){
assets.load("data/akemix.pack", TextureAtlas.class);
assets.finishLoading();
} else {
assets.load("bin/data/bakemix.pack", TextureAtlas.class);
assets.finishLoading();
}
if (Gdx.app.getType() == ApplicationType.Android){
atlas = assets.get("bin/data/bakemix.pack");
} else {
atlas = assets.get("bin/data/bakemix.pack");
}
sprite = new Sprite(atlas.findRegion("BLOCKBACKSEL"));
}
public void renderBlockMenu(){
//batch.setProjectionMatrix(camera.combined);
batch.begin();
sprite.draw(batch);
batch.end();
}
public void dispose(){
assets.dispose();
batch.dispose();
}
}
此课程是开始画面
public StartScreen(){
}
SpriteBatch batch;
Texture textBCKG;
BitmapFont font;
InputMultiplexer ui;
boolean leftPressed = false;
boolean screenTouched = false;
Debug debug = new Debug();
RecipeScreen rScreen = new RecipeScreen();
ScreenState sState = new ScreenState();
public void create(){
batch = new SpriteBatch();
font = new BitmapFont();
ui = new InputMultiplexer();
ui.addProcessor(new MyInputProcessor());
sState.setScreenState(0); //set to start
Gdx.input.setInputProcessor(ui);
if (Gdx.app.getType() == ApplicationType.Android){
textBCKG = new Texture(Gdx.files.internal("data/backgroundmix.png"));
} else {
textBCKG = new Texture(Gdx.files.internal("bin/data/backgroundmix.png"));
}
if (Gdx.app.getType() == ApplicationType.Android){
font = new BitmapFont(Gdx.files.internal("data/mixbig.fnt"),Gdx.files.internal("data/mixbig.png"),false);
} else {
font = new BitmapFont(Gdx.files.internal("bin/data/mixbig.fnt"),Gdx.files.internal("bin/data/mixbig.png"),false);
}
}
public void render(){
batch.begin();
if (sState.getScreenState() == 0){
batch.draw(textBCKG,0,0,1280,720);
font.setColor(1.0f,1.0f,1.0f,1.0f);
font.draw(batch, " BAKER MIX ", 180, 400);
font.draw(batch, " Touch To Start! ", 180, 350);
isStartHit();
} else if (sState.getScreenState() == 1){
batch.draw(textBCKG,0,0,32,32);
rScreen.renderBlockMenu();
}
//debug.displayDebugCoords();
batch.end();
}
public void dispose(){
batch.dispose();
textBCKG.dispose();
debug.dispose();
font.dispose();
}
public void isStartHit(){
if (Gdx.app.getType() == ApplicationType.Android){
if (screenTouched = Gdx.input.isTouched()){
font.draw(batch, "BUTTON PRESSED!", 180, 300);
sState.setScreenState(1);
}
} else {
if (leftPressed = Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
rScreen.create();
rScreen.renderBlockMenu();
sState.setScreenState(1);
}
}
}
}