AndEngine_example1.4 画SpriteBatch(和libgdx的类似)

用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;
}


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值