时间:2021-07-01 10:21:17 帮助过:49人阅读
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的使用
var backLayer = new LSprite(); addChild(backLayer); //在sprite上加child backLayer.addChild(mapimg);
3,事件
//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绘图
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,文字与输入框
//文字显示 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,按钮
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");
以上就是用仿ActionScript的语法来编写html5——终篇的内容,更多相关内容请关注PHP中文网(www.gxlcms.com)!