libGDX を使用してタワー ディフェンス ゲームを開発しています。始めたばかりで、パス、「環境」、およびパスに沿って歩いている敵を表示できます。
次のように、SpriteBatch オブジェクトを使用して環境を表示しました。
public LevelController(Level level) {
spriteBach = new SpriteBach();
atlas = new TextureAtlas(Gdx.files.internal("images/textures/textures.pack"));
}
public void setSize() {
spriteBatch.setProjectionMatrix(this.cam.combined);
}
public void render() {
spriteBatch.begin();
drawTowerBases();
spriteBatch.end();
}
private void drawTowerBases() {
// for each tower base (=environment square)
TextureRegion towerBaseTexture = atlas.findRegion("TowerBase");
if(towerBaseTexture != null) {
spriteBatch.draw(towerBaseTexture, x, y, 1f, 1f);
}
}
これは適切に機能しており、テクスチャも適切に表示されています: spriteBatch を使用したタワー ディフェンス
さて、背景をキャッシュできるかどうか疑問に思っていました。常に同じなので、毎回計算する必要はありません。Google 検索で SpriteCache を見つけました。そこで、コードを次のように変更しました。
public LevelController(Level Level) {
spriteCache= new SpriteCache();
atlas = new TextureAtlas(Gdx.files.internal("images/textures/textures.pack"));
spriteCache.beginCache();
this.drawTowerBases();
this.spriteCacheEnvironmentId = spriteCache.endCache();
}
public void setSize() {
this.cam.update();
spriteCache.setProjectionMatrix(this.cam.combined);
}
public void render() {
spriteCache.begin();
spriteCache.draw(this.spriteCacheEnvironmentId);
spriteCache.end();
}
private void drawTowerBases() {
// for each tower base (=environment square)
TextureRegion towerBaseTexture = atlas.findRegion("TowerBase");
if(towerBaseTexture != null) {
spriteCache.add(towerBaseTexture, x, y, 1f, 1f);
}
}
ゲームは次のようになります: spriteCache を使用したタワーディフェンス
私にとっては、透明度が適切にレンダリングされていないようです。透明度のない画像を撮ると、すべてうまくいきます。なぜこれが起こるのか、どうすればこれを修正できるのか、誰にも考えがありますか?
前もって感謝します。