2013-02-26 2 views
1

AndEngine을 사용한 일부 안드로이드 프로그래밍을 해왔으며 Hashtables로 어떤 이상한 일이 발생했습니다.AndEngine이 포함 된 Java Hashtable

나는이 할 기본적 경우 : 미세

 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()의 반환 값을 피하는지를 잘 모르겠습니다.

답변

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); 
+0

나는 본다! 고마워. –