好,
嗨,大家好,目前正在编写一个Android应用程序,该程序也适用于台式机。
有一个mainMenu,选择创建屏幕,游戏屏幕,但是在最后一个屏幕上,出现了SB错误...
我已经挣扎了两天,
我尝试在屏幕上绘制库存,但出现问题:
Spritebatch.end必须在.begin之前调用,
事实是我真的不知道错误可能从哪里来,告诉我lineX somethingX,在这一行没有Spritebach.end或begin,不知道该怎么办,
有什么提示吗?
public void render() {
stage.draw();
if (Settings.Paused) {
//DO NOTHING
}
}
错误是这样的:
E/LibGDX Utils: SpriteBatch.end must be called before begin.
java.lang.IllegalStateException: SpriteBatch.end must be called before begin.
at com.badlogic.gdx.graphics.g2d.SpriteBatch.begin(SpriteBatch.java:169)
at com.badlogic.gdx.scenes.scene2d.Stage.draw(Stage.java:127)
at com.oxyzstudio.oxyddia.system.gameRendering.InventoryUis.render(InventoryUis.java:115)
at com.oxyzstudio.oxyddia.screen.GameScreen.render(GameScreen.java:45)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.oxyzstudio.oxyddia.OxyddiA.render(OxyddiA.java:132)
at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:494)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1573)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
整个原因:
package com.oxyzstudio.oxyddia.system.gameRendering;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.DragAndDrop;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.oxyzstudio.oxyddia.OxyddiA;
import com.oxyzstudio.oxyddia.system.Settings;
import com.oxyzstudio.oxyddia.system.inventory.InvBar;
import com.oxyzstudio.oxyddia.system.inventory.InvSkillBarsActor;
import com.oxyzstudio.oxyddia.system.inventory.Inventory;
import com.oxyzstudio.oxyddia.system.inventory.InventoryActor;
public class InventoryUis {
private OxyddiA game;
//Inventory
public InventoryActor inventoryActor;
private ScrollPane scroll;
public Table inventoryGlobalTable;
public static Table inventoryGlobal;
private ImageButton All,Stuff,Cons,Crea,Comp,Boss,Craft,Quest;
//InvBar
private InvSkillBarsActor invbar1, invbar2, invbar3, invbar4;
private final Skin ImgSkin;
private final Skin UiSkin;
public static Stage stage;
//Other Tables
public Table seconAct, bar1, bar2, bar3, bar4;
public InventoryUis(OxyddiA game) {
this.game = game;
UiSkin = game.UiSkin;
ImgSkin = game.ImgSkin;
stage = new Stage(game.fillViewport);
stage.addActor(game.versionControl);
setWidgets();
configureWidgets();
}
private void setWidgets() {
createInventory();
createInvSkillBars();
}
private void createInventory() {
DragAndDrop dragAndDrop = new DragAndDrop();
inventoryActor = new InventoryActor(new Inventory(), dragAndDrop, UiSkin);
All = new ImageButton(ImgSkin,"inv_all");
Stuff = new ImageButton(ImgSkin,"inv_stuff");
Cons = new ImageButton(ImgSkin,"inv_cons");
Crea = new ImageButton(ImgSkin,"inv_crea");
Comp = new ImageButton(ImgSkin,"inv_comp");
Boss = new ImageButton(ImgSkin,"inv_boss");
Craft = new ImageButton(ImgSkin,"inv_craft");
Quest = new ImageButton(ImgSkin,"inv_quest");
}
private void createInvSkillBars() {
DragAndDrop dragAndDrop = new DragAndDrop();
invbar1 = new InvSkillBarsActor(new InvBar(), dragAndDrop, UiSkin);
invbar1.setVisible(true);
invbar2 = new InvSkillBarsActor(new InvBar(), dragAndDrop, UiSkin);
invbar2.setVisible(true);
invbar3 = new InvSkillBarsActor(new InvBar(), dragAndDrop, UiSkin);
invbar3.setVisible(true);
invbar4 = new InvSkillBarsActor(new InvBar(), dragAndDrop, UiSkin);
invbar4.setVisible(true);
}
private void configureWidgets() {
inventoryGlobalTable = new Table(UiSkin);
inventoryGlobalTable.add(All).row();
inventoryGlobalTable.add(Stuff).row();
inventoryGlobalTable.add(Cons).row();
inventoryGlobalTable.add(Crea).row();
inventoryGlobalTable.add(Comp).row();
inventoryGlobalTable.add(Boss).row();
inventoryGlobalTable.add(Craft).row();
inventoryGlobalTable.add(Quest).row();
inventoryGlobalTable.setSize(All.getWidth(), (All.getHeight()*11));
inventoryGlobal = new Table(UiSkin);
inventoryGlobal.add(inventoryGlobalTable);
inventoryGlobal.add(inventoryActor);
inventoryGlobal.setSize((inventoryActor.getWidth()+ inventoryGlobalTable.getWidth()), inventoryGlobalTable.getHeight());
inventoryGlobal.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture("tBexAlt.png"))));
inventoryGlobal.setPosition(game.WORLD_W/2 - inventoryGlobal.getWidth()/2, game.WORLD_H/2-inventoryGlobal.getHeight()/2);
inventoryGlobal.setVisible(false);
seconAct = new Table(UiSkin);
seconAct.setDebug(true);
seconAct.setFillParent(false);
seconAct.add(invbar1); seconAct.add(invbar2);
seconAct.row();
seconAct.add(invbar3); seconAct.add(invbar4);
seconAct.setPosition(game.WORLD_W /2- seconAct.getWidth()/2, 150);
stage.addActor(inventoryGlobal);
stage.addActor(seconAct);
}
public void update(float delta) {
stage.act(delta);
}
public void render() {
stage.draw();
if (Settings.Paused) {
//DO NOTHING
}
}
public void resize(int width, int height)
{
stage.getViewport().update(width, height);
//stage.getCamera().position.set(width/2,height/2,0);
//stage.getCamera().update();
}
public void dispose() {
stage.dispose();
}
}
顺便说一句,我正在使用-不会说很多,但是...-一些静态成员,
为了不像静态那样使用'em,
在课堂上:我创造他们
在另一种方法中:我调用了一些,然后Studio askme将其设置为静态,否则应用程序将无法编译:/
最佳答案
好,
终于多挖一点帮助了我...
问题实际上来自我的一个纹理包,
我在几节课中称呼它,并且随着我的改变,
我忘了更新Item Enum类,
我这样做了,瞧,没有更多的错误... :)
关于java - 解决-与TP相关的问题必须调用Libgdx SpriteBatch.end ...不要捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60818591/