当前位置: 移动技术网 > IT编程>网页制作>Html5 > 用仿ActionScript的语法来编写html5——终篇,LegendForHtml5Programming1.0开源库件

用仿ActionScript的语法来编写html5——终篇,LegendForHtml5Programming1.0开源库件

2018年11月25日  | 移动技术网IT编程  | 我要评论

 

用仿actionscript的语法来编写html5——终篇,legendforhtml5programming1.0开源库件

 

本页面的文字允许在cc-by-sa 3.0协议和gnu自由文档许可证下修改和再使用。

 

 

 

终篇,legendforhtml5programming1.0开源库件

 

 

库件下载地址

https://code.google.com/p/legendforhtml5programming/downloads/list

 

 

一,legendforhtml5programming1.0库件是什么?

它是一个javascript库,它模仿了actionscript的语法,用于html5的开发,目前实现的功能相对较少,还不能称之为引擎,希望将来可以作为html5的开源引擎,为html5开发者提供服务。

 

 

二,legendforhtml5programming1.0库件的构建过程

请参照下面的九篇文章,最终代码和构建过程会有些出入,以为准。

用仿actionscript的语法来编写html5系列文章

 

 

用仿actionscript的语法来编写html5——第一篇,

用仿actionscript的语法来编写html5——第二篇,利用sprite来实现动画

用仿actionscript的语法来编写html5——第三篇,鼠标事件与游戏人物移动

用仿actionscript的语法来编写html5——第四篇,继承与简单的rpg

用仿actionscript的语法来编写html5——第五篇,graphics绘图

用仿actionscript的语法来编写html5——第六篇,textfield与输入框

用仿actionscript的语法来编写html5——第七篇,自定义按钮

用仿actionscript的语法来编写html5——第八篇,图片处理+粒子效果

用仿actionscript的语法来编写html5——第九篇,仿urlloader读取文件

 

 

 

三,legendforhtml5programming1.0库件的使用举例

下面是使用legendforhtml5programming1.0开发的两个简陋的小游戏,只是为了试验,非常简陋,以后会开发几个像样的游戏来做参照。

1,俄罗斯方块

https://fsanguo.comoj.com/html5/jstoas10/

2,抽奖小游戏

https://fsanguo.comoj.com/html5/lottery_html5/

个人感觉,该库件使用起来还是很方便的,尤其上面的俄罗斯方块,我是直接把以前的as代码复制过来,在语法上稍加修改,竟然直接可以运行了

关于游戏的源码,大家点击鼠标右键就可以自己看了,我就不多说了

 

 

四,legendforhtml5programming1.0库件的语法举例

使用前,需要在html中引进legendforhtml5programming1.0库件的legend.js文件,然后在legend.js中配置你的库件所在的位置

 

 

1,显示图片

www.2cto.com

var loader;   

function main(){   

    loader = new lloader();   

    loader.addeventlistener(levent.complete,loadbitmapdata);   

    loader.load("10594855.png","bitmapdata");   

}   

function loadbitmapdata(event){   

    var bitmapdata = new lbitmapdata(loader.content);   

    var bitmap = new lbitmap(bitmapdata);   

    addchild(bitmap);   

}   

//图片的缩放 

bitmapdata = new lbitmapdata(imglist["chara"]); 

showimg2 = new lbitmap(bitmapdata); 

showimg2.scalex = 0.2; 

showimg2.scaley = 0.2; 

//图片的透明度 

bitmapdata = new lbitmapdata(imglist["chara"]); 

showimg3 = new lbitmap(bitmapdata); 

showimg3.alpha = 0.2; 

//图片的旋转 

bitmapdata = new lbitmapdata(imglist["chara"]); 

showimg4 = new lbitmap(bitmapdata); 

showimg4.rotate = 50; 

 

2,sprite的使用

www.2cto.com

var backlayer = new lsprite();   

addchild(backlayer);  

//在sprite上加child 

backlayer.addchild(mapimg);   

 

3,事件

www.2cto.com

//frame事件 

//backlayer.addeventlistener(levent.enter_frame, onframe)   

//鼠标事件 

//backlayer.addeventlistener(lmouseevent.mouse_down, onframe)   

 

鼠标事件可以添加mouse_down,mouse_up,mouse_move

如果你开发的是iphone,ipad或者android,那么该库件会自动将mouse_down,mouse_up,mouse_move转换为touch_start,touch_end,touch_move,无需自己添加touch事件

4,继承

在构造器中调用base(this,lsprite,[]);方法既可实现继承

三个参数分别是自己,要继承的父类,父类构造器的参数

5,graphics绘图

www.2cto.com

backlayer = new lsprite();   

addchild(backlayer);   

//画一圆   

backlayer.graphics.drawrect(1,"black",[20, 20, 150, 20],true,"#cccccc");   

//画一个矩形   

backlayer.graphics.drawarc(2,"black",[100, 100, 50, 0,2*math.pi,false],true,"#ff0000");   

//画一条线   

backlayer.graphics.drawline(2,"#ff0000",[200, 20, 100, 50]);   

 

6,文字与输入框

www.2cto.com

//文字显示   

var txt = new ltextfield();   

txt.x = 100;   

txt.text = "textfield 测试";   

addchild(txt);   

//输入框   

var txt1 = new ltextfield();   

txt1.x = 100;   

txt1.y = 50;   

txt1.settype(ltextfieldtype.input);   

addchild(txt1);   

 

7,按钮

www.2cto.com

function gameinit(event){   

    backlayer = new lsprite();   

    addchild(backlayer);   

       

    btn01 = new lbutton(new lbitmap(new lbitmapdata(imglist["replay_button_up"])),new lbitmap(new lbitmapdata(imglist["replay_button_over"])));   

    btn01.x = 76;   

    btn01.y = 50;   

    backlayer.addchild(btn01);   

       

    btn02 = new lbutton(new lbitmap(new lbitmapdata(imglist["quit_button_up"])),new lbitmap(new lbitmapdata(imglist["quit_button_over"])));   

    btn02.x = 76;   

    btn02.y = 100;   

    backlayer.addchild(btn02);   

       

    btn01.addeventlistener(lmouseevent.mouse_down, onmousedown01);   

    btn02.addeventlistener(lmouseevent.mouse_down, onmousedown02);   

}   

function onmousedown01(event){   

    alert("btn01 on click");   

}   

function onmousedown02(event){   

    alert("btn02 on click");   

}   

 

欢迎大家使用以及提出意见等

 

 


摘自 lufy小屋

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网