AndEngine ImageBox實現

 根據自己項目需求的封裝,可支持背景顏色,支持圖片文字。如果有需要,使用TimerHandler可實現文字刷新

import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.camera.hud.HUD;
import org.anddev.andengine.entity.layer.ILayer;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.ChangeableText;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

/**
 * @author Strong Chi
 * 2011-9-11 下午1:42:06
 * 圖片顯示的基本類
 */
public class XDImageBoxBase extends HUD{
	private Sprite mImage;
	private ChangeableText mText;
	private Rectangle mBackgroundRect;
	
	public XDImageBoxBase(final int pX, final int pY, final Camera pCamera, final TextureRegion pImageRegion) {
		this.setCamera(pCamera);
		this.mImage = new Sprite(pX, pY, pImageRegion);
		final ILayer bottomLayer = this.getBottomLayer();
		bottomLayer.addEntity(this.mImage);
		mBackgroundRect = new Rectangle(pX, pY, pImageRegion.getWidth(), pImageRegion.getHeight());
		mBackgroundRect.setColor(0, 0, 0, 0f);
		bottomLayer.addEntity(mBackgroundRect);
	}
	
	public void setColor(float pRed,float pGreen,float pBlue){
		mBackgroundRect.setColor(pRed, pGreen, pBlue);
	}
	
	public void setColor(float pRed,float pGreen,float pBlue, float pAlpha){
		mBackgroundRect.setColor(pRed, pGreen, pBlue, pAlpha);
	}
	
	public void initText(final int pX, final int pY,  final Font pFont, final String pText, final int pLength){
		mText = new ChangeableText(pX, pY, pFont, pText, pLength);
		final ILayer bottomLayer = this.getBottomLayer();
		bottomLayer.addEntity(mText);
	}
	
	public void setText(final String pText){
		mText.setText(pText);
	}


}


 

發佈了35 篇原創文章 · 獲贊 1 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章