在 libgdx 上应用 运行 时保留图像
Stay images while app running on libgdx
我是 LibGdx 的新手,但想 learn.anyway 这是我的问题。
我有代表 user.It 生命的心形图标 启动 side.My 旁边的 3 个心形图标 问题是,我无法显示这些图标,而 App running.It 仅在开始时显示游戏突然 disappers.How 我可以在游戏中保留生命图标(心形图标),而 运行 应用程序。
这是我的代码。
游戏构造
GameAreaScreen(final MyGdxGame game){
camera = new OrthographicCamera();
camHeight = Gdx.graphics.getHeight();//400
camWidh = Gdx.graphics.getWidth();//800
cany=camHeight;
camera.setToOrtho(false, camWidh, camHeight);
iconSize=64f;
canlar= new Array<Can>();
canlar.add(new Can());canlar.add(new Can());canlar.add(new Can());
_game= game;
create();
}
和我的渲染
@Override
public void render(float delta) {
//render
GL20 gl = Gdx.graphics.getGL20();
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
// tell the SpriteBatch to render in the
// coordinate system specified by the camera.
_game.batch.setProjectionMatrix(camera.combined);
_game.batch.begin();
_game.font.setColor(Color.BLACK);
_game.batch.draw(pointsbgImage,camWidh-iconSize, camHeight-iconSize);
_game.font.draw(_game.batch,String.valueOf(dropsGathered), camWidh-iconSize/2f,camHeight-iconSize/2f );
_game.batch.end();
_game.batch.begin();
for (Can eleman : canlar) {
_game.batch.draw(eleman.canImageTexture, canx+iconSize,cany-iconSize);
drawRect2(canx+iconSize, cany-iconSize, iconSize/2f, iconSize/2f, 1, eleman.canImageTexture);
canx+=iconSize;
}
_game.batch.end();
.......
.......
}
和我的Canclass代表生命
public class Can {
public Texture canImageTexture;
public Can(){
canImageTexture=(new Texture(Gdx.files.internal("data/heart.png")));
}
}
canx+=iconSize;
是问题所在。它增加到无穷大,将图标移到屏幕外。在 render() 方法中将 canx 重置为某个起始值
我是 LibGdx 的新手,但想 learn.anyway 这是我的问题。 我有代表 user.It 生命的心形图标 启动 side.My 旁边的 3 个心形图标 问题是,我无法显示这些图标,而 App running.It 仅在开始时显示游戏突然 disappers.How 我可以在游戏中保留生命图标(心形图标),而 运行 应用程序。 这是我的代码。
游戏构造
GameAreaScreen(final MyGdxGame game){
camera = new OrthographicCamera();
camHeight = Gdx.graphics.getHeight();//400
camWidh = Gdx.graphics.getWidth();//800
cany=camHeight;
camera.setToOrtho(false, camWidh, camHeight);
iconSize=64f;
canlar= new Array<Can>();
canlar.add(new Can());canlar.add(new Can());canlar.add(new Can());
_game= game;
create();
}
和我的渲染
@Override
public void render(float delta) {
//render
GL20 gl = Gdx.graphics.getGL20();
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
// tell the SpriteBatch to render in the
// coordinate system specified by the camera.
_game.batch.setProjectionMatrix(camera.combined);
_game.batch.begin();
_game.font.setColor(Color.BLACK);
_game.batch.draw(pointsbgImage,camWidh-iconSize, camHeight-iconSize);
_game.font.draw(_game.batch,String.valueOf(dropsGathered), camWidh-iconSize/2f,camHeight-iconSize/2f );
_game.batch.end();
_game.batch.begin();
for (Can eleman : canlar) {
_game.batch.draw(eleman.canImageTexture, canx+iconSize,cany-iconSize);
drawRect2(canx+iconSize, cany-iconSize, iconSize/2f, iconSize/2f, 1, eleman.canImageTexture);
canx+=iconSize;
}
_game.batch.end();
.......
.......
}
和我的Canclass代表生命
public class Can {
public Texture canImageTexture;
public Can(){
canImageTexture=(new Texture(Gdx.files.internal("data/heart.png")));
}
}
canx+=iconSize;
是问题所在。它增加到无穷大,将图标移到屏幕外。在 render() 方法中将 canx 重置为某个起始值