1

私はAndEngineでAndroidプログラミングを行っていましたが、Hashtablesでいくつかの奇妙なことに遭遇しました。

基本的に私がこれを行う場合:

        BitmapTextureAtlas m_textureAtlas = new BitmapTextureAtlas(p_baseActivity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    TextureRegion texture1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(m_textureAtlas, p_baseActivity, "Chrysanthemum.jpg", 0, 0);

    m_textureAtlas.load();

    Sprite m_sprite1 = new Sprite(0, 0, texture1, p_baseActivity.getEngine().getVertexBufferObjectManager());
    this.attachChild(m_sprite1);

すべての言葉は大丈夫です。しかし、私がこれを行う場合:

        BitmapTextureAtlas m_textureAtlas = new BitmapTextureAtlas(p_baseActivity.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

    Hashtable<String, TextureRegion> test = new Hashtable<String, TextureRegion>();
    TextureRegion texture1 = test.put("1", BitmapTextureAtlasTextureRegionFactory.createFromAsset(m_textureAtlas, p_baseActivity, "Chrysanthemum.jpg", 0, 0));

    m_textureAtlas.load();

    Sprite m_sprite1 = new Sprite(0, 0, texture1, p_baseActivity.getEngine().getVertexBufferObjectManager());
    this.attachChild(m_sprite1);

それ(画像)がちらつき、寸法がすべて間違っています。今のところ、このプロジェクトの最初のコードセットを実行しても問題ありませんが、何か間違ったことをしているのか、put()の戻り値を完全に回避する必要があるのか​​わかりません。

4

1 に答える 1

2

Hashtable#putこのハッシュテーブルで指定されたキーの以前の値を返します。キーがない場合はnullを返します。あなたの場合、インスタンスを作成したばかりなのでnullです。

例からハッシュテーブルが必要な理由を理解するのは簡単ではありませんが、これは機能します。

    Hashtable<String, TextureRegion> test = new Hashtable<String, TextureRegion>();
    TextureRegion texture1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(m_textureAtlas, p_baseActivity, "Chrysanthemum.jpg", 0, 0);
    test.put("1",  texture1);
于 2013-02-26T09:14:33.427 に答える