UNPKG

layaair-js

Version:

An open source HTML5 engine. Edition JavaScript.

1,812 lines (1,665 loc) 767 kB
var window = window || global; var document = document || (window.document = {}); /***********************************/ /*http://www.layabox.com 2016/05/19*/ /***********************************/ 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 g = Object.getOwnPropertyDescriptor(b, p).get, s = Object.getOwnPropertyDescriptor(b, p).set; if ( g || s ) { 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 name=supers[i]; ins[name]=ins[name] || {self:name}; a.extend.push(ins[name]); } } 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(miniName!="Image") //{ 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; })(window,document,Laya); (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.runtime.IMarket'); Laya.interface('laya.filters.IFilter'); Laya.interface('laya.display.ILayout'); Laya.interface('laya.resource.IDispose'); Laya.interface('laya.runtime.IPlatform'); Laya.interface('laya.runtime.IConchNode'); Laya.interface('laya.filters.IFilterAction'); Laya.interface('laya.runtime.ICPlatformClass'); Laya.interface('laya.runtime.IPlatformClass','laya.runtime.IPlatform'); /** *@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 /*__JS__ */Date.now(); } RunDriver.getWindow=function(){ return /*__JS__ */window; } RunDriver.newWebGLContext=function(canvas,webGLName){ return canvas.getContext(webGLName,{stencil:true,alpha:false,antialias:Config.isAntialias,premultipliedAlpha:false}); } 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; } return RunDriver.pixelRatio; } RunDriver.getIncludeStr=function(name){ return null; } RunDriver.createShaderCondition=function(conditionScript){ var fn="(function() {return "+conditionScript+";})"; return Browser.window.eval(fn); } RunDriver.measureText=function(txt,font){ if (Render.isConchApp){ var ctx=/*__JS__ */ConchTextCanvas; ctx.font=font; return ctx.measureText(txt); } if (RunDriver._charSizeTestDiv==null){ RunDriver._charSizeTestDiv=Browser.createElement('div'); RunDriver._charSizeTestDiv.style.cssText="z-index:10000000;padding:0px;position: absolute;left:0px;visibility:hidden;top:0px;background:white"; Browser.container.appendChild(RunDriver._charSizeTestDiv); } RunDriver._charSizeTestDiv.style.font=font; RunDriver._charSizeTestDiv.innerText=txt==" " ? "i" :txt; return {width:RunDriver._charSizeTestDiv.offsetWidth,height:RunDriver._charSizeTestDiv.offsetHeight}; } 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.fillTextureShader=function(value,x,y,width,height){ return null; } RunDriver.skinAniSprite=function(){ return null; } return RunDriver; })() /** *<code>Laya</code> 是全局对象的引用入口集。 */ //class Laya var ___Laya=(function(){ //function Laya(){}; /** *表示是否捕获全局错误并弹出提示。 */ __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]); 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.stageBox=Laya.stage=new Stage(); Laya.stage.model&&Laya.stage.model.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.stage=null; Laya.timer=null; Laya.loader=null; Laya.render=null Laya.version="1.5.2"; Laya.stageBox=null __static(Laya, ['conchMarket',function(){return this.conchMarket=/*__JS__ */window.conch?conchMarket:null;},'PlatformClass',function(){return this.PlatformClass=/*__JS__ */window.PlatformClass;} ]); return Laya; })() /** *Config 用于配置一些全局参数。 */ //class Config var Config=(function(){ function Config(){}; __class(Config,'Config'); Config.WebGLTextCacheCount=500; Config.atlasEnable=false; Config.showCanvasMark=false; Config.CPUMemoryLimit=120 *1024 *1024; Config.GPUMemoryLimit=160 *1024 *1024; Config.animationInterval=50; Config.isAntialias=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。 *@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)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); } __proto._createListener=function(type,caller,listener,args,once){ 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(){ /**@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()方法从对象池创建,减少对象创建消耗。</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.fontSize=12; this.autoScaleSize=false; this._texture=null; this._fontCharDic={}; this._complete=null; this._path=null; this._maxHeight=0; this._maxWidth=0; this._spaceWidth=10; this._leftPadding=0; this._rightPadding=0; 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:/*laya.net.Loader.XML*/"xml"},{url:this._path.replace(".fnt",".png"),type:/*laya.net.Loader.IMAGE*/"image"}],Handler.create(this,this.onLoaded)); } __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(","); var tUpPadding=parseInt(tPaddingArray[0]); var tDownPadding=parseInt(tPaddingArray[2]); this._leftPadding=parseInt(tPaddingArray[3]); this._rightPadding=parseInt(tPaddingArray[1]); 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._maxHeight=Math.max(this._maxHeight,tUpPadding+tDownPadding+tTexture.height); this._maxWidth=Math.max(this._maxWidth,tTexture.width); this._fontCharDic[tId]=tTexture; } if (this.getCharTexture(" "))this.setSpaceWidth(this.getCharWidth(" ")); } /** *获取指定字符的字体纹理对象。 *@param char 字符。 *@return 指定的字体纹理对象。 */ __proto.getCharTexture=function(char){ return this._fontCharDic[char.charCodeAt(0)]; } /** *销毁位图字体,调用Text.unregisterBitmapFont 时,默认会销毁。 */ __proto.destroy=function(){ var tTexture=null; for (var p in this._fontCharDic){ tTexture=this._fontCharDic[p]; if (tTexture)tTexture.destroy(); delete this._fontCharDic[p]; } this._texture.destroy(); } /** *设置空格的宽(如果字体库有空格,这里就可以不用设置了)。 *@param spaceWidth 宽度,单位为像素。 */ __proto.setSpaceWidth=function(spaceWidth){ this._spaceWidth=spaceWidth; } /** *获取指定字符的宽度。 *@param char 字符。 *@return 宽度。 */ __proto.getCharWidth=function(char){ if (char==" ")return this._spaceWidth+this._letterSpacing; var tTexture=this.getCharTexture(char) if (tTexture)return tTexture.width+tTexture.offsetX *2+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+this._letterSpacing; } /** *获取最大字符高度。 */ __proto.getMaxHeight=function(){ return this._maxHeight; } /** *@private *将指定的文本绘制到指定的显示对象上。 */ __proto.drawText=function(text,sprite,drawX,drawY,align,width){ var tWidth=0; var tTexture; for (var i=0,n=text.length;i < n;i++){ tWidth+=this.getCharWidth(text.charAt(i)); }; var dx=this._leftPadding; align==="center" && (dx=(width-tWidth)/ 2); align==="right" && (dx=(width-tWidth)-this._rightPadding); var tX=0; for (i=0,n=text.length;i < n;i++){ tTexture=this.getCharTexture(text.charAt(i)); if (tTexture)sprite.graphics.drawTexture(tTexture,drawX+tX+dx,drawY,tTexture.width,tTexture.height); tX+=this.getCharWidth(text.charAt(i)); } } /** *设置字符之间的间距(以像素为单位)。 */ /** *获取字符之间的间距(以像素为单位)。 */ __getset(0,__proto,'letterSpacing',function(){ return this._letterSpacing; },function(value){ this._letterSpacing=value; }); 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=Style._createTransform()); this._tf.translateX=value; } __proto.setTranslateY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); this._tf.translateY=value; } __proto.setScaleX=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); this._tf.scaleX=value; } __proto.setScaleY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); this._tf.scaleY=value; } __proto.setRotate=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); this._tf.rotate=value; } __proto.setSkewX=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); this._tf.skewX=value; } __proto.setSkewY=function(value){ this._tf===Style._TF_EMPTY && (this._tf=Style._createTransform()); 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=Style._createTransform(); Style.EMPTY=new Style(); } Style._createTransform=function(){ return {translateX:0,translateY:0,scaleX:1,scaleY:1,rotate:0,skewX:0,skewY:0}; } 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; })() /** *<code>Graphics</code> 类用于创建绘图显示对象。 *@see laya.display.Sprite#graphics */ //class laya.display.Graphics var Graphics=(function(){ function Graphics(){ //this._sp=null; this._one=null; this._cmds=null; //this._temp=null; //this._bounds=null; //this._rstBoundPoints=null; //this._vectorgraphArray=null; this._render=this._renderEmpty; this._render=this._renderEmpty; if (Render.isConchNode){ /*__JS__ */this._nativeObj=new _conchGraphics();; /*__JS__ */this.id=this._nativeObj.conchID;; } } __class(Graphics,'laya.display.Graphics'); var __proto=Graphics.prototype; /** *<p>销毁此对象。</p> */ __proto.destroy=function(){ this.clear(); this._temp=null; this._bounds=null; this._rstBoundPoints=null; this._sp && (this._sp._renderType=0); this._sp=null; } /** *<p>清空绘制命令。</p> */ __proto.clear=function(){ this._one=null; this._render=this._renderEmpty; this._cmds=null; this._temp && (this._temp.length=0); this._sp && (this._sp._renderType &=~ /*laya.renders.RenderSprite.IMAGE*/0x01); this._sp && (this._sp._renderType &=~ /*laya.renders.RenderSprite.GRAPHICS*/0x100); this._repaint(); if (this._vectorgraphArray){ for (var i=0,n=this._vectorgraphArray.length;i < n;i++){ VectorGraphManager.getInstance().deleteShape(this._vectorgraphArray[i]); } this._vectorgraphArray.length=0; } } /** *@private *重绘此对象。 */ __proto._repaint=function(){ this._temp && (this._temp.length=0); this._sp && this._sp.repaint(); } /**@private */ __proto._isOnlyOne=function(){ return !this._cmds || this._cmds.length===0; } /** *获取位置及宽高信息矩阵(比较耗,尽量少用)。 *@return 位置与宽高组成的 一个 Rectangle 对象。 */ __proto.getBounds=function(){ if (!this._bounds || !this._temp || this._temp.length < 1){ this._bounds=Rectangle._getWrapRec(this.getBoundPoints(),this._bounds) } return this._bounds; } /** *@private *获取端点列表。 */ __proto.getBoundPoints=function(){ if (!this._temp || this._temp.length < 1) this._temp=this._getCmdPoints(); return this._rstBoundPoints=Utils.copyArray(this._rstBoundPoints,this._temp); } __proto._addCmd=function(a){ this._cmds=this._cmds || []; a.callee=a.shift(); this._cmds.push(a); } __proto._getCmdPoints=function(){ var context=Render._context; var cmds=this._cmds; var rst; rst=this._temp || (this._temp=[]); rst.length=0; if (!cmds && this._one !=null){ Graphics._tempCmds.length=0; Graphics._tempCmds.push(this._one); cmds=Graphics._tempCmds; } if (!cmds) return rst; var matrixs; matrixs=Graphics._tempMatrixArrays; matrixs.length=0; var tMatrix=Graphics._initMatrix; tMatrix.identity(); var tempMatrix=Graphics._tempMatrix; var cmd; for (var i=0,n=cmds.length;i < n;i++){ cmd=cmds[i]; switch (cmd.callee){ case context.save: case 7: matrixs.push(tMatrix); tMatrix=tMatrix.clone(); break ; case context.restore: case 8: tMatrix=matrixs.pop(); break ; case context._scale: case 5: tempMatrix.identity(); tempMatrix.translate(-cmd[2],-cmd[3]); tempMatrix.scale(cmd[0],cmd[1]); tempMatrix.translate(cmd[2],cmd[3]); this._switchMatrix(tMatrix,tempMatrix); break ; case context._rotate: case 3: tempMatrix.identity(); tempMatrix.translate(-cmd[1],-cmd[2]); tempMatrix.rotate(cmd[0]); tempMatrix.translate(cmd[1],cmd[2]); this._switchMatrix(tMatrix,tempMatrix); break ; case context._translate: case 6: tempMatrix.identity(); tempMatrix.translate(cmd[0],cmd[1]); this._switchMatrix(tMatrix,tempMatrix); break ; case context._transform: case 4: tempMatrix.identity(); tempMatrix.translate(-cmd[1],-cmd[2]); tempMatrix.concat(cmd[0]); tempMatrix.translate(cmd[1],cmd[2]); this._switchMatrix(tMatrix,tempMatrix); break ; case 16: case 24: Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[0],cmd[1],cmd[2],cmd[3]),tMatrix); break ; case 17: tMatrix.copyTo(tempMatrix); tempMatrix.concat(cmd[4]); Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[0],cmd[1],cmd[2],cmd[3]),tempMatrix); break ; case context._drawTexture: case context._fillTexture: if (cmd[3] && cmd[4]){ Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[1],cmd[2],cmd[3],cmd[4]),tMatrix); }else { var tex=cmd[0]; Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[1],cmd[2],tex.width,tex.height),tMatrix); } break ; case context._drawTextureWithTransform: tMatrix.copyTo(tempMatrix); tempMatrix.concat(cmd[5]); if (cmd[3] && cmd[4]){ Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[1],cmd[2],cmd[3],cmd[4]),tempMatrix); }else { tex=cmd[0]; Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[1],cmd[2],tex.width,tex.height),tempMatrix); } break ; case context._drawRect: case 13: Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[0],cmd[1],cmd[2],cmd[3]),tMatrix); break ; case context._drawCircle: case context._fillCircle: case 14: Graphics._addPointArrToRst(rst,Rectangle._getBoundPointS(cmd[0]-cmd[2],cmd[1]-cmd[2],cmd[2]+cmd[2],cmd[2]+cmd[2]),tMatrix); break ; case context._drawLine: case 20: Graphics._tempPoints.length=0; var lineWidth=NaN; lineWidth=cmd[5] *0.5; if (cmd[0]==cmd[2]){ Graphics._tempPoints.push(cmd[0]+lineWidth,cmd[1],cmd[2]+lineWidth,cmd[3],cmd[0]-lineWidth,cmd[1],cmd[2]-lineWidth,cmd[3]); }else if (cmd[1]==cmd[3]){ Graphics._tempPoints.push(cmd[0],cmd[1]+lineWidth,cmd[2],cmd[3]+lineWidth,cmd[0],cmd[1]-lineWidth,cmd[2],cmd[3]-lineWidth); }else { Graphics._tempPoints.push(cmd[0],cmd[1],cmd[2],cmd[3]); } Graphics._addPointArrToRst(rst,Graphics._tempPoints,tMatrix); break ; case context._drawCurves: case 22: Graphics._addPointArrToRst(rst,Bezier.I.getBezierPoints(cmd[2]),tMatrix,cmd[0],cmd[1]); break ; case context._drawPoly: case context._drawLines: case 18: Graphics._addPointArrToRst(rst,cmd[2],tMatrix,cmd[0],cmd[1]); break ; case context._drawPath: case 19: Graphics._addPointArrToRst(rst,this._getPathPoints(cmd[2]),tMatrix,cmd[0],cmd[1]); break ; case context._drawPie: case 15: Graphics._addPointArrToRst(rst,this._getPiePoints(cmd[0],cmd[1],cmd[2],cmd[3],cmd[4]),tMatrix); break ; } } if (rst.length > 200){ rst=Utils.copyArray(rst,Rectangle._getWrapRec(rst)._getBoundPoints()); }else if (rst.length > 8) rst=GrahamScan.scanPList(rst); return rst; } __proto._switchMatrix=function(tMatix,tempMatrix){ tempMatrix.concat(tMatix); tempMatrix.copyTo(tMatix); } /** *绘制纹理。 *@param tex 纹理。 *@param x X 轴偏移量。 *@param y Y 轴偏移量。 *@param width 宽度。 *@param height 高度。 *@param m 矩阵信息。 */ __proto.drawTexture=function(tex,x,y,width,height,m,alpha){ (width===void 0)&& (width=0); (height===void 0)&& (height=0); (alpha===void 0)&& (alpha=1); if (!tex)return; if (!width)width=tex.sourceWidth; if (!height)height=tex.sourceHeight; width=width-tex.sourceWidth+tex.width; height=height-tex.sourceHeight+tex.height; if (tex.loaded && (width <=0 || height <=0))return; x+=tex.offsetX; y+=tex.offsetY; this._sp && (this._sp._renderType |=/*laya.renders.RenderSprite.GRAPHICS*/0x100); var 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(/*laya.events.Event.LOADED*/"loaded",this,this._textureLoaded,[tex,args]); } this._repaint(); } /** *批量绘制同样纹理。 *@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]; if (!tex.loaded){ tex.once(/*laya.events.Event.LOADED*/"loaded",this,this._textureLoaded,[tex,args]); } if (Render.isWebGL){ var tFillTextureSprite=RunDriver.fillTextureShader(tex,x,y,width,height); args.push(tFillTextureSprite); } 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 |=/*laya.renders.RenderSprite.GRAPHICS*/0x100); if (this._one==null){ this._one=args; this._render=this._renderOne; }else { this._sp && (this._sp._renderType &=~ /*laya.renders.RenderSprite.IMAGE*/0x01); this._render=this._renderAll; (this._cmds || (this._cmds=[])).length===0 && this._cmds.push(this._one); this._cmds.push(args); } args.callee=fun; this._temp && (this._temp.length=0); 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 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]); } /** *旋转当前绘图。 *@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]); } /** *缩放当前绘图至更大或更小。 *@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,/*laya.net.Loader.IMAGE*/"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){} /** *@private */ __proto._renderAll=function(sprite,context,x,y){ var cmds=this._cmds,cmd; for (var i=0,n=cmds.length;i < n;i++){ (cmd=cmds[i]).callee.call(context,x,y,cmd); } } /** *@private */ __proto._renderOne=function(sprite,context,x,y){ this._one.callee.call(context,x,y,this._one); } /** *@private */ __proto._renderOneImg=function(sprite,context,x,y){ this._one.callee.call(context,x,y,this._one); if (sprite._renderType!==2305){ sprite._renderType |=/*laya.renders.RenderSprite.IMAGE*/0x01; } } /** *绘制一条线。 *@param fromX X 轴开始位置。 *@param fromY Y 轴开始位置。 *@param toX X 轴结束位置。 *@param toY Y 轴结束位置。 *@param lineColor 颜色。 *@param lineWidth 线条宽度。 */ __proto.drawLine=function(fromX,fromY,toX,toY,lineColor,lineWidth){ (lineWidth===void 0)&& (lineWidth=1)