这个问题是指andengine GL-ES1。
当您返回壁纸活动或用户在游戏中执行操作时,我无法制作刷新壁纸活动。
我的游戏有两个活动。一方面,您可以编辑和排列房间中的背景元素。在另一个你玩游戏时,它使用与你在第一个活动中安排的元素相同的背景。
还有一个动态壁纸,其中你的房间是背景,人物在它前面移动。
我正在墙纸的 onResume() 中进行更新。
首先,我分离了我之前使用的所有背景精灵。然后我在更新的位置附加新的精灵。
发生的情况是:一些精灵没有出现。
这是方法:你能看出我做错了什么吗?
private void loadBackgroundDecorations() {
//Add new decorations
Log.d(TAG, "loadBackgoundDecorations");
mEngine.runOnUpdateThread(new Runnable() {
@Override
public void run() {
// Remove Old Decorations
Log.d(TAG, "loadBackgoundDecorations: decorationList.size() =" + decorationList.size());
while(decorationList.size() > 0){
Sprite d = decorationList.remove(0);
scene.detachChild(d);
Log.d(TAG, "loadBackgoundDecorations: detachChild");
}
decorationList.clear();
//Add new decorations
ArrayList<Integer> decorations = app.getBackgroundManager().getDecorations();
Log.d(TAG, "loadBackgoundDecorations: decorations.size()" +decorations.size());
for (int i = 0; i < decorations.size(); i+=3) {
Log.d(TAG, "Decoration Values: texture-"+decorations.get(i)+", x-"+decorations.get(1+i)+", y-"+decorations.get(2+i));
Sprite draggable = new Sprite(decorations.get(1+i),decorations.get(2+i),mGameTextureRegionLibrary.get(decorations.get(i)));
draggable.setIgnoreUpdate(true);
scene.attachChild(draggable,0);
decorationList.add(draggable);
Log.d(TAG, "loadBackgoundDecorations: attachChild"+ i);
}
}
});
}
@Override protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
BitmapTextureAtlasTextureRegionFactory.createFromAsset(mTexture, this, app.getAquariumBackground(), 0, 0);
addBubbles();
loadBackgroundDecorations();
addCharacters()
}
============ 更新 ================= 正如一些人在下面建议的那样,我尝试将所有场景设置功能添加到可运行文件中。这没有效果。对我有用的是将“错误”装饰可见属性设置为“假”。但我担心这最终会导致内存泄漏,因为越来越多的精灵副本被隐藏在墙纸上。仅当我调用“detachChild”时才存在问题。出于某种原因,这似乎阻止了“attachChild”正确触发。有人对可能导致这种情况的原因有任何想法吗?
其他人可以创建一个在 onResume 函数中添加和删除精灵的活动吗?