2012-02-19 74 views
0

爲什麼當我添加新的敵人,那不動畫?動畫只有第一個敵人..AndEngine AnimatedSprite動畫只有第一個精靈

private BitmapTextureAtlas EnemyTextureAtlas; 
private TiledTextureRegion enemyTextureRegion; 

EnemyTextureAtlas = new BitmapTextureAtlas(512, 256, TextureOptions.BILINEAR);   
enemyTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(EnemyTextureAtlas, this, "enemy.png", 400, 0, 2, 2); 

private void addEnemy(final float pX, final float pY) 
{ 
    final AnimatedSprite enemy; 
    enemy = new AnimatedSprite(pX, pY, this.enemyTextureRegion); 
    enemy.animate(200); 
    scene.attachChild(enemy); 

} 

回答

1

您需要克隆textureRegion

enemy = new AnimatedSprite(pX, pY, this.enemyTextureRegion.clone()); 
+0

謝謝,但這個我有2個錯誤:'構造函數AnimatedSprite(float,float,Object)未定義' '類型Object中的方法clone()不可見\t Main.java' – user1219517 2012-02-19 21:09:57

+0

好的,我在TiledTextureRegion中釋放了我的克隆函數,現在就工作了。 非常感謝你 – user1219517 2012-02-19 22:07:35

+2

方法clone()被折舊,使用deepCopy()來代替 – Jimmar 2012-02-23 17:03:42

3

enemy = new AnimatedSprite(pX, pY, this.enemyTextureRegion.deepCopy());

,而不是

enemy = new AnimatedSprite(pX, pY, this.enemyTextureRegion.clone());