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


}


 

你可能感兴趣的:(String,Class,import,float)