用SpriteBatch 来画多个Sprite后, 再添加到 Scene中
其中动态添加,就是当成Sprite对象来控制对应的 扩大 和 翻转
静态,就是通过SpriteBatch的draw方法来控制
创建资源 和3里面一样, 所以就 onCreateScene() 修改一下
@Override
protected Scene onCreateScene() {
// TODO Auto-generated method stub
final Scene scene = new Scene();
scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
/* Calculate the coordinates for the face, so its centered on the camera. */
final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
final Sprite faceSprite1 = new Sprite(-50, 0, this.mFaceTextureRegion, this.getVertexBufferObjectManager());
final Sprite faceSprite2 = new Sprite(50, 0, this.mFaceTextureRegion, this.getVertexBufferObjectManager());
faceSprite1.setScale(2);
faceSprite2.setRotation(45);
/* Create the face and add it to the scene. */
//动态的 可以添加对应的sprite对象
final SpriteBatch dynamicSpriteBatch = new DynamicSpriteBatch(this.mBitmapTextureAtlas, 2, this.getVertexBufferObjectManager()) {
@Override
public boolean onUpdateSpriteBatch() {
this.draw(faceSprite1);
this.draw(faceSprite2);
return true;
}
};
//直接通过draw来设置对应的 scale 和 degree
final SpriteBatch staticSpriteBatch = new SpriteBatch(this.mBitmapTextureAtlas, 2, this.getVertexBufferObjectManager());
staticSpriteBatch.draw(this.mFaceTextureRegion, -50, 0, this.mFaceTextureRegion.getWidth(), this.mFaceTextureRegion.getHeight(), 2, 2, 1, 1, 1, 1);
staticSpriteBatch.draw(this.mFaceTextureRegion, 50, 0, this.mFaceTextureRegion.getWidth(), this.mFaceTextureRegion.getHeight(), 45, 1, 1, 1, 1);
staticSpriteBatch.submit();
dynamicSpriteBatch.setPosition(centerX - 100, centerY - 150);
staticSpriteBatch.setPosition(centerX + 100, centerY + 150);
scene.attachChild(dynamicSpriteBatch);
scene.attachChild(staticSpriteBatch);
return scene;
}