AndEngine 分析之五-----Scene

Scene:
The Scene class is the root container for all objects to be drawn on the screen. A Scene has a specific amount of Layers, which themselves can contain a (fixed or dynamic) amount of Entities. There are subclasses, like the CameraScene/HUD/MenuScene that are drawing themselves to the same position of the Scene no matter where the camera is positioned to.

 

Scene是屏幕上所有对象的根容器,它有许多的曾用来包含其他实体,它可以有许多特定的子类。

 

一般情况下继承BaseGameActivity的类会覆写onLoadScene()方法

	public Scene onLoadScene() {
		this.mEngine.registerUpdateHandler(new FPSLogger());

		final Scene scene = new Scene(1);
		scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

		final Text textCenter = new Text(100, 60, this.mFont, "Hello AndEngine!\nYou can even have multilined text!", HorizontalAlign.CENTER);
		final Text textLeft = new Text(100, 200, this.mFont, "Also left aligned!\nLorem ipsum dolor sit amat...", HorizontalAlign.LEFT);
		final Text textRight = new Text(100, 340, this.mFont, "And right aligned!\nLorem ipsum dolor sit amat...", HorizontalAlign.RIGHT);

		scene.getTopLayer().addEntity(textCenter);
		scene.getTopLayer().addEntity(textLeft);
		scene.getTopLayer().addEntity(textRight);

		return scene;
	}
 

 

1.Scene构造方法

	public Scene(final int pLayerCount) {
		this.mLayerCount = pLayerCount;
		this.mLayers = new ILayer[pLayerCount];
		this.createLayers();
	}
 

2.创建层

	private void createLayers() {
		final ILayer[] layers = this.mLayers;
		for(int i = this.mLayerCount - 1; i >= 0; i--) {
			layers[i] = new DynamicCapacityLayer();
		}
	}
 

3.获取最上面的层:

	public ILayer getTopLayer() {
		return this.mLayers[this.mLayerCount - 1];
	}

 

 

 

从Scene类上看public class Scene extends Entity {}

 

他继承自Entity,它的层上面又可以添加新的Entity,所以在接受上属于合成模式。

 

 


你可能感兴趣的:(AndEngine)