簡體   English   中英

libgdx渲染在另一個場景上導致背景精靈消失

[英]libgdx rendering srite over another causes background sprite to disapear

問題的圖片http://imgur.com/ZNpHiiu,所以我成功為游戲渲染了一個背景,現在我嘗試在其上渲染一些精靈,屏幕上的所有東西都被大藍色L弄亂了。

代碼主體

public class WizardGame extends Game {
public static final String TITLE = "Are you a bad enough wizard to save the princess?!", VERISION = "0.0.0.0.PREALPHA";
PlayTest pt = new PlayTest();
private FPSLogger fps;
public void create() {  
    Gdx.gl20.glClearColor(0, 0, 0, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
    fps = new FPSLogger();
    fps.log();
    pt.create();
}

public void dispose() {
super.dispose();
}

public void render() {      
    super.render();
    pt.render();
}

public void resize(int width, int height) {
super.resize(width, height);
}

public void pause() {
    super.pause();
}

public void resume() {
super.resume();
}

}

游戲測試代碼

public class PlayTest implements Screen  {

private TextureAtlas atlas;
private AtlasRegion floor;
private SpriteBatch batch;
private OrthographicCamera camera;
private Sprite background;
private BitmapFont font;
private String fps;
Blocks block = new Blocks();
public void render() {
    Gdx.gl20.glClearColor(0, 0, 05, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    background.setBounds(0, 0, 720, 1280);
    background.draw(batch);
    block.renderBlocks();
    batch.end();
}

public void resize(int width, int height) {
    // TODO Auto-generated method stub

}

public void show() {
}

public void hide() {

}

public void pause() {

}

public void resume() {

}

public void dispose() {
    atlas.dispose();
    batch.dispose();
}

public void create() {
    atlas = new TextureAtlas(Gdx.files.internal("data/wizardpack.pack"));
    floor = atlas.findRegion("Backfloor");
    background = new Sprite(floor);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/magicdebug48.fnt"));
    block.create();

}

@Override
public void render(float delta) {
    // TODO Auto-generated method stub

}

}

區塊碼

public class Blocks extends Game {
private TextureAtlas atlas;
private SpriteBatch batch;
private AtlasRegion sword,shield,staff,fireball,iceball;
private Sprite sprSword,sprShield,sprStaff,sprFireball,sprIceball;
@Override
public void create() {
    atlas = new TextureAtlas(Gdx.files.internal("data/wizardpack.pack"));
    batch = new SpriteBatch();
    sword = atlas.findRegion("Sword");
    shield = atlas.findRegion("Shield");
    staff = atlas.findRegion("Staff");
    fireball = atlas.findRegion("flame");
    iceball = atlas.findRegion("icespell");
    sprSword = new Sprite(sword);
    sprShield = new Sprite(shield);
    sprStaff = new Sprite(staff);
    sprFireball = new Sprite(fireball);
    sprIceball = new Sprite(iceball);

}

public void renderBlocks(){
    Gdx.gl20.glClearColor(0, 0, 05, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(sword, 0, 0, 0, 0, 32, 32, 1, 1, 0);
    //sprShield.setBounds(15, 15, 32, 32);
//  sprShield.draw(batch);
    batch.end();
}
public void dispose(){
    atlas.dispose();
    batch.dispose();
}

}

我修復了:D對renderBlocks的調用必須在批處理結束之后進行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM