LibGDX: Android SpriteBatch not drawing(LibGDX:Android SpriteBatch 不绘图)
问题描述
我很难让 spriteBatch 在 LibGDX 中呈现.它显示了我何时在桌面上运行它,但在 Android 上却没有.我要渲染的精灵是星星背景.
I'm having a hard time getting a spriteBatch to render in LibGDX. It shows when I run it for the desktop, but not on Android. I sprite I'm trying to render is the star background.
桌面:http://i.stack.imgur.com/6a4m5.png
安卓:http://i.stack.imgur.com/mOvo2.png
这是我的代码:
@Override
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glClearColor(0, 0, 0, 1);
update(delta);
spriteBatchBack.begin();
sprite.draw(spriteBatchBack);
spriteBatchBack.end();
stage.act(delta);
stage.draw();
}
public void update(float delta) {
scrollTimer += delta * 0.03f;
if (scrollTimer > 1.0f)
scrollTimer = 0.0f;
sprite.setU(scrollTimer);
sprite.setU2(scrollTimer + 1);
}
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
@Override
public void resize(int width, int height) {
if (stage == null) {
stage = new Stage(width, height, true);
stage.clear();
addMusic();
addBackground();
addScence();
stage.addActor(play);
stage.addActor(options);
stage.addActor(quit);
stage.addActor(logoHead);
stage.addActor(lblPlay);
stage.addActor(lblOptions);
stage.addActor(lblQuit);
}
Gdx.input.setInputProcessor(stage);
}
public void addBackground() {
spriteBatchBack = new SpriteBatch();
Texture spriteTexture = new Texture(
Gdx.files.internal("pictures/menuBackground.png"));
spriteTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
sprite = new Sprite(spriteTexture, 0, 0, spriteTexture.getWidth(), spriteTexture.getHeight());
sprite.setSize(width, height);
}
如果我遗漏了任何重要的内容,请发表评论并告诉我.谢谢!
If there's anything important that I am leaving out, comment and let me know. Thanks!
推荐答案
我发现了我的问题.结果很简单,我使用的手机不支持 Open GL 2.0.为了解决这个问题,我将所有纹理的大小重新调整为 2 的幂,并将配置设置更改为 Open GL 1.1.
I found my problem. It turned out to be simply that the phones I used didn't support Open GL 2.0. To fix this I re-sized all my textures to the power-of-two, and changed the configuration settings to Open GL 1.1.
这篇关于LibGDX:Android SpriteBatch 不绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGDX:Android SpriteBatch 不绘图
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01