安卓版Canvas渲染引擎——hEngine入门,初始化引擎,并创建基本的显示对象。
1、下载源码包
2、使用安卓开发工具(比如eclipse)创建一个安卓项目。
3、将源码包中的hEngine.jar复制到项目的bin文件夹下。
4、在onCreate方法中添加代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo01);
//初始化引擎和stage
HEngine hengine=new HEngine(this);
setContentView(hengine);
HStage stage=hengine.stage;
stage.frameRate=30;
//添加位图(HBitmap)
Bitmap bmp=BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_launcher);
HBitmap hbmp=new HBitmap(bmp);
stage.addChild(hbmp);
hbmp.x=10;
hbmp.y=10;
//添加文字
HTextField textF=new HTextField();
stage.addChild(textF);
textF.text="山不在高,有仙则名。水不在深,有龙则灵。斯是陋室,惟吾德馨。苔痕上阶绿,草色入帘青。谈笑有鸿儒,往来无白丁。可以调素琴,阅金经。无丝竹之乱耳,无案牍之劳形。南阳诸葛庐,西蜀子云亭。孔子云:何陋之有?";
textF.x=10;
textF.y=300;
textF.width=400;
textF.height=600;
textF.wordWrap=true;
textF.color=Color.RED;
textF.size=30;
textF.lineHeight=45;
//添加矢量图
Path pa=new Path();
Paint pain=new Paint();
pain.setColor(0xffff0000);
pa.addCircle(0, 0, 50, Path.Direction.CCW);
HShape shape=new HShape();
shape.graphics.addPath(pa, pain);
stage.addChild(shape);
shape.x=300;
shape.y=60;
}
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。