libgdx 和安卓应用程序.图像作为背景 [英] libgdx and android application. Image as background

查看:22
本文介绍了libgdx 和安卓应用程序.图像作为背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,刚开始使用 libgdx.我想知道如何在我的游戏中将分辨率为 960x640 的 image.png 作为背景?这个有可能?感谢您的建议和宽容.也许你有一个简单的教程?这是我的渲染类:

I am new and I just start my journey with libgdx. I would like to know how I can do image.png in resolution 960x640 as background in my game? This is possible? Thx for advices and forbearance. Maybe you hava a simply tutorial? This is my render class:

public void render() {

     texture = new Texture(Gdx.files.internal("E:/background.png"));

     Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
     batch.begin();
     batch.draw(texture, 0, 0);
     batch.end();
}

第二个问题.我需要插入两个活动图像,活动意味着当我单击该图像时,下一个图像会显示在屏幕上.我想在点击该图片时执行操作.

Second question. I need to insert two active images, active means when I click on that image, the next image show me on the screen. I want to implement action when I click on that picture.

推荐答案

在你的 create() 方法中,创建一个引用你的 image.png 的新纹理,然后使用你现有的 SpriteBatch 在 render() 循环中渲染它.在您调用 GL.clear() 之后,立即执行 batch.draw(backgroundTexture, 0. 0) 并确保您的相机处于 OrthographicProjection 模式.

In your create() method, create a new Texture referencing your image.png, and then use your existing SpriteBatch to render it in the render() loop. Immediately after your GL.clear() call, go your batch.draw(backgroundTexture, 0. 0) and make sure you're in OrthographicProjection mode for your camera.

这篇关于libgdx 和安卓应用程序.图像作为背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆