AlloyRenderingEngine
AlloyRenderingEngine燃烧的进度条
写在前面
Github: https://github.com/AlloyTeam/AlloyGameEngine
HTML 5新增了progress标签,那么再去使用AlloyRenderingEngine去模拟进度条是否多余?
不多余。有四大好处:
- 样式更加灵活(想怎么绘制就怎么绘制)
- 跨平台跨浏览器样式更加统一(使用便签,各个浏览器默认样式是五花八门)
- 效果更加酷炫,(比如燃烧的进度条= =!)
- 像素能够统一管理
统一像素管理的好处:
- 更容易的全尺寸缩小和放大(最常见的:全屏游戏)
- 缩小和放大不用操心内部元素错位(只是交给浏览器去进行插值运算)
- 更好的滤镜控制(如游戏中死亡画面,全屏黑白化)
- 更好的移植性和跨平台性(opengl<->canvas2d<->webgl<->opengl等等各种mapping)
上面所列的,对AlloyRenderingEngine所有组件都适用。
演示
组件使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
; ( function () { //注意:当要渲染文字(Text)和图形(Graphics)时,请使用Cavnas渲染 //Progress组件内部使用了Graphics //第二个参数true代表关闭webgl,使用Canvas2d渲染 //如果要使用webgl渲染,请使用Lable渲染文字,Shape渲染矢量图。 var stage = new ARE.Stage( "#ourCanvas" , true ); var progress = new ARE.Progress({ width: 200, height: 20, borderColor: "#3d3d3d" , fillColor: "#black" }) progress.x = 50; progress.y = 50; stage.add(progress); var current = 0, pause = true ; stage.onTick( function () { if (!pause) { current += 0.005; progress.value = current; } }); //进度条的over时,鼠标的形状 progress.cursor = "pointer" ; progress.onClick( function (evt) { //注意这里可以使用evt.stageX来得到相对于舞台(Canvas)的偏移 current = progress.value = (evt.stageX - progress.x) / progress.width; }) var btn = document.querySelector( "#progressBegin" ); //点击按钮,开始进度条开始运行 btn.addEventListener( "click" , function () { pause = false ; }, false ); })(); |
组件原理(看注释)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
; ( function () { //先把要使用类的赋给临时变量,以后就不用打点了:) var Stage = ARE.Stage, Container = ARE.Container, Graphics = ARE.Graphics; //进度条继承自容器 ARE.Progress = Container.extend({ //构造函数 ctor: function (option) { //把容器的属性和方法搞给自己 this ._super(); this .width = option.width; this .height = option.height; this .fillColor = option.fillColor; this .value = option.value||0; //外层边框 this .box = new Graphics() //直接根据传进的宽和高画个矩形 this .box.lineWidth(2).strokeStyle(option.borderColor || "black" ).strokeRect(0, 0, option.width, option.height); //把边框添加到自身(因为自身就是容器,继承自Container,所以有了add方法) this .add( this .box); var barWidth = this .value * option.width - 4; this .bar = new Graphics(); //把bar添加到自身(因为自身就是容器,继承自Container,所以有了add方法) this .add( this .bar); this .bar.fillStyle(option.fillColor || "green" ).fillRect(2, 2, barWidth < 0 ? 0 : barWidth, option.height - 4); //引导的火焰,使用粒子系统去模拟 this .pilot = new ARE.ParticleSystem({ emitX: 0, emitY:0, speed:10, angle: 180, angleRange: 90, emitArea: [1, option.height], texture: "data:image/png;base64\,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=" , filter: [0.63, 0.35, 0.18, 1], emitCount: 1, maxCount: 50 }); this .pilot.y = option.height / 2; //设置火焰色缩放,因为ParticleSystem本身也是继承自容器,所以具备scale属性 //等同于this.pilot.scaleX = this.pilot.scaleY = 0.4; this .pilot.scale = 0.4; //把引导的火焰添加到自身(因为自身就是容器,继承自Container,所以有了add方法) this .add( this .pilot); //监听value的变化,赋值胜于call method ARE.Observe( this , "value" , function (name, value) { if (value >= 1) { //通过maxCount限制粒子的个数,达到关闭火焰的效果 this .pilot.maxCount = 0; this .value = 1; } else { this .pilot.maxCount = 50; this .value = value; } //设置火焰的位置 this .pilot.x = this .value * this .width; var barWidth = this .value * this .width - 4; this .bar.clear().fillStyle( this .fillColor || "green" ).fillRect(2, 2, barWidth < 0 ? 0 : barWidth, this .height - 4); }) } }); })(); |
最新动态请关注Github: https://github.com/AlloyTeam/AlloyGameEngine
AlloyRenderingEngine的更多相关文章
- AlloyRenderingEngine燃烧的进度条
写在前面 Github: https://github.com/AlloyTeam/AlloyGameEngine HTML 5新增了progress标签,那么再去使用AlloyRenderingEn ...
- AlloyRenderingEngine文本框组件
写在前面 Github: https://github.com/AlloyTeam/AlloyGameEngine 在dom元素里,自带了input标签,设置其type为text,它就是一个文本框. ...
- AlloyRenderingEngine继承
写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine然后star一下,多谢支持:). 前几天发了篇向ES6靠齐 ...
- AlloyRenderingEngine之Shape
写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine 然后star一下,多谢支持:). 游戏或者应用中,不是所 ...
- AlloyRenderingEngine入门
写在前面 AlloyRenderingEngine是一款非常快速的渲染引擎,目前该项目已经合并至 https://github.com/AlloyTeam/AlloyGameEngine/ , 属于A ...
- AlloyRenderingEngine开门大吉
快速入口 不读文章可以直接拐向这里: github:https://github.com/AlloyTeam/AlloyRenderingEngine website:http://alloyteam ...
- spritecow改造
快速入口 不读文章可以直接拐向这里: spritecow二代:https://kmdjs.github.io/arejs-tool-sprite/ 写在前面 工欲善其事必先利其器,最近fork了一份s ...
随机推荐
- c# 操作 MongoDB 的 第三方类库 MongoRepository
https://github.com/RobThree/MongoRepository 文档 https://github.com/RobThree/MongoRepository/wiki/Docu ...
- android数据储存之应用安装位置
原文地址:http://developer.android.com/guide/topics/data/install-location.html#Compatiblity 从API8開始,你能够将你 ...
- JS弄ASP.NET(C#)在页GridView信息选择行
做web发展还是新手我,为了之前获得Gridview中间值,它是通过服务器端控件通过第一Gridview将数据保存到服务器,当一个服务器,然后绑定的隐藏字段,在通过的js阅读隐藏字段值,如今,这种方法 ...
- 学习pthreads,创建和终止多线程
更CPU多线程编程,通过笔者的研究发现,,pthreads使用日趋广泛.它是螺纹POSIX标准,它定义了一组线程的创建和操作API. 配置环境见上博客文章.配置环境后,只需要加入#include &l ...
- OAuth在WebApi
OAuth在WebApi中的使用,前后台分离的调用方式 前段时间由于公司架构服务层向WebApi转换,就研究了OAuth在WebApi中的使用,这中间遇到了很多坑,在此记录一下OAuth的正确使用方式 ...
- 开源Math.NET基础数学类库使用(12)C#随机数扩展方法
原文:[原创]开源Math.NET基础数学类库使用(12)C#随机数扩展方法 本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...
- crm操作观点
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; /// <summary> ...
- ng-repeat出现环路输出Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique
采用ng-repeat循环发生错误时,如下面的输出对象: Duplicates in a repeater are not allowed. Use 'track by' expression to ...
- IOS-Plist文件存储(1)
1.什么是一个文件系统? IOS每个应用程序都有自己的文件系统.并且有一个相应的接入,一般分 ~/Documents/ ~/tmp/ ~/Library/Caches/ ~/Library/Prefe ...
- Git--Submodule使用
项目模板中通常由前端保持,所以每次更新模板.我也要跟着变化项目. 随着时间的推移,这不是一个方法来找到,老这么维护.大型项目,更多的模板,真的很容易管理和维护. 然后头让我用submodule前端资源 ...