UNPKG

layaair2-cmd

Version:

layaair version 2 toolkit

1,932 lines (1,768 loc) 3.29 MB
var window = window || global; var document = document || (window.document = {}); /***********************************/ /*http://www.layabox.com 2017/01/16*/ /***********************************/ var Laya=window.Laya=(function(window,document){ var Laya={ __internals:[], __packages:{}, __classmap:{'Object':Object,'Function':Function,'Array':Array,'String':String}, __sysClass:{'object':'Object','array':'Array','string':'String','dictionary':'Dictionary'}, __propun:{writable: true,enumerable: false,configurable: true}, __presubstr:String.prototype.substr, __substr:function(ofs,sz){return arguments.length==1?Laya.__presubstr.call(this,ofs):Laya.__presubstr.call(this,ofs,sz>0?sz:(this.length+sz));}, __init:function(_classs){_classs.forEach(function(o){o.__init$ && o.__init$();});}, __isClass:function(o){return o && (o.__isclass || o==Object || o==String || o==Array);}, __newvec:function(sz,value){ var d=[]; d.length=sz; for(var i=0;i<sz;i++) d[i]=value; return d; }, __extend:function(d,b){ for (var p in b){ if (!b.hasOwnProperty(p)) continue; var gs=Object.getOwnPropertyDescriptor(b, p); var g = gs.get, s = gs.set; if ( g || s ) { if ( g && s) Object.defineProperty(d,p,gs); else{ g && Object.defineProperty(d, p, g); s && Object.defineProperty(d, p, s); } } else d[p] = b[p]; } function __() { Laya.un(this,'constructor',d); }__.prototype=b.prototype;d.prototype=new __();Laya.un(d.prototype,'__imps',Laya.__copy({},b.prototype.__imps)); }, __copy:function(dec,src){ if(!src) return null; dec=dec||{}; for(var i in src) dec[i]=src[i]; return dec; }, __package:function(name,o){ if(Laya.__packages[name]) return; Laya.__packages[name]=true; var p=window,strs=name.split('.'); if(strs.length>1){ for(var i=0,sz=strs.length-1;i<sz;i++){ var c=p[strs[i]]; p=c?c:(p[strs[i]]={}); } } p[strs[strs.length-1]] || (p[strs[strs.length-1]]=o||{}); }, __hasOwnProperty:function(name,o){ o=o ||this; function classHas(name,o){ if(Object.hasOwnProperty.call(o.prototype,name)) return true; var s=o.prototype.__super; return s==null?null:classHas(name,s); } return (Object.hasOwnProperty.call(o,name)) || classHas(name,o.__class); }, __typeof:function(o,value){ if(!o || !value) return false; if(value===String) return (typeof o==='string'); if(value===Number) return (typeof o==='number'); if(value.__interface__) value=value.__interface__; else if(typeof value!='string') return (o instanceof value); return (o.__imps && o.__imps[value]) || (o.__class==value); }, __as:function(value,type){ return (this.__typeof(value,type))?value:null; }, interface:function(name,_super){ Laya.__package(name,{}); var ins=Laya.__internals; var a=ins[name]=ins[name] || {self:name}; if(_super) { var supers=_super.split(','); a.extend=[]; for(var i=0;i<supers.length;i++){ var nm=supers[i]; ins[nm]=ins[nm] || {self:nm}; a.extend.push(ins[nm]); } } var o=window,words=name.split('.'); for(var i=0;i<words.length-1;i++) o=o[words[i]]; o[words[words.length-1]]={__interface__:name}; }, class:function(o,fullName,_super,miniName){ _super && Laya.__extend(o,_super); if(fullName){ Laya.__package(fullName,o); Laya.__classmap[fullName]=o; if(fullName.indexOf('.')>0){ if(fullName.indexOf('laya.')==0){ var paths=fullName.split('.'); miniName=miniName || paths[paths.length-1]; if(Laya[miniName]) console.log("Warning!,this class["+miniName+"] already exist:",Laya[miniName]); Laya[miniName]=o; } } else { if(fullName=="Main") window.Main=o; else{ if(Laya[fullName]){ console.log("Error!,this class["+fullName+"] already exist:",Laya[fullName]); } Laya[fullName]=o; } } } var un=Laya.un,p=o.prototype; un(p,'hasOwnProperty',Laya.__hasOwnProperty); un(p,'__class',o); un(p,'__super',_super); un(p,'__className',fullName); un(o,'__super',_super); un(o,'__className',fullName); un(o,'__isclass',true); un(o,'super',function(o){this.__super.call(o);}); }, imps:function(dec,src){ if(!src) return null; var d=dec.__imps|| Laya.un(dec,'__imps',{}); function __(name){ var c,exs; if(! (c=Laya.__internals[name]) ) return; d[name]=true; if(!(exs=c.extend)) return; for(var i=0;i<exs.length;i++){ __(exs[i].self); } } for(var i in src) __(i); }, getset:function(isStatic,o,name,getfn,setfn){ if(!isStatic){ getfn && Laya.un(o,'_$get_'+name,getfn); setfn && Laya.un(o,'_$set_'+name,setfn); } else{ getfn && (o['_$GET_'+name]=getfn); setfn && (o['_$SET_'+name]=setfn); } if(getfn && setfn) Object.defineProperty(o,name,{get:getfn,set:setfn,enumerable:false}); else{ getfn && Object.defineProperty(o,name,{get:getfn,enumerable:false}); setfn && Object.defineProperty(o,name,{set:setfn,enumerable:false}); } }, static:function(_class,def){ for(var i=0,sz=def.length;i<sz;i+=2){ if(def[i]=='length') _class.length=def[i+1].call(_class); else{ function tmp(){ var name=def[i]; var getfn=def[i+1]; Object.defineProperty(_class,name,{ get:function(){delete this[name];return this[name]=getfn.call(this);}, set:function(v){delete this[name];this[name]=v;},enumerable: true,configurable: true}); } tmp(); } } }, un:function(obj,name,value){ value || (value=obj[name]); Laya.__propun.value=value; Object.defineProperty(obj, name, Laya.__propun); return value; }, uns:function(obj,names){ names.forEach(function(o){Laya.un(obj,o)}); } }; window.console=window.console || ({log:function(){}}); window.trace=window.console.log; Error.prototype.throwError=function(){throw arguments;}; String.prototype.substr=Laya.__substr; Object.defineProperty(Array.prototype,'fixed',{enumerable: false}); return Laya; })(window,document); (function(window,document,Laya){ var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec; Laya.interface('laya.ui.IItem'); Laya.interface('laya.ui.IRender'); Laya.interface('laya.ui.ISelect'); Laya.interface('laya.ui.IComponent'); Laya.interface('laya.runtime.IMarket'); Laya.interface('laya.filters.IFilter'); Laya.interface('laya.display.ILayout'); Laya.interface('laya.editor.core.IClip'); Laya.interface('laya.resource.IDispose'); Laya.interface('laya.runtime.IConchNode'); Laya.interface('laya.ide.viewer.IViewer'); Laya.interface('laya.editor.core.IContent'); Laya.interface('laya.filters.IFilterAction'); Laya.interface('laya.runtime.ICPlatformClass'); Laya.interface('as3analyser.parser.struct.ICodePiece'); Laya.interface('laya.editor.core.Wraps.xml.IXMLElement'); Laya.interface('laya.ui.IBox','laya.ui.IComponent'); /** *@private */ //class laya.utils.RunDriver var RunDriver=(function(){ function RunDriver(){}; __class(RunDriver,'laya.utils.RunDriver'); RunDriver.FILTER_ACTIONS=[]; RunDriver.pixelRatio=-1; RunDriver._charSizeTestDiv=null RunDriver.now=function(){ return Date.now(); } RunDriver.getWindow=function(){ return window; } RunDriver.getPixelRatio=function(){ if (RunDriver.pixelRatio < 0){ var ctx=Browser.context; var backingStore=ctx.backingStorePixelRatio || ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1; RunDriver.pixelRatio=(Browser.window.devicePixelRatio || 1)/ backingStore; if (RunDriver.pixelRatio < 1)RunDriver.pixelRatio=1; } return RunDriver.pixelRatio; } RunDriver.getIncludeStr=function(name){ return null; } RunDriver.createShaderCondition=function(conditionScript){ var fn="(function() {return "+conditionScript+";})"; return Browser.window.eval(fn); } RunDriver.fontMap=[]; RunDriver.measureText=function(txt,font){ var isChinese=RunDriver.hanzi.test(txt); if (isChinese && RunDriver.fontMap[font]){ return RunDriver.fontMap[font]; }; var ctx=Browser.context; ctx.font=font; var r=ctx.measureText(txt); if (isChinese)RunDriver.fontMap[font]=r; return r; } RunDriver.getWebGLContext=function(canvas){ }; RunDriver.beginFlush=function(){ }; RunDriver.endFinish=function(){ }; RunDriver.addToAtlas=null RunDriver.flashFlushImage=function(atlasWebGLCanvas){ }; RunDriver.drawToCanvas=function(sprite,_renderType,canvasWidth,canvasHeight,offsetX,offsetY){ var canvas=HTMLCanvas.create("2D"); var context=new RenderContext(canvasWidth,canvasHeight,canvas); RenderSprite.renders[_renderType]._fun(sprite,context,offsetX,offsetY); return canvas; } RunDriver.createParticleTemplate2D=null RunDriver.createGLTextur=null; RunDriver.createWebGLContext2D=null; RunDriver.changeWebGLSize=function(w,h){ }; RunDriver.createRenderSprite=function(type,next){ return new RenderSprite(type,next); } RunDriver.createFilterAction=function(type){ return new ColorFilterAction(); } RunDriver.createGraphics=function(){ return new Graphics(); } RunDriver.clear=function(value){ Render._context.ctx.clear(); } RunDriver.clearAtlas=function(value){ }; RunDriver.addTextureToAtlas=function(value){ }; RunDriver.getTexturePixels=function(value,x,y,width,height){ return null; } RunDriver.skinAniSprite=function(){ return null; } __static(RunDriver, ['hanzi',function(){return this.hanzi=new RegExp("^[\u4E00-\u9FA5]$");} ]); return RunDriver; })() /** *<code>Laya</code> 是全局对象的引用入口集。 *Laya类引用了一些常用的全局对象,比如Laya.stage:舞台,Laya.timer:时间管理器,Laya.loader:加载管理器,使用时注意大小写。 */ //class Laya var ___Laya=(function(){ //function Laya(){}; /** *表示是否捕获全局错误并弹出提示。默认为false。 *适用于移动设备等不方便调试的时候,设置为true后,如有未知错误,可以弹窗抛出详细错误堆栈。 */ __getset(1,Laya,'alertGlobalError',null,function(value){ var erralert=0; if (value){ Browser.window.onerror=function (msg,url,line,column,detail){ if (erralert++< 5 && detail) alert("出错啦,请把此信息截图给研发商\n"+msg+"\n"+detail.stack); } }else { Browser.window.onerror=null; } }); Laya.init=function(width,height,__plugins){ var plugins=[];for(var i=2,sz=arguments.length;i<sz;i++)plugins.push(arguments[i]); if (Laya._isinit)return; ArrayBuffer.prototype.slice || (ArrayBuffer.prototype.slice=Laya._arrayBufferSlice); Laya._isinit=true; Browser.__init__(); Context.__init__(); Graphics.__init__(); Laya.timer=new Timer(); Laya.loader=new LoaderManager(); for (var i=0,n=plugins.length;i < n;i++){ if (plugins[i].enable)plugins[i].enable(); } Font.__init__(); Style.__init__(); ResourceManager.__init__(); CacheManger.beginCheck(); Laya._currentStage=Laya.stage=new Stage(); Laya.stage.conchModel && Laya.stage.conchModel.setRootNode(); var location=Browser.window.location; var pathName=location.pathname; pathName=pathName.charAt(2)==':' ? pathName.substring(1):pathName; URL.rootPath=URL.basePath=URL.getPath(location.protocol=="file:" ? pathName :location.protocol+"//"+location.host+location.pathname); Laya.render=new Render(0,0); Laya.stage.size(width,height); RenderSprite.__init__(); KeyBoardManager.__init__(); MouseManager.instance.__init__(Laya.stage,Render.canvas); Input.__init__(); SoundManager.autoStopMusic=true; LocalStorage.__init__(); return Render.canvas; } Laya._arrayBufferSlice=function(start,end){ var arr=this; var arrU8List=new Uint8Array(arr,start,end-start); var newU8List=new Uint8Array(arrU8List.length); newU8List.set(arrU8List); return newU8List.buffer; } Laya.stage=null; Laya.timer=null; Laya.loader=null; Laya.version="1.7.8beta"; Laya.render=null Laya._currentStage=null Laya._isinit=false; __static(Laya, ['conchMarket',function(){return this.conchMarket=window.conch?conchMarket:null;},'PlatformClass',function(){return this.PlatformClass=window.PlatformClass;} ]); return Laya; })() /** *... *@author ww */ //class LayaAirCmdTool var LayaAirCmdTool=(function(){ function LayaAirCmdTool(){ this.tarProject="E:/wangwei/bugProjects/testjj/test/laya/.laya"; this.releasemode="normal"; this.appPath=null; this.clear="false"; this.scriptPath=null; this.exportUICode="true"; this.exportRes="true"; LayaAirCmdTool.I=this; this.init(); } __class(LayaAirCmdTool,'LayaAirCmdTool'); var __proto=LayaAirCmdTool.prototype; __proto.init=function(){ SystemSetting.isCMDVer=true; TypeManager.init(); var argv; argv=process.argv;; console.log("argv:",argv); this.parseCMD(argv); CMDShell.init(); FileTools.init2(); this.appPath=this.getAbsPath("./"); OSInfo.init(); Browser.userAgent=OSInfo.type; FileTools.tempApp=FileManager.getPath(OSInfo.env["APPDATA"]||OSInfo.env["HOME"],"LayaAirIDE"); Device.dataPath=FileTools.tempApp; SystemSetting.appPath=this.appPath; SystemSetting.tempPath=FileManager.getAppPath("data"); console.log("appPath:",this.appPath); ExportManager.isCmdVer=true; CodeTplManager.initCodeTpls(); RenderManager.addXMLConfig(this.getAbsPath("data/laya.editorUI.xml")); this.addCustomConfig(this.getAbsPath("data/custom")); this.openProject(this.tarProject,this.releasemode=="release"); } __proto.addCustomConfig=function(path){ if (FileTools.exist(path)){ var files; files=FileTools.getDirFiles(path); console.log("custom files",files); var fileType; var i=0,len=0; len=files.length; var tFile; for (i=0;i < len;i++){ tFile=files[i]; if (FileTools.getExtensionName(tFile)=="xml"){ console.log("add Cumstom config:",tFile); RenderManager.addXMLConfig(FileManager.getPath(path,tFile)); } } } } __proto.getAbsPath=function(path){ return FileManager.getPath(FileTools.getFolder(this.scriptPath),path); } __proto.initConfig=function(){ var configO; configO=FileManager.readJSONFile("./CmdConfig.json"); console.log("configO:",configO); var tAppPath=configO.appPath; tAppPath=FileManager.getPath(FileTools.getFolder(this.scriptPath),tAppPath); console.log("appPath:",tAppPath); this.appPath=tAppPath; } __proto.parseCMD=function(args){ this.scriptPath=args[1]; this.tarProject=args[2]; var i=0,len=0; len=args.length; var tParam; var pArr; for (i=3;i < len;i++){ tParam=args[i]; if (tParam.indexOf("=")> 0){ pArr=tParam.split("="); this[pArr[0]]=pArr[1]; } } } __proto.openProject=function(projectPath,release){ (release===void 0)&& (release=true); DataSheetManager.init(); console.log("openProject:",projectPath); ProjectManager.loadProject(projectPath,null,true); console.log("assetsPath:",SystemSetting.assetsPath); ResFileManager.setPath(SystemSetting.assetsPath); MultiProjectManager.initByMainProject(SystemSetting.workPath); ResStyleManager.init(); PageStyleManager.init(); this.addCustomConfig(FileManager.getWorkPath("laya/custom")); ExportManager.packingEndHandler=Utils.bind(this.packingEnd,this); ExportManager.clearRes=false; var ifExportCode=false; ifExportCode=this.exportUICode !="false"; var ifExportRes=false; ifExportRes=this.exportRes !="false"; if (this.clear !="false"){ if (ifExportCode){ ExportManager.clear(); } ExportManager.clearRes=true; } ExportManager.doExportLater(release,ifExportCode,ifExportRes); } //__JS__("setTimeout(laya.editor.manager.ExportManager.doExportLater,1000,release,ifExportCode,ifExportRes)"); __proto.packingEnd=function(){ console.log("Packing complete"); console.log("All Work complete"); } LayaAirCmdTool.I=null return LayaAirCmdTool; })() /** *... *@author ww */ //class nodetool.NodeJSTools var NodeJSTools=(function(){ function NodeJSTools(){} __class(NodeJSTools,'nodetool.NodeJSTools'); NodeJSTools.require=function(str){ return require(str);; } NodeJSTools.getArgv=function(){ var argv; argv=process.argv;; console.log("argv:",argv); return argv; } NodeJSTools.parseArgToObj=function(args,start,target){ (start===void 0)&& (start=0); var i=0,len=0; len=args.length; var tParam; var pArr; for (i=start;i < len;i++){ tParam=args[i]; if (tParam.indexOf("=")> 0){ pArr=tParam.split("="); if (target[pArr[0]] && typeof(target[pArr[0]])=="number"){ pArr[1]=Sys.mParseFloat(pArr[1]); } console.log(pArr); target[pArr[0]]=pArr[1]; } } } NodeJSTools.getMyPath=function(){ return __dirname; } NodeJSTools.eval=function(codeStr){ return eval(codeStr); } NodeJSTools.excuteFile=function(filePath){ var codeStr; codeStr=FileTools.readFile(filePath); NodeJSTools.eval(codeStr); } NodeJSTools.setTimeout=function(fun,_this,time){ fun=fun.bind(_this); setTimeout(fun,time); } return NodeJSTools; })() /** *Config 用于配置一些全局参数。如需更改,请在初始化引擎之前设置。 */ //class Config var Config=(function(){ function Config(){}; __class(Config,'Config'); Config.WebGLTextCacheCount=500; Config.atlasEnable=false; Config.showCanvasMark=false; Config.animationInterval=50; Config.isAntialias=false; Config.isAlpha=false; Config.premultipliedAlpha=true; Config.isStencil=true; Config.preserveDrawingBuffer=false; return Config; })() /** *<code>EventDispatcher</code> 类是可调度事件的所有类的基类。 */ //class laya.events.EventDispatcher var EventDispatcher=(function(){ var EventHandler; function EventDispatcher(){ this._events=null; } __class(EventDispatcher,'laya.events.EventDispatcher'); var __proto=EventDispatcher.prototype; /** *检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。 *@param type 事件的类型。 *@return 如果指定类型的侦听器已注册,则值为 true;否则,值为 false。 */ __proto.hasListener=function(type){ var listener=this._events && this._events[type]; return !!listener; } /** *派发事件。 *@param type 事件类型。 *@param data (可选)回调数据。<b>注意:</b>如果是需要传递多个参数 p1,p2,p3,...可以使用数组结构如:[p1,p2,p3,...] ;如果需要回调单个参数 p ,且 p 是一个数组,则需要使用结构如:[p],其他的单个参数 p ,可以直接传入参数 p。 *@return 此事件类型是否有侦听者,如果有侦听者则值为 true,否则值为 false。 */ __proto.event=function(type,data){ if (!this._events || !this._events[type])return false; var listeners=this._events[type]; if (listeners.run){ if (listeners.once)delete this._events[type]; data !=null ? listeners.runWith(data):listeners.run(); }else { for (var i=0,n=listeners.length;i < n;i++){ var listener=listeners[i]; if (listener){ (data !=null)? listener.runWith(data):listener.run(); } if (!listener || listener.once){ listeners.splice(i,1); i--; n--; } } if (listeners.length===0 && this._events)delete this._events[type]; } return true; } /** *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。 *@param type 事件的类型。 *@param caller 事件侦听函数的执行域。 *@param listener 事件侦听函数。 *@param args (可选)事件侦听函数的回调参数。 *@return 此 EventDispatcher 对象。 */ __proto.on=function(type,caller,listener,args){ return this._createListener(type,caller,listener,args,false); } /** *使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。 *@param type 事件的类型。 *@param caller 事件侦听函数的执行域。 *@param listener 事件侦听函数。 *@param args (可选)事件侦听函数的回调参数。 *@return 此 EventDispatcher 对象。 */ __proto.once=function(type,caller,listener,args){ return this._createListener(type,caller,listener,args,true); } /**@private */ __proto._createListener=function(type,caller,listener,args,once,offBefore){ (offBefore===void 0)&& (offBefore=true); offBefore && this.off(type,caller,listener,once); var handler=EventHandler.create(caller || this,listener,args,once); this._events || (this._events={}); var events=this._events; if (!events[type])events[type]=handler; else { if (!events[type].run)events[type].push(handler); else events[type]=[events[type],handler]; } return this; } /** *从 EventDispatcher 对象中删除侦听器。 *@param type 事件的类型。 *@param caller 事件侦听函数的执行域。 *@param listener 事件侦听函数。 *@param onceOnly (可选)如果值为 true ,则只移除通过 once 方法添加的侦听器。 *@return 此 EventDispatcher 对象。 */ __proto.off=function(type,caller,listener,onceOnly){ (onceOnly===void 0)&& (onceOnly=false); if (!this._events || !this._events[type])return this; var listeners=this._events[type]; if (listener !=null){ if (listeners.run){ if ((!caller || listeners.caller===caller)&& listeners.method===listener && (!onceOnly || listeners.once)){ delete this._events[type]; listeners.recover(); } }else { var count=0; for (var i=0,n=listeners.length;i < n;i++){ var item=listeners[i]; if (item && (!caller || item.caller===caller)&& item.method===listener && (!onceOnly || item.once)){ count++; listeners[i]=null; item.recover(); } } if (count===n)delete this._events[type]; } } return this; } /** *从 EventDispatcher 对象中删除指定事件类型的所有侦听器。 *@param type (可选)事件类型,如果值为 null,则移除本对象所有类型的侦听器。 *@return 此 EventDispatcher 对象。 */ __proto.offAll=function(type){ var events=this._events; if (!events)return this; if (type){ this._recoverHandlers(events[type]); delete events[type]; }else { for (var name in events){ this._recoverHandlers(events[name]); } this._events=null; } return this; } __proto._recoverHandlers=function(arr){ if (!arr)return; if (arr.run){ arr.recover(); }else { for (var i=arr.length-1;i >-1;i--){ if (arr[i]){ arr[i].recover(); arr[i]=null; } } } } /** *检测指定事件类型是否是鼠标事件。 *@param type 事件的类型。 *@return 如果是鼠标事件,则值为 true;否则,值为 false。 */ __proto.isMouseEvent=function(type){ return EventDispatcher.MOUSE_EVENTS[type]; } EventDispatcher.MOUSE_EVENTS={"rightmousedown":true,"rightmouseup":true,"rightclick":true,"mousedown":true,"mouseup":true,"mousemove":true,"mouseover":true,"mouseout":true,"click":true,"doubleclick":true}; EventDispatcher.__init$=function(){ Object.defineProperty(laya.events.EventDispatcher.prototype,"_events",{enumerable:false,writable:true}); /**@private */ //class EventHandler extends laya.utils.Handler EventHandler=(function(_super){ function EventHandler(caller,method,args,once){ EventHandler.__super.call(this,caller,method,args,once); } __class(EventHandler,'',_super); var __proto=EventHandler.prototype; __proto.recover=function(){ if (this._id > 0){ this._id=0; EventHandler._pool.push(this.clear()); } } EventHandler.create=function(caller,method,args,once){ (once===void 0)&& (once=true); if (EventHandler._pool.length)return EventHandler._pool.pop().setTo(caller,method,args,once); return new EventHandler(caller,method,args,once); } EventHandler._pool=[]; return EventHandler; })(Handler) } return EventDispatcher; })() /** *<p><code>Handler</code> 是事件处理器类。</p> *<p>推荐使用 Handler.create()方法从对象池创建,减少对象创建消耗。创建的 Handler 对象不再使用后,可以使用 Handler.recover()将其回收到对象池,回收后不要再使用此对象,否则会导致不可预料的错误。</p> *<p><b>注意:</b>由于鼠标事件也用本对象池,不正确的回收及调用,可能会影响鼠标事件的执行。</p> */ //class laya.utils.Handler var Handler=(function(){ function Handler(caller,method,args,once){ //this.caller=null; //this.method=null; //this.args=null; this.once=false; this._id=0; (once===void 0)&& (once=false); this.setTo(caller,method,args,once); } __class(Handler,'laya.utils.Handler'); var __proto=Handler.prototype; /** *设置此对象的指定属性值。 *@param caller 执行域(this)。 *@param method 回调方法。 *@param args 携带的参数。 *@param once 是否只执行一次,如果为true,执行后执行recover()进行回收。 *@return 返回 handler 本身。 */ __proto.setTo=function(caller,method,args,once){ this._id=Handler._gid++; this.caller=caller; this.method=method; this.args=args; this.once=once; return this; } /** *执行处理器。 */ __proto.run=function(){ if (this.method==null)return null; var id=this._id; var result=this.method.apply(this.caller,this.args); this._id===id && this.once && this.recover(); return result; } /** *执行处理器,携带额外数据。 *@param data 附加的回调数据,可以是单数据或者Array(作为多参)。 */ __proto.runWith=function(data){ if (this.method==null)return null; var id=this._id; if (data==null) var result=this.method.apply(this.caller,this.args); else if (!this.args && !data.unshift)result=this.method.call(this.caller,data); else if (this.args)result=this.method.apply(this.caller,this.args.concat(data)); else result=this.method.apply(this.caller,data); this._id===id && this.once && this.recover(); return result; } /** *清理对象引用。 */ __proto.clear=function(){ this.caller=null; this.method=null; this.args=null; return this; } /** *清理并回收到 Handler 对象池内。 */ __proto.recover=function(){ if (this._id > 0){ this._id=0; Handler._pool.push(this.clear()); } } Handler.create=function(caller,method,args,once){ (once===void 0)&& (once=true); if (Handler._pool.length)return Handler._pool.pop().setTo(caller,method,args,once); return new Handler(caller,method,args,once); } Handler._pool=[]; Handler._gid=1; return Handler; })() /** *<code>BitmapFont</code> 是位图字体类,用于定义位图字体信息。 */ //class laya.display.BitmapFont var BitmapFont=(function(){ function BitmapFont(){ this._texture=null; this._fontCharDic={}; this._fontWidthMap={}; this._complete=null; this._path=null; this._maxWidth=0; this._spaceWidth=10; this._padding=null; this.fontSize=12; this.autoScaleSize=false; this.letterSpacing=0; } __class(BitmapFont,'laya.display.BitmapFont'); var __proto=BitmapFont.prototype; /** *通过指定位图字体文件路径,加载位图字体文件,加载完成后会自动解析。 *@param path 位图字体文件的路径。 *@param complete 加载并解析完成的回调。 */ __proto.loadFont=function(path,complete){ this._path=path; this._complete=complete; Laya.loader.load([{url:this._path,type:"xml"},{url:this._path.replace(".fnt",".png"),type:"image"}],Handler.create(this,this.onLoaded)); } /** *@private */ __proto.onLoaded=function(){ this.parseFont(Loader.getRes(this._path),Loader.getRes(this._path.replace(".fnt",".png"))); this._complete && this._complete.run(); } /** *解析字体文件。 *@param xml 字体文件XML。 *@param texture 字体的纹理。 */ __proto.parseFont=function(xml,texture){ if (xml==null || texture==null)return; this._texture=texture; var tX=0; var tScale=1; var tInfo=xml.getElementsByTagName("info"); this.fontSize=parseInt(tInfo[0].attributes["size"].nodeValue); var tPadding=tInfo[0].attributes["padding"].nodeValue; var tPaddingArray=tPadding.split(","); this._padding=[parseInt(tPaddingArray[0]),parseInt(tPaddingArray[1]),parseInt(tPaddingArray[2]),parseInt(tPaddingArray[3])]; var chars=xml.getElementsByTagName("char"); var i=0; for (i=0;i < chars.length;i++){ var tAttribute=chars[i].attributes; var tId=parseInt(tAttribute["id"].nodeValue); var xOffset=parseInt(tAttribute["xoffset"].nodeValue)/ tScale; var yOffset=parseInt(tAttribute["yoffset"].nodeValue)/ tScale; var xAdvance=parseInt(tAttribute["xadvance"].nodeValue)/ tScale; var region=new Rectangle(); region.x=parseInt(tAttribute["x"].nodeValue); region.y=parseInt(tAttribute["y"].nodeValue); region.width=parseInt(tAttribute["width"].nodeValue); region.height=parseInt(tAttribute["height"].nodeValue); var tTexture=Texture.create(texture,region.x,region.y,region.width,region.height,xOffset,yOffset); this._maxWidth=Math.max(this._maxWidth,xAdvance+this.letterSpacing); this._fontCharDic[tId]=tTexture; this._fontWidthMap[tId]=xAdvance; } } /** *获取指定字符的字体纹理对象。 *@param char 字符。 *@return 指定的字体纹理对象。 */ __proto.getCharTexture=function(char){ return this._fontCharDic[char.charCodeAt(0)]; } /** *销毁位图字体,调用Text.unregisterBitmapFont 时,默认会销毁。 */ __proto.destroy=function(){ if (this._texture){ for (var p in this._fontCharDic){ var tTexture=this._fontCharDic[p]; if (tTexture)tTexture.destroy(); } this._texture.destroy(); this._fontCharDic=null; this._fontWidthMap=null; this._texture=null; } } /** *设置空格的宽(如果字体库有空格,这里就可以不用设置了)。 *@param spaceWidth 宽度,单位为像素。 */ __proto.setSpaceWidth=function(spaceWidth){ this._spaceWidth=spaceWidth; } /** *获取指定字符的宽度。 *@param char 字符。 *@return 宽度。 */ __proto.getCharWidth=function(char){ var code=char.charCodeAt(0); if (this._fontWidthMap[code])return this._fontWidthMap[code]+this.letterSpacing; if (char==" ")return this._spaceWidth+this.letterSpacing; return 0; } /** *获取指定文本内容的宽度。 *@param text 文本内容。 *@return 宽度。 */ __proto.getTextWidth=function(text){ var tWidth=0; for (var i=0,n=text.length;i < n;i++){ tWidth+=this.getCharWidth(text.charAt(i)); } return tWidth; } /** *获取最大字符宽度。 */ __proto.getMaxWidth=function(){ return this._maxWidth; } /** *获取最大字符高度。 */ __proto.getMaxHeight=function(){ return this.fontSize; } /** *@private *将指定的文本绘制到指定的显示对象上。 */ __proto.drawText=function(text,sprite,drawX,drawY,align,width){ var tWidth=this.getTextWidth(text); var tTexture; var dx=0; align==="center" && (dx=(width-tWidth)/ 2); align==="right" && (dx=(width-tWidth)); var tX=0; for (var i=0,n=text.length;i < n;i++){ tTexture=this.getCharTexture(text.charAt(i)); if (tTexture){ sprite.graphics.drawTexture(tTexture,drawX+tX+dx,drawY); tX+=this.getCharWidth(text.charAt(i)); } } } return BitmapFont; })() /** *@private *<code>Style</code> 类是元素样式定义类。 */ //class laya.display.css.Style var Style=(function(){ function Style(){ this.alpha=1; this.visible=true; this.scrollRect=null; this.blendMode=null; this._type=0; this._tf=Style._TF_EMPTY; } __class(Style,'laya.display.css.Style'); var __proto=Style.prototype; __proto.getTransform=function(){ return this._tf; } __proto.setTransform=function(value){ this._tf=value==='none' || !value ? Style._TF_EMPTY :value; } __proto.setTranslateX=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.translateX=value; } __proto.setTranslateY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.translateY=value; } __proto.setScaleX=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.scaleX=value; } __proto.setScale=function(x,y){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.scaleX=x; this._tf.scaleY=y; } __proto.setScaleY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.scaleY=value; } __proto.setRotate=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.rotate=value; } __proto.setSkewX=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.skewX=value; } __proto.setSkewY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=new TransformInfo()); this._tf.skewY=value; } /**销毁此对象。*/ __proto.destroy=function(){ this.scrollRect=null; } /**@private */ __proto.render=function(sprite,context,x,y){} /**@private */ __proto.getCSSStyle=function(){ return CSSStyle.EMPTY; } /**@private */ __proto._enableLayout=function(){ return false; } /**X 轴缩放值。*/ __getset(0,__proto,'scaleX',function(){ return this._tf.scaleX; },function(value){ this.setScaleX(value); }); /**元素应用的 2D 或 3D 转换的值。该属性允许我们对元素进行旋转、缩放、移动或倾斜。*/ __getset(0,__proto,'transform',function(){ return this.getTransform(); },function(value){ this.setTransform(value); }); /**定义转换,只是用 X 轴的值。*/ __getset(0,__proto,'translateX',function(){ return this._tf.translateX; },function(value){ this.setTranslateX(value); }); /**定义转换,只是用 Y 轴的值。*/ __getset(0,__proto,'translateY',function(){ return this._tf.translateY; },function(value){ this.setTranslateY(value); }); /**Y 轴缩放值。*/ __getset(0,__proto,'scaleY',function(){ return this._tf.scaleY; },function(value){ this.setScaleY(value); }); /**表示元素是否显示为块级元素。*/ __getset(0,__proto,'block',function(){ return (this._type & 0x1)!=0; }); /**定义沿着 Y 轴的 2D 倾斜转换。*/ __getset(0,__proto,'skewY',function(){ return this._tf.skewY; },function(value){ this.setSkewY(value); }); /**定义旋转角度。*/ __getset(0,__proto,'rotate',function(){ return this._tf.rotate; },function(value){ this.setRotate(value); }); /**定义沿着 X 轴的 2D 倾斜转换。*/ __getset(0,__proto,'skewX',function(){ return this._tf.skewX; },function(value){ this.setSkewX(value); }); /**表示元素的左内边距。*/ __getset(0,__proto,'paddingLeft',function(){ return 0; }); /**表示元素的上内边距。*/ __getset(0,__proto,'paddingTop',function(){ return 0; }); /**是否为绝对定位。*/ __getset(0,__proto,'absolute',function(){ return true; }); Style.__init__=function(){ Style._TF_EMPTY=new TransformInfo(); Style.EMPTY=new Style(); } Style.EMPTY=null Style._TF_EMPTY=null return Style; })() /** *@private *<code>Font</code> 类是字体显示定义类。 */ //class laya.display.css.Font var Font=(function(){ function Font(src){ this._type=0; this._weight=0; this._decoration=null; this._text=null; this.indent=0; this._color=Color.create(Font.defaultColor); this.family=Font.defaultFamily; this.stroke=Font._STROKE; this.size=Font.defaultSize; src && src!==Font.EMPTY && src.copyTo(this); } __class(Font,'laya.display.css.Font'); var __proto=Font.prototype; /** *字体样式字符串。 */ __proto.set=function(value){ this._text=null; var strs=value.split(' '); for (var i=0,n=strs.length;i < n;i++){ var str=strs[i]; switch (str){ case 'italic': this.italic=true; continue ; case 'bold': this.bold=true; continue ; } if (str.indexOf('px')> 0){ this.size=parseInt(str); this.family=strs[i+1]; i++; continue ; } } } /** *返回字体样式字符串。 *@return 字体样式字符串。 */ __proto.toString=function(){ this._text="" this.italic && (this._text+="italic "); this.bold && (this._text+="bold "); return this._text+=this.size+"px "+this.family; } /** *将当前的属性值复制到传入的 <code>Font</code> 对象。 *@param dec 一个 Font 对象。 */ __proto.copyTo=function(dec){ dec._type=this._type; dec._text=this._text; dec._weight=this._weight; dec._color=this._color; dec.family=this.family; dec.stroke=this.stroke !=Font._STROKE ? this.stroke.slice():Font._STROKE; dec.indent=this.indent; dec.size=this.size; } /** *表示是否为密码格式。 */ __getset(0,__proto,'password',function(){ return (this._type & 0x400)!==0; },function(value){ value ? (this._type |=0x400):(this._type &=~0x400); }); /** *表示颜色字符串。 */ __getset(0,__proto,'color',function(){ return this._color.strColor; },function(value){ this._color=Color.create(value); }); /** *表示是否为斜体。 */ __getset(0,__proto,'italic',function(){ return (this._type & 0x200)!==0; },function(value){ value ? (this._type |=0x200):(this._type &=~0x200); }); /** *表示是否为粗体。 */ __getset(0,__proto,'bold',function(){ return (this._type & 0x800)!==0; },function(value){ value ? (this._type |=0x800):(this._type &=~0x800); }); /** *文本的粗细。 */ __getset(0,__proto,'weight',function(){ return ""+this._weight; },function(value){ var weight=0; switch (value){ case 'normal': break ; case 'bold': this.bold=true; weight=700; break ; case 'bolder': weight=800; break ; case 'lighter': weight=100; break ; default : weight=parseInt(value); } this._weight=weight; this._text=null; }); /** *规定添加到文本的修饰。 */ __getset(0,__proto,'decoration',function(){ return this._decoration ? this._decoration.value :"none"; },function(value){ var strs=value.split(' '); this._decoration || (this._decoration={}); switch (strs[0]){ case '_': this._decoration.type='underline' break ; case '-': this._decoration.type='line-through' break ; case 'overline': this._decoration.type='overline' break ; default : this._decoration.type=strs[0]; } strs[1] && (this._decoration.color=Color.create(strs)); this._decoration.value=value; }); Font.__init__=function(){ Font.EMPTY=new Font(null); } Font.EMPTY=null Font.defaultColor="#000000"; Font.defaultSize=12; Font.defaultFamily="Arial"; Font.defaultFont="12px Arial"; Font._STROKE=[0,"#000000"]; Font._ITALIC=0x200; Font._PASSWORD=0x400; Font._BOLD=0x800; return Font; })() /** *@private */ //class laya.display.css.TransformInfo var TransformInfo=(function(){ function TransformInfo(){ this.translateX=0; this.translateY=0; this.scaleX=1; this.scaleY=1; this.rotate=0; this.skewX=0; this.skewY=0; } __class(TransformInfo,'laya.display.css.TransformInfo'); return TransformInfo; })() /** *<code>Graphics</code> 类用于创建绘图显示对象。Graphics可以同时绘制多个位图或者矢量图,还可以结合save,restore,transform,scale,rotate,translate,alpha等指令对绘图效果进行变化。 *Graphics以命令流方式存储,可以通过cmds属性访问所有命令流。Graphics是比Sprite更轻量级的对象,合理使用能提高应用性能(比如把大量的节点绘图改为一个节点的Graphics命令集合,能减少大量节点创建消耗)。 *@see laya.display.Sprite#graphics */ //class laya.display.Graphics var Graphics=(function(){ function Graphics(){ //this._sp=null; this._one=null; this._cmds=null; //this._vectorgraphArray=null; //this._graphicBounds=null; this._render=this._renderEmpty; if (Render.isConchNode){ this._nativeObj=new _conchGraphics();; this.id=this._nativeObj.conchID;; } } __class(Graphics,'laya.display.Graphics'); var __proto=Graphics.prototype; /** *<p>销毁此对象。</p> */ __proto.destroy=function(){ this.clear(); if (this._graphicBounds)this._graphicBounds.destroy(); this._graphicBounds=null; this._vectorgraphArray=null; this._sp && (this._sp._renderType=0); this._sp=null; } /** *<p>清空绘制命令。</p> *@param recoverCmds 是否回收绘图指令 */ __proto.clear=function(recoverCmds){ (recoverCmds===void 0)&& (recoverCmds=false); if (recoverCmds){ var tCmd=this._one; if (this._cmds){ var i=0,len=this._cmds.length; for (i=0;i < len;i++){ tCmd=this._cmds[i]; if (tCmd && (tCmd.callee===Render._context._drawTexture || tCmd.callee===Render._context._drawTextureWithTransform)){ tCmd[0]=null; Graphics._cache.push(tCmd); } } this._cmds.length=0; }else if (tCmd){ if (tCmd && (tCmd.callee===Render._context._drawTexture || tCmd.callee===Render._context._drawTextureWithTransform)){ tCmd[0]=null; Graphics._cache.push(tCmd); } } }else { this._cmds=null; } this._one=null; this._render=this._renderEmpty; this._sp && (this._sp._renderType &=~0x01 & ~0x200); this._repaint(); if (this._vectorgraphArray){ for (i=0,len=this._vectorgraphArray.length;i < len;i++){ VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]); } this._vectorgraphArray.length=0; } } /**@private */ __proto._clearBoundsCache=function(){ if (this._graphicBounds)this._graphicBounds.reset(); } /**@private */ __proto._initGraphicBounds=function(){ if (!this._graphicBounds){ this._graphicBounds=new GraphicsBounds(); this._graphicBounds._graphics=this; } } /** *@private *重绘此对象。 */ __proto._repaint=function(){ this._clearBoundsCache(); this._sp && this._sp.repaint(); } /**@private */ __proto._isOnlyOne=function(){ return !this._cmds || this._cmds.length===0; } /** *获取位置及宽高信息矩阵(比较耗CPU,频繁使用会造成卡顿,尽量少用)。 *@param realSize (可选)使用图片的真实大小,默认为false *@return 位置与宽高组成的 一个 Rectangle 对象。 */ __proto.getBounds=function(realSize){ (realSize===void 0)&& (realSize=false); this._initGraphicBounds(); return this._graphicBounds.getBounds(realSize); } /** *@private *@param realSize (可选)使用图片的真实大小,默认为false *获取端点列表。 */ __proto.getBoundPoints=function(realSize){ (realSize===void 0)&& (realSize=false); this._initGraphicBounds(); return this._graphicBounds.getBoundPoints(realSize); } __proto._addCmd=function(a){ this._cmds=this._cmds || []; a.callee=a.shift(); this._cmds.push(a); } /** *绘制纹理。 *@param tex 纹理。 *@param x (可选)X轴偏移量。 *@param y (可选)Y轴偏移量。 *@param width (可选)宽度。 *@param height (可选)高度。 *@param m (可选)矩阵信息。 *@param alpha (可选)透明度。 */ __proto.drawTexture=function(tex,x,y,width,height,m,alpha){ (x===void 0)&& (x=0); (y===void 0)&& (y=0); (width===void 0)&& (width=0); (height===void 0)&& (height=0); (alpha===void 0)&& (alpha=1); if (!tex || alpha < 0.01)return null; if (!width)width=tex.sourceWidth; if (!height)height=tex.sourceHeight; var wRate=width / tex.sourceWidth; var hRate=height / tex.sourceHeight; width=tex.width *wRate; height=tex.height *hRate; if (tex.loaded && (width <=0 || height <=0))return null; x+=tex.offsetX *wRate; y+=tex.offsetY *hRate; this._sp && (this._sp._renderType |=0x200); if (Graphics._cache.length){ var args=Graphics._cache.pop(); args[0]=tex; args[1]=x; args[2]=y; args[3]=width; args[4]=height; args[5]=m; args[6]=alpha; }else { args=[tex,x,y,width,height,m,alpha]; } args.callee=(m || alpha !=1)? Render._context._drawTextureWithTransform :Render._context._drawTexture; if (this._one==null && !m && alpha==1){ this._one=args; this._render=this._renderOneImg; }else { this._saveToCmd(args.callee,args); } if (!tex.loaded){ tex.once("loaded",this,this._textureLoaded,[tex,args]); } this._repaint(); return args; } /** *@private 清理贴图并替换为最新的 *@param tex */ __proto.cleanByTexture=function(tex,x,y,width,height){ (width===void 0)&& (width=0); (height===void 0)&& (height=0); if (!tex)return this.clear(); if (this._one && this._render===this._renderOneImg){ if (!width)width=tex.sourceWidth; if (!height)height=tex.sourceHeight; var wRate=width / tex.sourceWidth; var hRate=height / tex.sourceHeight; width=tex.width *wRate; height=tex.height *hRate; x+=tex.offsetX *wRate; y+=tex.offsetY *hRate; this._one[0]=tex; this._one[1]=x; this._one[2]=y; this._one[3]=width; this._one[4]=height; }else { this.clear(); tex && this.drawTexture(tex,x,y,width,height); } } /** *批量绘制同样纹理。 *@param tex 纹理。 *@param pos 绘制次数和坐标。 */ __proto.drawTextures=function(tex,pos){ if (!tex)return; this._saveToCmd(Render._context._drawTextures,[tex,pos]); } /** *用texture填充。 *@param tex 纹理。 *@param x X轴偏移量。 *@param y Y轴偏移量。 *@param width (可选)宽度。 *@param height (可选)高度。 *@param type (可选)填充类型 repeat|repeat-x|repeat-y|no-repeat *@param offset (可选)贴图纹理偏移 * */ __proto.fillTexture=function(tex,x,y,width,height,type,offset){ (width===void 0)&& (width=0); (height===void 0)&& (height=0); (type===void 0)&& (type="repeat"); if (!tex)return; var args=[tex,x,y,width,height,type,offset || Point.EMPTY,{}]; if (!tex.loaded){ tex.once("loaded",this,this._textureLoaded,[tex,args]); } this._saveToCmd(Render._context._fillTexture,args); } __proto._textureLoaded=function(tex,param){ param[3]=param[3] || tex.width; param[4]=param[4] || tex.height; this._repaint(); } /** *@private *保存到命令流。 */ __proto._saveToCmd=function(fun,args){ this._sp && (this._sp._renderType |=0x200); if (this._one==null){ this._one=args; this._render=this._renderOne; }else { this._sp && (this._sp._renderType &=~0x01); this._render=this._renderAll; (this._cmds || (this._cmds=[])).length===0 && this._cmds.push(this._one); this._cmds.push(args); } args.callee=fun; this._repaint(); return args; } /** *设置剪裁区域,超出剪裁区域的坐标不显示。 *@param x X 轴偏移量。 *@param y Y 轴偏移量。 *@param width 宽度。 *@param height 高度。 */ __proto.clipRect=function(x,y,width,height){ this._saveToCmd(Render._context._clipRect,[x,y,width,height]); } /** *在画布上绘制文本。 *@param text 在画布上输出的文本。 *@param x 开始绘制文本的 x 坐标位置(相对于画布)。 *@param y 开始绘制文本的 y 坐标位置(相对于画布)。 *@param font 定义字号和字体,比如"20px Arial"。 *@param color 定义文本颜色,比如"#ff0000"。 *@param textAlign 文本对齐方式,可选值:"left","center","right"。 */ __proto.fillText=function(text,x,y,font,color,textAlign){ this._saveToCmd(Render._context._fillText,[text,x,y,font || Font.defaultFont,color,textAlign]); } /** *在画布上绘制“被填充且镶边的”文本。 *@param text 在画布上输出的文本。 *@param x 开始绘制文本的 x 坐标位置(相对于画布)。 *@param y 开始绘制文本的 y 坐标位置(相对于画布)。 *@param font 定义字体和字号,比如"20px Arial"。 *@param fillColor 定义文本颜色,比如"#ff0000"。 *@param borderColor 定义镶边文本颜色。 *@param lineWidth 镶边线条宽度。 *@param textAlign 文本对齐方式,可选值:"left","center","right"。 */ __proto.fillBorderText=function(text,x,y,font,fillColor,borderColor,lineWidth,textAlign){ this._saveToCmd(Render._context._fillBorderText,[text,x,y,font || Font.defaultFont,fillColor,borderColor,lineWidth,textAlign]); } /** *在画布上绘制文本(没有填色)。文本的默认颜色是黑色。 *@param text 在画布上输出的文本。 *@param x 开始绘制文本的 x 坐标位置(相对于画布)。 *@param y 开始绘制文本的 y 坐标位置(相对于画布)。 *@param font 定义字体和字号,比如"20px Arial"。 *@param color 定义文本颜色,比如"#ff0000"。 *@param lineWidth 线条宽度。 *@param textAlign 文本对齐方式,可选值:"left","center","right"。 */ __proto.strokeText=function(text,x,y,font,color,lineWidth,textAlign){ this._saveToCmd(Render._context._strokeText,[text,x,y,font || Font.defaultFont,color,lineWidth,textAlign]); } /** *设置透明度。 *@param value 透明度。 */ __proto.alpha=function(value){ this._saveToCmd(Render._context._alpha,[value]); } /** *设置当前透明度。 *@param value 透明度。 */ __proto.setAlpha=function(value){ this._saveToCmd(Render._context._setAlpha,[value]); } /** *替换绘图的当前转换矩阵。 *@param mat 矩阵。 *@param pivotX (可选)水平方向轴心点坐标。 *@param pivotY (可选)垂直方向轴心点坐标。 */ __proto.transform=function(matrix,pivotX,pivotY){ (pivotX===void 0)&& (pivotX=0); (pivotY===void 0)&& (pivotY=0); this._saveToCmd(Render._context._transform,[matrix,pivotX,pivotY]); } /** *旋转当前绘图。(推荐使用transform,性能更高) *@param angle 旋转角度,以弧度计。 *@param pivotX (可选)水平方向轴心点坐标。 *@param pivotY (可选)垂直方向轴心点坐标。 */ __proto.rotate=function(angle,pivotX,pivotY){ (pivotX===void 0)&& (pivotX=0); (pivotY===void 0)&& (pivotY=0); this._saveToCmd(Render._context._rotate,[angle,pivotX,pivotY]); } /** *缩放当前绘图至更大或更小。(推荐使用transform,性能更高) *@param scaleX 水平方向缩放值。 *@param scaleY 垂直方向缩放值。 *@param pivotX (可选)水平方向轴心点坐标。 *@param pivotY (可选)垂直方向轴心点坐标。 */ __proto.scale=function(scaleX,scaleY,pivotX,pivotY){ (pivotX===void 0)&& (pivotX=0); (pivotY===void 0)&& (pivotY=0); this._saveToCmd(Render._context._scale,[scaleX,scaleY,pivotX,pivotY]); } /** *重新映射画布上的 (0,0)位置。 *@param x 添加到水平坐标(x)上的值。 *@param y 添加到垂直坐标(y)上的值。 */ __proto.translate=function(x,y){ this._saveToCmd(Render._context._translate,[x,y]); } /** *保存当前环境的状态。 */ __proto.save=function(){ this._saveToCmd(Render._context._save,[]); } /** *返回之前保存过的路径状态和属性。 */ __proto.restore=function(){ this._saveToCmd(Render._context._restore,[]); } /** *@private *替换文本内容。 *@param text 文本内容。 *@return 替换成功则值为true,否则值为flase。 */ __proto.replaceText=function(text){ this._repaint(); var cmds=this._cmds; if (!cmds){ if (this._one && this._isTextCmd(this._one.callee)){ if (this._one[0].toUpperCase)this._one[0]=text; else this._one[0].setText(text); return true; } }else { for (var i=cmds.length-1;i >-1;i--){ if (this._isTextCmd(cmds[i].callee)){ if (cmds[i][0].toUpperCase)cmds[i][0]=text; else cmds[i][0].setText(text); return true; } } } return false; } /**@private */ __proto._isTextCmd=function(fun){ return fun===Render._context._fillText || fun===Render._context._fillBorderText || fun===Render._context._strokeText; } /** *@private *替换文本颜色。 *@param color 颜色。 */ __proto.replaceTextColor=function(color){ this._repaint(); var cmds=this._cmds; if (!cmds){ if (this._one && this._isTextCmd(this._one.callee)){ this._one[4]=color; if (!this._one[0].toUpperCase)this._one[0].changed=true; } }else { for (var i=cmds.length-1;i >-1;i--){ if (this._isTextCmd(cmds[i].callee)){ cmds[i][4]=color; if (!cmds[i][0].toUpperCase)cmds[i][0].changed=true; } } } } /** *加载并显示一个图片。 *@param url 图片地址。 *@param x (可选)显示图片的x位置。 *@param y (可选)显示图片的y位置。 *@param width (可选)显示图片的宽度,设置为0表示使用图片默认宽度。 *@param height (可选)显示图片的高度,设置为0表示使用图片默认高度。 *@param complete (可选)加载完成回调。 */ __proto.loadImage=function(url,x,y,width,height,complete){ var _$this=this; (x===void 0)&& (x=0); (y===void 0)&& (y=0); (width===void 0)&& (width=0); (height===void 0)&& (height=0); var tex=Loader.getRes(url); if (tex)onloaded(tex); else Laya.loader.load(url,Handler.create(null,onloaded),null,"image"); function onloaded (tex){ if (tex){ _$this.drawTexture(tex,x,y,width,height); if (complete !=null)complete.call(_$this._sp,tex); } } } /** *@private */ __proto._renderEmpty=function(sprite,context,x,y){} /** *@pri