java - 当我创建一个舞台时,它不允许我在 libgdx 中绘制精灵
问题描述
我在 libgdx 中制作了一个游戏,其中一只乌龟必须收集海星,但我使用的是演员,所以我必须使用舞台。创建阶段后,我无法在屏幕上绘制精灵,并且游戏崩溃
编辑:我忘了把 batch.end() 放在最后,但它仍然没有绘制精灵
这是我的代码
@Override
public void render()
{
for (int i=0; i<5; i++)
{
if (Gdx.input.isTouched(i))
{
Vector3 touchPos = new Vector3(Gdx.input.getX(i), Gdx.input.getY(i), 0);
camera.unproject(touchPos);
Rectangle touch = new Rectangle(touchPos.x-16, touchPos.y-16, 32, 32);
if (touch.overlaps(leftButton))
{
moveX-=Gdx.graphics.getDeltaTime()*80;
System.out.println("left touched");
}
if (touch.overlaps(rightButton))
{
moveX+=Gdx.graphics.getDeltaTime()*80;
System.out.println("right touched");
}
if (touch.overlaps(jumpButton))
{
moveY+=Gdx.graphics.getDeltaTime()*80;
System.out.println("up touched");
}
}
}
// check user input
mainStage.act(1/60f);
// check win condition: turtle must be overlapping starfish
if (turtle.overlaps(starfish))
{
starfish.remove();
winMessage.setVisible(true);
}
// clear screen
Gdx.gl.glClearColor(0,0,0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// draw graphics
mainStage.draw();
batch.setProjectionMatrix(camera.combined);
batch.begin();
leftSpriteButton.draw(batch);
rightSpriteButton.draw(batch);
jumpSpriteButton.draw(batch);
}
解决方案
推荐阅读
- c# - 什么会导致 DbSet 中的持久实体被分离?
- google-apps-script - Google App Script - 如何从库中调用函数
- reactjs - 在不同的基于虚拟 DOM 的 UI 库(React、Inferno、Preact 等)中处理“ref”和“key”
- typescript - Phaser + TypeScript 严格模式
- c# - 在集中提交到 aspx 页面之前修剪所有控件的空间
- android - 如何使用场景形式从场景中删除选定的对象?
- java - Hibernate JPA @Generated 注解编译错误
- database - 使用 flask-sqlalchemy 组织数据库表
- javascript - window.screenY 上的 JS if 语句不起作用
- amazon-web-services - AWS 目标组 - 健康检查失败 - 目标路径无效