canvas教程

CreateJs系列教程之 EaselJs

字号+ 作者:H5之家 来源:H5之家 2015-11-17 17:58 我要评论( )

核心Js代码: var?canvas,????stage,????w?=?window.innerWidth,????h?=?window.innerHeight;function?init()?{????//设置canvas属性????canvas?=?document.getE

标签:

核心Js代码: var canvas,     stage,     w = window.innerWidth,     h = window.innerHeight; function init() {     //设置canvas属性     canvas = document.getElementById(‘game‘);     canvas.width = w;     canvas.height = h;     //创建舞台     stage = new createjs.Stage(canvas);     //绘制居中文字     var text1 = new createjs.Text("Hello World", "20px Arial", "#ff4400"),         bounds = text1.getBounds();     text1.x = stage.canvas.width - bounds.width >> 1;     text1.y = stage.canvas.height - bounds.height >> 1;     //绘制左边文字     var text2 = new createjs.Text("Hello World", "20px Arial", "#ff4400");     //绘制右边文字     var text3 = new createjs.Text("Hello World", "40px Arial", "#ff4400"),         bounds = text3.getBounds();     text3.x = w - bounds.width;     //下居中文字     var text4 = new createjs.Text("Hello World", "20px Arial", "#ff7700"),         bounds = text4.getBounds();     text4.x = stage.canvas.width - bounds.width >> 1;     text4.y = stage.canvas.height - bounds.height;     stage.addChild(text1);     stage.addChild(text2);     stage.addChild(text3);     stage.addChild(text4);     stage.update(); }


说明讲解:

1:绘制舞台类

createjs.Stage(canvas HTML)

2:绘制文字类

createjs.Text(‘text‘, ‘font-size font-family‘, ‘#color‘)

3:获得文字边界属性

Text.getBounds();

其中包含的属性有: width,height等;

4:添加到舞台

stage.addChild(displayObject);

5:更新画板显示出来

 stage.update(); 效果展示:

技术分享


CreateJs系列教程之 EaselJs_1_绘制文字(Text)

标签:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 众创缘 web前端开发,ui设计,seo,网络营销互联网技术学习网站

    众创缘 web前端开发,ui设计,seo,网络营销互联网技术学习网站

    2017-03-29 14:00

  • HTML5游戏开发案例教程 -互联网+职业技能系列

    HTML5游戏开发案例教程 -互联网+职业技能系列

    2017-03-22 17:00

  • SVG学习入门:VML、SVG和Canvas兼容性

    SVG学习入门:VML、SVG和Canvas兼容性

    2017-01-21 12:05

  • 用canvas实现鼠标拖动绘制矩形框

    用canvas实现鼠标拖动绘制矩形框

    2016-12-24 13:05

网友点评