新版Andengine引擎包中没有了layer对象,貌似是优化整合了。(如果简单的场景的话,不分层也是没问题的,如果精灵相对不多的话) 但是为了层次清晰,方便管理,有分层效果还是好些的。
精灵是Entity的扩展,
在层中添加精灵。
图示:
方法①:
Entity layer1 = new Entity();
Entity layer2 = new Entity();
Entity layer3 = new Entity();
mScene.attachChild(layer1);
mScene.attachChild(layer2);
mScene.attachChild(layer3);
anyEntity.attachChild(yourSprite);
方法②:
final int FIRST_LAYER = 0;
final int SECOND_LAYER = 1;
private void createLayers()
{
scene.attachChild(new Entity()); // First Layer
scene.attachChild(new Entity()); // Second Layer
}
scene.getChildByIndex(FIRST_LAYER).attachChild(yourEntity);