3

子エンティティにAlphaを設定するのに問題があります。Rectangleエンティティを作成し、次のようにTextエンティティを長方形にアタッチします。

m_background = new Rectangle(0.0f, 0.0f, m_activity.getCamera().getWidth(), m_activity.getCamera().getHeight(), m_activity.getVertexBufferObjectManager());
m_background.setColor(0.0f, 0.0f, 0.0f);

FontFactory.setAssetBasePath("font/");

final ITexture fontTexture = new BitmapTextureAtlas(m_activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
this.m_Font = FontFactory.createFromAsset(m_activity.getFontManager(), fontTexture, m_activity.getAssets(), "Droid.ttf", 48, true, android.graphics.Color.WHITE);
this.m_Font.load();

Text text = new Text(100, 300, this.m_Font, "LoadingScreen", new TextOptions(HorizontalAlign.RIGHT), m_activity.getVertexBufferObjectManager());
    m_background.attachChild(text);

ここで、このバックグラウンドエンティティのアルファを0に設定します。

m_background.setAlpha(0.0f);

子の実体も影響を受けるという印象を受けましたが、そうではありませんか?子エンティティに直接アルファを設定する以外に、これを行うにはどうすればよいですか?もっと良い方法はありますか?

よろしくお願いします、Zerd

4

1 に答える 1

5

残念ながらいいえ、子エンティティはその親の位置によってのみ影響を受けます (アタッチされています)。テキストを含む Rectangle が必要で、両方にアルファ変更を適用する場合は、テキストにもアルファを適用するか、その概念をより頻繁に使用して、アルファ チャネルを変更する以外に他のことを行います。独自のクラスを作成します。

このようなものかもしれません:

public class Background extends Entity {

    private Text text;

    public Background(float x, float y, float width, float height, Font font, String textMessage, VertexBufferObjectManager vertexBufferObjectManager) {
         this.setPosition(x, y);
         this.attachChild(new Rectangle(0, 0, width, height, vertexBufferObjectManager));
         this.text = new Text(0, 0, font, textMessage, vertexBufferObjectManager);
         this.attachChild(text);
    }

    @Override
    public void setAlpha(float pAlpha) {        
         super.setAlpha(pAlpha);
         this.text.setAlpha(pAlpha);
    }   
}

これはほんの一例です。四角形をさらに処理する必要がある場合 (サイズ変更など)、四角形とテキストを処理する独自のメソッドを作成するだけです。両方に自動的に適用されるのは位置だけです (ここでは、Text を Rectangle の位置 0,0 に配置します)。

お役に立てれば

  • クリストフ
于 2012-12-13T21:11:22.753 に答える