game.js 185 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815
  1. var __reflect = (this && this.__reflect) || function (p, c, t) {
  2. p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
  3. };
  4. var __extends = this && this.__extends || function __extends(t, e) {
  5. function r() {
  6. this.constructor = t;
  7. }
  8. for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
  9. r.prototype = e.prototype, t.prototype = new r();
  10. };
  11. //////////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Copyright (c) 2014-present, Egret Technology.
  14. // All rights reserved.
  15. // Redistribution and use in source and binary forms, with or without
  16. // modification, are permitted provided that the following conditions are met:
  17. //
  18. // * Redistributions of source code must retain the above copyright
  19. // notice, this list of conditions and the following disclaimer.
  20. // * Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the distribution.
  23. // * Neither the name of the Egret nor the
  24. // names of its contributors may be used to endorse or promote products
  25. // derived from this software without specific prior written permission.
  26. //
  27. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  28. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  29. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  30. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  33. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  35. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  36. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. //
  38. //////////////////////////////////////////////////////////////////////////////////////
  39. var egret;
  40. (function (egret) {
  41. /**
  42. * The URLLoaderDataFormat class provides values that specify how downloaded data is received.
  43. * @see http://edn.egret.com/cn/docs/page/600 Read different data format
  44. * @version Egret 2.4
  45. * @platform Web,Native
  46. * @includeExample extension/game/net/URLLoaderDataFormat.ts
  47. * @language en_US
  48. */
  49. /**
  50. * URLLoaderDataFormat 类提供了一些用于指定如何接收已下载数据的值。
  51. * @see http://edn.egret.com/cn/docs/page/600 读取不同数据格式
  52. * @version Egret 2.4
  53. * @platform Web,Native
  54. * @includeExample extension/game/net/URLLoaderDataFormat.ts
  55. * @language zh_CN
  56. */
  57. var URLLoaderDataFormat = (function () {
  58. function URLLoaderDataFormat() {
  59. }
  60. /**
  61. * Specify that downloaded data is received as raw binary data.
  62. * @version Egret 2.4
  63. * @platform Web
  64. * @language en_US
  65. */
  66. /**
  67. * 指定以原始二进制数据形式接收下载的数据。
  68. * @version Egret 2.4
  69. * @platform Web
  70. * @language zh_CN
  71. */
  72. URLLoaderDataFormat.BINARY = "binary";
  73. /**
  74. * Specify that downloaded data is received as text.
  75. * @version Egret 2.4
  76. * @platform Web,Native
  77. * @language en_US
  78. */
  79. /**
  80. * 指定以文本形式接收已下载的数据。
  81. * @version Egret 2.4
  82. * @platform Web,Native
  83. * @language zh_CN
  84. */
  85. URLLoaderDataFormat.TEXT = "text";
  86. /**
  87. * Specify that downloaded data is received as URL-encoded variables.
  88. * @version Egret 2.4
  89. * @platform Web,Native
  90. * @language en_US
  91. */
  92. /**
  93. * 指定以 URL 编码变量形式接收下载的数据。
  94. * @version Egret 2.4
  95. * @platform Web,Native
  96. * @language zh_CN
  97. */
  98. URLLoaderDataFormat.VARIABLES = "variables";
  99. /**
  100. * Specify that downloaded data is received as bitmap texture.
  101. * @version Egret 2.4
  102. * @platform Web,Native
  103. * @language en_US
  104. */
  105. /**
  106. * 指定以位图纹理形式接收已下载的数据。
  107. * @version Egret 2.4
  108. * @platform Web,Native
  109. * @language zh_CN
  110. */
  111. URLLoaderDataFormat.TEXTURE = "texture";
  112. /**
  113. * Specify that downloaded data is received as sound.
  114. * @version Egret 2.4
  115. * @platform Web,Native
  116. * @language en_US
  117. */
  118. /**
  119. * 指定以声音形式接收已下载的数据。
  120. * @version Egret 2.4
  121. * @platform Web,Native
  122. * @language zh_CN
  123. */
  124. URLLoaderDataFormat.SOUND = "sound";
  125. return URLLoaderDataFormat;
  126. }());
  127. egret.URLLoaderDataFormat = URLLoaderDataFormat;
  128. __reflect(URLLoaderDataFormat.prototype, "egret.URLLoaderDataFormat");
  129. })(egret || (egret = {}));
  130. //////////////////////////////////////////////////////////////////////////////////////
  131. //
  132. // Copyright (c) 2014-present, Egret Technology.
  133. // All rights reserved.
  134. // Redistribution and use in source and binary forms, with or without
  135. // modification, are permitted provided that the following conditions are met:
  136. //
  137. // * Redistributions of source code must retain the above copyright
  138. // notice, this list of conditions and the following disclaimer.
  139. // * Redistributions in binary form must reproduce the above copyright
  140. // notice, this list of conditions and the following disclaimer in the
  141. // documentation and/or other materials provided with the distribution.
  142. // * Neither the name of the Egret nor the
  143. // names of its contributors may be used to endorse or promote products
  144. // derived from this software without specific prior written permission.
  145. //
  146. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  147. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  148. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  149. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  150. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  151. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  152. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  153. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  154. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  155. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  156. //
  157. //////////////////////////////////////////////////////////////////////////////////////
  158. var egret;
  159. (function (egret) {
  160. /**
  161. * @version Egret 2.4
  162. * @platform Web,Native
  163. * @private
  164. */
  165. var FrameLabel = (function (_super) {
  166. __extends(FrameLabel, _super);
  167. /**
  168. * @version Egret 2.4
  169. * @platform Web,Native
  170. */
  171. function FrameLabel(name, frame /*int*/, end /*int*/) {
  172. var _this = _super.call(this) || this;
  173. _this._name = name;
  174. _this._frame = frame | 0;
  175. if (end)
  176. _this._end = end | 0;
  177. return _this;
  178. }
  179. Object.defineProperty(FrameLabel.prototype, "name", {
  180. /**
  181. * Frame number
  182. * @version Egret 2.4
  183. * @platform Web,Native
  184. * @language en_US
  185. */
  186. /**
  187. * 标签名
  188. * @version Egret 2.4
  189. * @platform Web,Native
  190. * @language zh_CN
  191. */
  192. get: function () {
  193. return this._name;
  194. },
  195. enumerable: true,
  196. configurable: true
  197. });
  198. Object.defineProperty(FrameLabel.prototype, "frame", {
  199. /**
  200. * Frame serial number of the label
  201. * @version Egret 2.4
  202. * @platform Web,Native
  203. * @language en_US
  204. */
  205. /**
  206. * 标签所在帧序号
  207. * @version Egret 2.4
  208. * @platform Web,Native
  209. * @language zh_CN
  210. */
  211. get: function () {
  212. return this._frame;
  213. },
  214. enumerable: true,
  215. configurable: true
  216. });
  217. Object.defineProperty(FrameLabel.prototype, "end", {
  218. /**
  219. * Frame serial number, the end of the label
  220. * @version Egret 2.4
  221. * @platform Web,Native
  222. * @language en_US
  223. */
  224. /**
  225. * 标签对应的结束帧序号
  226. * @version Egret 2.4
  227. * @platform Web,Native
  228. * @language zh_CN
  229. */
  230. get: function () {
  231. return this._end;
  232. },
  233. enumerable: true,
  234. configurable: true
  235. });
  236. /**
  237. * Duplicate the current frame label object
  238. * @version Egret 2.4
  239. * @platform Web,Native
  240. * @language en_US
  241. */
  242. /**
  243. * 复制当前帧标签对象
  244. * @version Egret 2.4
  245. * @platform Web,Native
  246. * @language zh_CN
  247. */
  248. FrameLabel.prototype.clone = function () {
  249. return new FrameLabel(this._name, this._frame, this._end);
  250. };
  251. return FrameLabel;
  252. }(egret.EventDispatcher));
  253. egret.FrameLabel = FrameLabel;
  254. __reflect(FrameLabel.prototype, "egret.FrameLabel");
  255. })(egret || (egret = {}));
  256. //////////////////////////////////////////////////////////////////////////////////////
  257. //
  258. // Copyright (c) 2014-present, Egret Technology.
  259. // All rights reserved.
  260. // Redistribution and use in source and binary forms, with or without
  261. // modification, are permitted provided that the following conditions are met:
  262. //
  263. // * Redistributions of source code must retain the above copyright
  264. // notice, this list of conditions and the following disclaimer.
  265. // * Redistributions in binary form must reproduce the above copyright
  266. // notice, this list of conditions and the following disclaimer in the
  267. // documentation and/or other materials provided with the distribution.
  268. // * Neither the name of the Egret nor the
  269. // names of its contributors may be used to endorse or promote products
  270. // derived from this software without specific prior written permission.
  271. //
  272. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  273. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  274. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  275. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  276. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  277. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  278. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  279. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  280. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  281. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  282. //
  283. //////////////////////////////////////////////////////////////////////////////////////
  284. var egret;
  285. (function (egret) {
  286. /**
  287. * @classdesc 使用 MovieClipData 类,您可以创建 MovieClip 对象和处理 MovieClip 对象的数据。MovieClipData 一般由MovieClipDataFactory生成
  288. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  289. * @version Egret 2.4
  290. * @platform Web,Native
  291. */
  292. var MovieClipData = (function (_super) {
  293. __extends(MovieClipData, _super);
  294. /**
  295. * 创建一个 egret.MovieClipData 对象
  296. * @version Egret 2.4
  297. * @platform Web,Native
  298. */
  299. function MovieClipData() {
  300. var _this = _super.call(this) || this;
  301. /**
  302. * @private
  303. * MovieClip数据
  304. */
  305. _this.$mcData = null;
  306. /**
  307. * 总帧数
  308. * @version Egret 2.4
  309. * @platform Web,Native
  310. */
  311. _this.numFrames = 1;
  312. /**
  313. * 帧数据列表
  314. * @version Egret 2.4
  315. * @platform Web,Native
  316. */
  317. _this.frames = [];
  318. /**
  319. * 帧标签列表
  320. * @version Egret 2.4
  321. * @platform Web,Native
  322. */
  323. _this.labels = null;
  324. /**
  325. * 帧事件列表
  326. * @version Egret 2.4
  327. * @platform Web,Native
  328. */
  329. _this.events = [];
  330. /**
  331. * 帧率
  332. * @version Egret 2.4
  333. * @platform Web,Native
  334. */
  335. _this.frameRate = 0;
  336. /**
  337. * 纹理数据
  338. * @version Egret 2.4
  339. * @platform Web,Native
  340. */
  341. _this.textureData = null;
  342. /**
  343. * 纹理集
  344. * @version Egret 2.4
  345. * @platform Web,Native
  346. */
  347. _this.spriteSheet = null;
  348. return _this;
  349. }
  350. /**
  351. * @private
  352. *
  353. * @param mcData
  354. * @param textureData
  355. * @param spriteSheet
  356. */
  357. MovieClipData.prototype.$init = function (mcData, textureData, spriteSheet) {
  358. this.textureData = textureData;
  359. this.spriteSheet = spriteSheet;
  360. this.setMCData(mcData);
  361. };
  362. /**
  363. * 根据指定帧序号获取该帧对应的关键帧数据
  364. * @param frame {number} 帧序号
  365. * @returns {any} 帧数据对象
  366. * @version Egret 2.4
  367. * @platform Web,Native
  368. */
  369. MovieClipData.prototype.getKeyFrameData = function (frame) {
  370. var outputFrameData = this.frames[frame - 1];
  371. if (outputFrameData.frame) {
  372. outputFrameData = this.frames[outputFrameData.frame - 1];
  373. }
  374. return outputFrameData;
  375. };
  376. /**
  377. * 根据指定帧序号获取该帧对应的Texture对象
  378. * @param frame {number} 帧序号
  379. * @returns {egret.Texture} Texture对象
  380. * @version Egret 2.4
  381. * @platform Web,Native
  382. */
  383. MovieClipData.prototype.getTextureByFrame = function (frame) {
  384. var frameData = this.getKeyFrameData(frame);
  385. if (frameData.res) {
  386. var outputTexture = this.getTextureByResName(frameData.res);
  387. return outputTexture;
  388. }
  389. return null;
  390. };
  391. MovieClipData.prototype.$getOffsetByFrame = function (frame, point) {
  392. var frameData = this.getKeyFrameData(frame);
  393. if (frameData.res) {
  394. point.setTo(frameData.x | 0, frameData.y | 0);
  395. }
  396. };
  397. /**
  398. * @private
  399. *
  400. * @param resName
  401. * @returns
  402. */
  403. MovieClipData.prototype.getTextureByResName = function (resName) {
  404. if (this.spriteSheet == null) {
  405. return null;
  406. }
  407. var texture = this.spriteSheet.getTexture(resName);
  408. if (!texture) {
  409. var textureData = this.textureData[resName];
  410. texture = this.spriteSheet.createTexture(resName, textureData.x, textureData.y, textureData.w, textureData.h);
  411. }
  412. return texture;
  413. };
  414. /**
  415. * @private
  416. *
  417. * @returns
  418. */
  419. MovieClipData.prototype.$isDataValid = function () {
  420. return this.frames.length > 0;
  421. };
  422. /**
  423. * @private
  424. *
  425. * @returns
  426. */
  427. MovieClipData.prototype.$isTextureValid = function () {
  428. return this.textureData != null && this.spriteSheet != null;
  429. };
  430. /**
  431. * @private
  432. *
  433. * @param mcData
  434. */
  435. MovieClipData.prototype.$fillMCData = function (mcData) {
  436. this.frameRate = mcData["frameRate"] || 24;
  437. this.fillFramesData(mcData.frames);
  438. this.fillFrameLabelsData(mcData.labels);
  439. this.fillFrameEventsData(mcData.events);
  440. };
  441. /**
  442. * @private
  443. *
  444. * @param framesData
  445. */
  446. MovieClipData.prototype.fillFramesData = function (framesData) {
  447. var frames = this.frames;
  448. var length = framesData ? framesData.length : 0;
  449. var keyFramePosition;
  450. for (var i = 0; i < length; i++) {
  451. var frameData = framesData[i];
  452. frames.push(frameData);
  453. if (frameData.duration) {
  454. var duration = parseInt(frameData.duration);
  455. if (duration > 1) {
  456. keyFramePosition = frames.length;
  457. for (var j = 1; j < duration; j++) {
  458. frames.push({ "frame": keyFramePosition });
  459. }
  460. }
  461. }
  462. }
  463. this.numFrames = frames.length;
  464. };
  465. /**
  466. * @private
  467. *
  468. * @param frameLabelsData
  469. */
  470. MovieClipData.prototype.fillFrameLabelsData = function (frameLabelsData) {
  471. if (frameLabelsData) {
  472. var length_1 = frameLabelsData.length;
  473. if (length_1 > 0) {
  474. this.labels = [];
  475. for (var i = 0; i < length_1; i++) {
  476. var label = frameLabelsData[i];
  477. this.labels.push(new egret.FrameLabel(label.name, label.frame, label.end));
  478. }
  479. }
  480. }
  481. };
  482. /**
  483. * @private
  484. *
  485. * @param frameEventsData
  486. */
  487. MovieClipData.prototype.fillFrameEventsData = function (frameEventsData) {
  488. if (frameEventsData) {
  489. var length_2 = frameEventsData.length;
  490. if (length_2 > 0) {
  491. this.events = [];
  492. for (var i = 0; i < length_2; i++) {
  493. var events = frameEventsData[i];
  494. this.events[events.frame] = events.name;
  495. }
  496. }
  497. }
  498. };
  499. Object.defineProperty(MovieClipData.prototype, "mcData", {
  500. /**
  501. * @version Egret 2.4
  502. * @platform Web,Native
  503. */
  504. get: function () {
  505. return this.$mcData;
  506. },
  507. /**
  508. * MovieClip数据源
  509. */
  510. set: function (value) {
  511. this.setMCData(value);
  512. },
  513. enumerable: true,
  514. configurable: true
  515. });
  516. /**
  517. * @private
  518. *
  519. * @param value
  520. */
  521. MovieClipData.prototype.setMCData = function (value) {
  522. if (this.$mcData == value) {
  523. return;
  524. }
  525. this.$mcData = value;
  526. if (value) {
  527. this.$fillMCData(value);
  528. }
  529. };
  530. return MovieClipData;
  531. }(egret.HashObject));
  532. egret.MovieClipData = MovieClipData;
  533. __reflect(MovieClipData.prototype, "egret.MovieClipData");
  534. })(egret || (egret = {}));
  535. //////////////////////////////////////////////////////////////////////////////////////
  536. //
  537. // Copyright (c) 2014-present, Egret Technology.
  538. // All rights reserved.
  539. // Redistribution and use in source and binary forms, with or without
  540. // modification, are permitted provided that the following conditions are met:
  541. //
  542. // * Redistributions of source code must retain the above copyright
  543. // notice, this list of conditions and the following disclaimer.
  544. // * Redistributions in binary form must reproduce the above copyright
  545. // notice, this list of conditions and the following disclaimer in the
  546. // documentation and/or other materials provided with the distribution.
  547. // * Neither the name of the Egret nor the
  548. // names of its contributors may be used to endorse or promote products
  549. // derived from this software without specific prior written permission.
  550. //
  551. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  552. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  553. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  554. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  555. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  556. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  557. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  558. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  559. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  560. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  561. //
  562. //////////////////////////////////////////////////////////////////////////////////////
  563. var egret;
  564. (function (egret) {
  565. /**
  566. * @classdesc 使用 MovieClipDataFactory 类,可以生成 MovieClipData 对象用于创建MovieClip
  567. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  568. * @version Egret 2.4
  569. * @platform Web,Native
  570. */
  571. var MovieClipDataFactory = (function (_super) {
  572. __extends(MovieClipDataFactory, _super);
  573. /**
  574. * 创建一个 egret.MovieClipDataFactory 对象
  575. * @param movieClipDataSet {any} MovieClip数据集,该数据集必须由Egret官方工具生成
  576. * @param texture {Texture} 纹理
  577. * @version Egret 2.4
  578. * @platform Web,Native
  579. */
  580. function MovieClipDataFactory(movieClipDataSet, texture) {
  581. var _this = _super.call(this) || this;
  582. /**
  583. * 是否开启缓存
  584. * @version Egret 2.4
  585. * @platform Web,Native
  586. */
  587. _this.enableCache = true;
  588. /**
  589. * @private
  590. */
  591. _this.$mcDataCache = {};
  592. _this.$mcDataSet = movieClipDataSet;
  593. _this.setTexture(texture);
  594. return _this;
  595. }
  596. /**
  597. * 清空缓存
  598. * @version Egret 2.4
  599. * @platform Web,Native
  600. */
  601. MovieClipDataFactory.prototype.clearCache = function () {
  602. this.$mcDataCache = {};
  603. };
  604. /**
  605. * 根据名字生成一个MovieClipData实例。可以用于创建MovieClip。
  606. * @param movieClipName {string} MovieClip名字. 可选参数,默认为"", 相当于取第一个MovieClip数据
  607. * @returns {MovieClipData} 生成的MovieClipData对象
  608. * @version Egret 2.4
  609. * @platform Web,Native
  610. */
  611. MovieClipDataFactory.prototype.generateMovieClipData = function (movieClipName) {
  612. if (movieClipName === void 0) { movieClipName = ""; }
  613. if (movieClipName == "") {
  614. if (this.$mcDataSet) {
  615. for (movieClipName in this.$mcDataSet.mc) {
  616. break;
  617. }
  618. }
  619. }
  620. if (movieClipName == "") {
  621. return null;
  622. }
  623. var output = this.findFromCache(movieClipName, this.$mcDataCache);
  624. if (!output) {
  625. output = new egret.MovieClipData();
  626. this.fillData(movieClipName, output, this.$mcDataCache);
  627. }
  628. return output;
  629. };
  630. /**
  631. * @private
  632. *
  633. * @param movieClipName
  634. * @param cache
  635. * @returns
  636. */
  637. MovieClipDataFactory.prototype.findFromCache = function (movieClipName, cache) {
  638. if (this.enableCache && cache[movieClipName]) {
  639. return cache[movieClipName];
  640. }
  641. return null;
  642. };
  643. /**
  644. * @private
  645. *
  646. * @param movieClipName
  647. * @param movieClip
  648. * @param cache
  649. */
  650. MovieClipDataFactory.prototype.fillData = function (movieClipName, movieClip, cache) {
  651. if (this.$mcDataSet) {
  652. var mcData = this.$mcDataSet.mc[movieClipName];
  653. if (mcData) {
  654. movieClip.$init(mcData, this.$mcDataSet.res, this.$spriteSheet);
  655. if (this.enableCache) {
  656. cache[movieClipName] = movieClip;
  657. }
  658. }
  659. }
  660. };
  661. Object.defineProperty(MovieClipDataFactory.prototype, "mcDataSet", {
  662. /**
  663. * MovieClip数据集
  664. * @version Egret 2.4
  665. * @platform Web,Native
  666. */
  667. get: function () {
  668. return this.$mcDataSet;
  669. },
  670. set: function (value) {
  671. this.$mcDataSet = value;
  672. },
  673. enumerable: true,
  674. configurable: true
  675. });
  676. Object.defineProperty(MovieClipDataFactory.prototype, "texture", {
  677. /**
  678. * MovieClip需要使用的纹理图
  679. */
  680. set: function (value) {
  681. this.setTexture(value);
  682. },
  683. enumerable: true,
  684. configurable: true
  685. });
  686. Object.defineProperty(MovieClipDataFactory.prototype, "spriteSheet", {
  687. /**
  688. * 由纹理图生成的精灵表
  689. * @version Egret 2.4
  690. * @platform Web,Native
  691. */
  692. get: function () {
  693. return this.$spriteSheet;
  694. },
  695. enumerable: true,
  696. configurable: true
  697. });
  698. /**
  699. * @private
  700. *
  701. * @param value
  702. */
  703. MovieClipDataFactory.prototype.setTexture = function (value) {
  704. this.$spriteSheet = value ? new egret.SpriteSheet(value) : null;
  705. };
  706. return MovieClipDataFactory;
  707. }(egret.EventDispatcher));
  708. egret.MovieClipDataFactory = MovieClipDataFactory;
  709. __reflect(MovieClipDataFactory.prototype, "egret.MovieClipDataFactory");
  710. })(egret || (egret = {}));
  711. //////////////////////////////////////////////////////////////////////////////////////
  712. //
  713. // Copyright (c) 2014-present, Egret Technology.
  714. // All rights reserved.
  715. // Redistribution and use in source and binary forms, with or without
  716. // modification, are permitted provided that the following conditions are met:
  717. //
  718. // * Redistributions of source code must retain the above copyright
  719. // notice, this list of conditions and the following disclaimer.
  720. // * Redistributions in binary form must reproduce the above copyright
  721. // notice, this list of conditions and the following disclaimer in the
  722. // documentation and/or other materials provided with the distribution.
  723. // * Neither the name of the Egret nor the
  724. // names of its contributors may be used to endorse or promote products
  725. // derived from this software without specific prior written permission.
  726. //
  727. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  728. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  729. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  730. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  731. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  732. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  733. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  734. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  735. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  736. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  737. //
  738. //////////////////////////////////////////////////////////////////////////////////////
  739. var egret;
  740. (function (egret) {
  741. /**
  742. * When the movieClip's current frame have a frameLabel, dispatches MovieClipEvent object. FrameLabel Event type: MovieClipEvent.FRAME_LABEL
  743. * @version Egret 2.4
  744. * @platform Web,Native
  745. * @language en_US
  746. */
  747. /**
  748. * 当动画的当前帧有事件,将调度 MovieClipEvent 对象。帧事件类型 MovieClipEvent.FRAME_LABEL.
  749. * @version Egret 2.4
  750. * @platform Web,Native
  751. * @language zh_CN
  752. */
  753. var MovieClipEvent = (function (_super) {
  754. __extends(MovieClipEvent, _super);
  755. /**
  756. * TextEvent create an object that contains information about movieClip events.
  757. * @param type Type of event, you can access the MovieClipEvent.type.
  758. * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
  759. * @param cancelable Determine whether the Event object can be canceled. The default value is false.
  760. * @param frameLabel When the current frame have a frameLabel, the event listeners can access this information through the frameLabel property.
  761. * @version Egret 2.4
  762. * @platform Web,Native
  763. * @language en_US
  764. */
  765. /**
  766. * 创建一个 MovieClipEvent 对象,其中包含有关帧事件的信息。
  767. * @param type 事件的类型,可以作为 MovieClipEvent.type 访问。
  768. * @param bubbles 确定 Event 对象是否参与事件流的冒泡阶段。默认值为 false。
  769. * @param cancelable 确定是否可以取消 Event 对象。默认值为 false。
  770. * @param frameLabel 动画上的帧事件。事件侦听器可以通过 frameLabel 属性访问此信息。
  771. * @version Egret 2.4
  772. * @platform Web,Native
  773. * @language zh_CN
  774. */
  775. function MovieClipEvent(type, bubbles, cancelable, frameLabel) {
  776. if (bubbles === void 0) { bubbles = false; }
  777. if (cancelable === void 0) { cancelable = false; }
  778. if (frameLabel === void 0) { frameLabel = null; }
  779. var _this = _super.call(this, type, bubbles, cancelable) || this;
  780. /**
  781. * In MovieClipEvent.FRAME_LABEL event, event corresponding string.
  782. * @version Egret 2.4
  783. * @platform Web,Native
  784. * @language en_US
  785. */
  786. /**
  787. * 在 MovieClipEvent.FRAME_LABEL 事件中,event对应的字符串。
  788. * @version Egret 2.4
  789. * @platform Web,Native
  790. * @language zh_CN
  791. */
  792. _this.frameLabel = null;
  793. _this.frameLabel = frameLabel;
  794. return _this;
  795. }
  796. /**
  797. * EventDispatcher object using the specified event object thrown MovieClipEvent. The objects will be thrown in the object cache pool for the next round robin.
  798. * @param type The type of the event, accessible as Event.type.
  799. * @param bubbles Determines whether the Event object participates in the bubbling stage of the event flow. The default value is false.
  800. * @param frameLabel MovieClipEvent object frameLabel
  801. * @version Egret 2.4
  802. * @platform Web,Native
  803. * @language en_US
  804. */
  805. /**
  806. * 使用指定的EventDispatcher对象来抛出 MovieClipEvent 事件对象。抛出的对象将会缓存在对象池上,供下次循环复用。
  807. * @param target 派发事件目标
  808. * @param type 事件类型
  809. * @param frameLabel MovieClipEvent 对象的 frameLabel 赋值
  810. * @version Egret 2.4
  811. * @platform Web,Native
  812. * @language zh_CN
  813. */
  814. MovieClipEvent.dispatchMovieClipEvent = function (target, type, frameLabel) {
  815. if (frameLabel === void 0) { frameLabel = null; }
  816. var event = egret.Event.create(MovieClipEvent, type);
  817. event.frameLabel = frameLabel;
  818. var result = target.dispatchEvent(event);
  819. egret.Event.release(event);
  820. return result;
  821. };
  822. /**
  823. * Dispatched whenever the current frame have a frameLabel.
  824. * @version Egret 2.4
  825. * @platform Web,Native
  826. * @language en_US
  827. */
  828. /**
  829. * 动画的当前帧上有事件时调度
  830. * @version Egret 2.4
  831. * @platform Web,Native
  832. * @language zh_CN
  833. */
  834. MovieClipEvent.FRAME_LABEL = "frame_label";
  835. return MovieClipEvent;
  836. }(egret.Event));
  837. egret.MovieClipEvent = MovieClipEvent;
  838. __reflect(MovieClipEvent.prototype, "egret.MovieClipEvent");
  839. })(egret || (egret = {}));
  840. //////////////////////////////////////////////////////////////////////////////////////
  841. //
  842. // Copyright (c) 2014-present, Egret Technology.
  843. // All rights reserved.
  844. // Redistribution and use in source and binary forms, with or without
  845. // modification, are permitted provided that the following conditions are met:
  846. //
  847. // * Redistributions of source code must retain the above copyright
  848. // notice, this list of conditions and the following disclaimer.
  849. // * Redistributions in binary form must reproduce the above copyright
  850. // notice, this list of conditions and the following disclaimer in the
  851. // documentation and/or other materials provided with the distribution.
  852. // * Neither the name of the Egret nor the
  853. // names of its contributors may be used to endorse or promote products
  854. // derived from this software without specific prior written permission.
  855. //
  856. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  857. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  858. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  859. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  860. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  861. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  862. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  863. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  864. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  865. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  866. //
  867. //////////////////////////////////////////////////////////////////////////////////////
  868. var egret;
  869. (function (egret) {
  870. /**
  871. * @private
  872. */
  873. var ScrollEase = (function () {
  874. /**
  875. * @version Egret 2.4
  876. * @platform Web,Native
  877. */
  878. function ScrollEase() {
  879. egret.$error(1014);
  880. }
  881. /**
  882. *
  883. * @param amount
  884. * @returns
  885. * @version Egret 2.4
  886. * @platform Web,Native
  887. */
  888. ScrollEase.get = function (amount) {
  889. if (amount < -1) {
  890. amount = -1;
  891. }
  892. if (amount > 1) {
  893. amount = 1;
  894. }
  895. return function (t) {
  896. if (amount == 0) {
  897. return t;
  898. }
  899. if (amount < 0) {
  900. return t * (t * -amount + 1 + amount);
  901. }
  902. return t * ((2 - t) * amount + (1 - amount));
  903. };
  904. };
  905. /**
  906. *
  907. * @param pow
  908. * @returns
  909. * @version Egret 2.4
  910. * @platform Web,Native
  911. */
  912. ScrollEase.getPowOut = function (pow) {
  913. return function (t) {
  914. return 1 - Math.pow(1 - t, pow);
  915. };
  916. };
  917. /**
  918. * @version Egret 2.4
  919. * @platform Web,Native
  920. */
  921. ScrollEase.quintOut = ScrollEase.getPowOut(5);
  922. /**
  923. * @version Egret 2.4
  924. * @platform Web,Native
  925. */
  926. ScrollEase.quartOut = ScrollEase.getPowOut(4);
  927. return ScrollEase;
  928. }());
  929. egret.ScrollEase = ScrollEase;
  930. __reflect(ScrollEase.prototype, "egret.ScrollEase");
  931. /**
  932. * @private
  933. */
  934. var ScrollTween = (function (_super) {
  935. __extends(ScrollTween, _super);
  936. /**
  937. * 创建一个 egret.ScrollTween 对象
  938. * @private
  939. * @version Egret 2.4
  940. * @platform Web,Native
  941. */
  942. function ScrollTween(target, props, pluginData) {
  943. var _this = _super.call(this) || this;
  944. /**
  945. * @private
  946. */
  947. _this._target = null;
  948. /**
  949. * @private
  950. */
  951. _this._useTicks = false;
  952. /**
  953. * @private
  954. */
  955. _this.ignoreGlobalPause = false;
  956. /**
  957. * @private
  958. */
  959. _this.loop = false;
  960. /**
  961. * @private
  962. */
  963. _this.pluginData = null;
  964. /**
  965. * @private
  966. */
  967. _this._steps = null;
  968. /**
  969. * @private
  970. */
  971. _this._actions = null;
  972. /**
  973. * @private
  974. */
  975. _this.paused = false;
  976. /**
  977. * @private
  978. */
  979. _this.duration = 0;
  980. /**
  981. * @private
  982. */
  983. _this._prevPos = -1;
  984. /**
  985. * @private
  986. */
  987. _this.position = null;
  988. /**
  989. * @private
  990. */
  991. _this._prevPosition = 0;
  992. /**
  993. * @private
  994. */
  995. _this._stepPosition = 0;
  996. /**
  997. * @private
  998. */
  999. _this.passive = false;
  1000. _this.initialize(target, props, pluginData);
  1001. return _this;
  1002. }
  1003. /**
  1004. * Activate an object and add a ScrollTween animation to the object
  1005. * @param target {any} The object to be activated
  1006. * @param props {any} Parameters, support loop onChange onChangeObj
  1007. * @param pluginData {any} Write realized
  1008. * @param override {boolean} Whether to remove the object before adding a tween, the default value false
  1009. * @version Egret 2.4
  1010. * @platform Web,Native
  1011. * @language en_US
  1012. */
  1013. /**
  1014. * 激活一个对象,对其添加 ScrollTween 动画
  1015. * @param target {any} 要激活 ScrollTween 的对象
  1016. * @param props {any} 参数,支持loop(循环播放) onChange(变化函数) onChangeObj(变化函数作用域)
  1017. * @param pluginData {any} 暂未实现
  1018. * @param override {boolean} 是否移除对象之前添加的tween,默认值false
  1019. * @version Egret 2.4
  1020. * @platform Web,Native
  1021. * @language zh_CN
  1022. */
  1023. ScrollTween.get = function (target, props, pluginData, override) {
  1024. if (props === void 0) { props = null; }
  1025. if (pluginData === void 0) { pluginData = null; }
  1026. if (override === void 0) { override = false; }
  1027. if (override) {
  1028. ScrollTween.removeTweens(target);
  1029. }
  1030. return new ScrollTween(target, props, pluginData);
  1031. };
  1032. /**
  1033. * Delete all ScrollTween animations from an object
  1034. * @param target The object whose ScrollTween to be deleted
  1035. * @version Egret 2.4
  1036. * @platform Web,Native
  1037. * @language en_US
  1038. */
  1039. /**
  1040. * 删除一个对象上的全部 ScrollTween 动画
  1041. * @param target 需要移除 ScrollTween 的对象
  1042. * @version Egret 2.4
  1043. * @platform Web,Native
  1044. * @language zh_CN
  1045. */
  1046. ScrollTween.removeTweens = function (target) {
  1047. if (!target.tween_count) {
  1048. return;
  1049. }
  1050. var tweens = ScrollTween._tweens;
  1051. for (var i = tweens.length - 1; i >= 0; i--) {
  1052. if (tweens[i]._target == target) {
  1053. tweens[i].paused = true;
  1054. tweens.splice(i, 1);
  1055. }
  1056. }
  1057. target.tween_count = 0;
  1058. };
  1059. /**
  1060. * @private
  1061. *
  1062. * @param delta
  1063. * @param paused
  1064. */
  1065. ScrollTween.tick = function (timeStamp, paused) {
  1066. if (paused === void 0) { paused = false; }
  1067. var delta = timeStamp - ScrollTween._lastTime;
  1068. ScrollTween._lastTime = timeStamp;
  1069. var tweens = ScrollTween._tweens.concat();
  1070. for (var i = tweens.length - 1; i >= 0; i--) {
  1071. var tween = tweens[i];
  1072. if ((paused && !tween.ignoreGlobalPause) || tween.paused) {
  1073. continue;
  1074. }
  1075. tween.tick(tween._useTicks ? 1 : delta);
  1076. }
  1077. return false;
  1078. };
  1079. /**
  1080. * @private
  1081. *
  1082. * @param tween
  1083. * @param value
  1084. */
  1085. ScrollTween._register = function (tween, value) {
  1086. var target = tween._target;
  1087. var tweens = ScrollTween._tweens;
  1088. if (value) {
  1089. if (target) {
  1090. target.tween_count = target.tween_count > 0 ? target.tween_count + 1 : 1;
  1091. }
  1092. tweens.push(tween);
  1093. if (!ScrollTween._inited) {
  1094. ScrollTween._lastTime = egret.getTimer();
  1095. egret.ticker.$startTick(ScrollTween.tick, null);
  1096. ScrollTween._inited = true;
  1097. }
  1098. }
  1099. else {
  1100. if (target) {
  1101. target.tween_count--;
  1102. }
  1103. var i = tweens.length;
  1104. while (i--) {
  1105. if (tweens[i] == tween) {
  1106. tweens.splice(i, 1);
  1107. return;
  1108. }
  1109. }
  1110. }
  1111. };
  1112. /**
  1113. * @private
  1114. *
  1115. * @param target
  1116. * @param props
  1117. * @param pluginData
  1118. */
  1119. ScrollTween.prototype.initialize = function (target, props, pluginData) {
  1120. this._target = target;
  1121. if (props) {
  1122. this._useTicks = props.useTicks;
  1123. this.ignoreGlobalPause = props.ignoreGlobalPause;
  1124. this.loop = props.loop;
  1125. props.onChange && this.addEventListener("change", props.onChange, props.onChangeObj);
  1126. if (props.override) {
  1127. ScrollTween.removeTweens(target);
  1128. }
  1129. }
  1130. this.pluginData = pluginData || {};
  1131. this._curQueueProps = {};
  1132. this._initQueueProps = {};
  1133. this._steps = [];
  1134. this._actions = [];
  1135. if (props && props.paused) {
  1136. this.paused = true;
  1137. }
  1138. else {
  1139. ScrollTween._register(this, true);
  1140. }
  1141. if (props && props.position != null) {
  1142. this.setPosition(props.position);
  1143. }
  1144. };
  1145. /**
  1146. * @private
  1147. *
  1148. * @param value
  1149. * @param actionsMode
  1150. * @returns
  1151. */
  1152. ScrollTween.prototype.setPosition = function (value, actionsMode) {
  1153. if (actionsMode === void 0) { actionsMode = 1; }
  1154. if (value < 0) {
  1155. value = 0;
  1156. }
  1157. //正常化位置
  1158. var t = value;
  1159. var end = false;
  1160. if (t >= this.duration) {
  1161. if (this.loop) {
  1162. t = t % this.duration;
  1163. }
  1164. else {
  1165. t = this.duration;
  1166. end = true;
  1167. }
  1168. }
  1169. if (t == this._prevPos) {
  1170. return end;
  1171. }
  1172. var prevPos = this._prevPos;
  1173. this.position = this._prevPos = t;
  1174. this._prevPosition = value;
  1175. if (this._target) {
  1176. if (end) {
  1177. //结束
  1178. this._updateTargetProps(null, 1);
  1179. }
  1180. else if (this._steps.length > 0) {
  1181. // 找到新的tween
  1182. var i = void 0;
  1183. var l = this._steps.length;
  1184. for (i = 0; i < l; i++) {
  1185. if (this._steps[i].t > t) {
  1186. break;
  1187. }
  1188. }
  1189. var step = this._steps[i - 1];
  1190. this._updateTargetProps(step, (this._stepPosition = t - step.t) / step.d);
  1191. }
  1192. }
  1193. if (end) {
  1194. this.setPaused(true);
  1195. }
  1196. //执行actions
  1197. if (actionsMode != 0 && this._actions.length > 0) {
  1198. if (this._useTicks) {
  1199. this._runActions(t, t);
  1200. }
  1201. else if (actionsMode == 1 && t < prevPos) {
  1202. if (prevPos != this.duration) {
  1203. this._runActions(prevPos, this.duration);
  1204. }
  1205. this._runActions(0, t, true);
  1206. }
  1207. else {
  1208. this._runActions(prevPos, t);
  1209. }
  1210. }
  1211. this.dispatchEventWith("change");
  1212. return end;
  1213. };
  1214. /**
  1215. * @private
  1216. *
  1217. * @param startPos
  1218. * @param endPos
  1219. * @param includeStart
  1220. */
  1221. ScrollTween.prototype._runActions = function (startPos, endPos, includeStart) {
  1222. if (includeStart === void 0) { includeStart = false; }
  1223. var sPos = startPos;
  1224. var ePos = endPos;
  1225. var i = -1;
  1226. var j = this._actions.length;
  1227. var k = 1;
  1228. if (startPos > endPos) {
  1229. //把所有的倒置
  1230. sPos = endPos;
  1231. ePos = startPos;
  1232. i = j;
  1233. j = k = -1;
  1234. }
  1235. while ((i += k) != j) {
  1236. var action = this._actions[i];
  1237. var pos = action.t;
  1238. if (pos == ePos || (pos > sPos && pos < ePos) || (includeStart && pos == startPos)) {
  1239. action.f.apply(action.o, action.p);
  1240. }
  1241. }
  1242. };
  1243. /**
  1244. * @private
  1245. *
  1246. * @param step
  1247. * @param ratio
  1248. */
  1249. ScrollTween.prototype._updateTargetProps = function (step, ratio) {
  1250. var p0, p1, v, v0, v1, arr;
  1251. if (!step && ratio == 1) {
  1252. this.passive = false;
  1253. p0 = p1 = this._curQueueProps;
  1254. }
  1255. else {
  1256. this.passive = !!step.v;
  1257. //不更新props.
  1258. if (this.passive) {
  1259. return;
  1260. }
  1261. //使用ease
  1262. if (step.e) {
  1263. ratio = step.e(ratio, 0, 1, 1);
  1264. }
  1265. p0 = step.p0;
  1266. p1 = step.p1;
  1267. }
  1268. for (var n in this._initQueueProps) {
  1269. if ((v0 = p0[n]) == null) {
  1270. p0[n] = v0 = this._initQueueProps[n];
  1271. }
  1272. if ((v1 = p1[n]) == null) {
  1273. p1[n] = v1 = v0;
  1274. }
  1275. if (v0 == v1 || ratio == 0 || ratio == 1 || (typeof (v0) != "number")) {
  1276. v = ratio == 1 ? v1 : v0;
  1277. }
  1278. else {
  1279. v = v0 + (v1 - v0) * ratio;
  1280. }
  1281. var ignore = false;
  1282. if (arr = ScrollTween._plugins[n]) {
  1283. for (var i = 0, l = arr.length; i < l; i++) {
  1284. var v2 = arr[i].tween(this, n, v, p0, p1, ratio, !!step && p0 == p1, !step);
  1285. if (v2 == ScrollTween.IGNORE) {
  1286. ignore = true;
  1287. }
  1288. else {
  1289. v = v2;
  1290. }
  1291. }
  1292. }
  1293. if (!ignore) {
  1294. this._target[n] = v;
  1295. }
  1296. }
  1297. };
  1298. /**
  1299. * Whether setting is paused
  1300. * @param value {boolean} Whether to pause
  1301. * @returns ScrollTween object itself
  1302. * @version Egret 2.4
  1303. * @platform Web,Native
  1304. * @language en_US
  1305. */
  1306. /**
  1307. * 设置是否暂停
  1308. * @param value {boolean} 是否暂停
  1309. * @returns Tween对象本身
  1310. * @version Egret 2.4
  1311. * @platform Web,Native
  1312. * @language zh_CN
  1313. */
  1314. ScrollTween.prototype.setPaused = function (value) {
  1315. this.paused = value;
  1316. ScrollTween._register(this, !value);
  1317. return this;
  1318. };
  1319. /**
  1320. * @private
  1321. *
  1322. * @param props
  1323. * @returns
  1324. */
  1325. ScrollTween.prototype._cloneProps = function (props) {
  1326. var o = {};
  1327. for (var n in props) {
  1328. o[n] = props[n];
  1329. }
  1330. return o;
  1331. };
  1332. /**
  1333. * @private
  1334. *
  1335. * @param o
  1336. * @returns
  1337. */
  1338. ScrollTween.prototype._addStep = function (o) {
  1339. if (o.d > 0) {
  1340. this._steps.push(o);
  1341. o.t = this.duration;
  1342. this.duration += o.d;
  1343. }
  1344. return this;
  1345. };
  1346. /**
  1347. * @private
  1348. *
  1349. * @param o
  1350. * @returns
  1351. */
  1352. ScrollTween.prototype._appendQueueProps = function (o) {
  1353. var arr, oldValue, i, l, injectProps;
  1354. for (var n in o) {
  1355. if (this._initQueueProps[n] === undefined) {
  1356. oldValue = this._target[n];
  1357. //设置plugins
  1358. if (arr = ScrollTween._plugins[n]) {
  1359. for (i = 0, l = arr.length; i < l; i++) {
  1360. oldValue = arr[i].init(this, n, oldValue);
  1361. }
  1362. }
  1363. this._initQueueProps[n] = this._curQueueProps[n] = (oldValue === undefined) ? null : oldValue;
  1364. }
  1365. else {
  1366. oldValue = this._curQueueProps[n];
  1367. }
  1368. }
  1369. for (var n in o) {
  1370. oldValue = this._curQueueProps[n];
  1371. if (arr = ScrollTween._plugins[n]) {
  1372. injectProps = injectProps || {};
  1373. for (i = 0, l = arr.length; i < l; i++) {
  1374. if (arr[i].step) {
  1375. arr[i].step(this, n, oldValue, o[n], injectProps);
  1376. }
  1377. }
  1378. }
  1379. this._curQueueProps[n] = o[n];
  1380. }
  1381. if (injectProps) {
  1382. this._appendQueueProps(injectProps);
  1383. }
  1384. return this._curQueueProps;
  1385. };
  1386. /**
  1387. * @private
  1388. *
  1389. * @param o
  1390. * @returns
  1391. */
  1392. ScrollTween.prototype._addAction = function (o) {
  1393. o.t = this.duration;
  1394. this._actions.push(o);
  1395. return this;
  1396. };
  1397. /**
  1398. * Modify the property of the specified display object to a specified value
  1399. * @param props {Object} Property set of an object
  1400. * @param duration {number} Duration
  1401. * @param ease {egret.ScrollEase} Easing algorithm
  1402. * @returns {egret.ScrollTween} ScrollTween object itself
  1403. * @version Egret 2.4
  1404. * @platform Web,Native
  1405. * @language en_US
  1406. */
  1407. /**
  1408. * 将指定显示对象的属性修改为指定值
  1409. * @param props {Object} 对象的属性集合
  1410. * @param duration {number} 持续时间
  1411. * @param ease {egret.ScrollEase} 缓动算法
  1412. * @returns {egret.ScrollTween} Tween对象本身
  1413. * @version Egret 2.4
  1414. * @platform Web,Native
  1415. * @language zh_CN
  1416. */
  1417. ScrollTween.prototype.to = function (props, duration, ease) {
  1418. if (ease === void 0) { ease = undefined; }
  1419. if (isNaN(duration) || duration < 0) {
  1420. duration = 0;
  1421. }
  1422. return this._addStep({ d: duration || 0, p0: this._cloneProps(this._curQueueProps), e: ease, p1: this._cloneProps(this._appendQueueProps(props)) });
  1423. };
  1424. /**
  1425. * Execute callback function
  1426. * @param callback {Function} Callback method
  1427. * @param thisObj {any} this action scope of the callback method
  1428. * @param params {any[]} Parameter of the callback method
  1429. * @returns {egret.ScrollTween} ScrollTween object itself
  1430. * @version Egret 2.4
  1431. * @platform Web,Native
  1432. * @language en_US
  1433. */
  1434. /**
  1435. * 执行回调函数
  1436. * @param callback {Function} 回调方法
  1437. * @param thisObj {any} 回调方法this作用域
  1438. * @param params {any[]} 回调方法参数
  1439. * @returns {egret.ScrollTween} Tween对象本身
  1440. * @version Egret 2.4
  1441. * @platform Web,Native
  1442. * @language zh_CN
  1443. */
  1444. ScrollTween.prototype.call = function (callback, thisObj, params) {
  1445. if (thisObj === void 0) { thisObj = undefined; }
  1446. if (params === void 0) { params = undefined; }
  1447. return this._addAction({ f: callback, p: params ? params : [], o: thisObj ? thisObj : this._target });
  1448. };
  1449. /**
  1450. * @method egret.ScrollTween#tick
  1451. * @param delta {number}
  1452. * @private
  1453. * @version Egret 2.4
  1454. * @platform Web,Native
  1455. */
  1456. ScrollTween.prototype.tick = function (delta) {
  1457. if (this.paused) {
  1458. return;
  1459. }
  1460. this.setPosition(this._prevPosition + delta);
  1461. };
  1462. /**
  1463. * @private
  1464. */
  1465. ScrollTween._tweens = [];
  1466. /**
  1467. * @private
  1468. */
  1469. ScrollTween.IGNORE = {};
  1470. /**
  1471. * @private
  1472. */
  1473. ScrollTween._plugins = {};
  1474. /**
  1475. * @private
  1476. */
  1477. ScrollTween._inited = false;
  1478. ScrollTween._lastTime = 0;
  1479. return ScrollTween;
  1480. }(egret.EventDispatcher));
  1481. egret.ScrollTween = ScrollTween;
  1482. __reflect(ScrollTween.prototype, "egret.ScrollTween");
  1483. })(egret || (egret = {}));
  1484. //////////////////////////////////////////////////////////////////////////////////////
  1485. //
  1486. // Copyright (c) 2014-present, Egret Technology.
  1487. // All rights reserved.
  1488. // Redistribution and use in source and binary forms, with or without
  1489. // modification, are permitted provided that the following conditions are met:
  1490. //
  1491. // * Redistributions of source code must retain the above copyright
  1492. // notice, this list of conditions and the following disclaimer.
  1493. // * Redistributions in binary form must reproduce the above copyright
  1494. // notice, this list of conditions and the following disclaimer in the
  1495. // documentation and/or other materials provided with the distribution.
  1496. // * Neither the name of the Egret nor the
  1497. // names of its contributors may be used to endorse or promote products
  1498. // derived from this software without specific prior written permission.
  1499. //
  1500. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  1501. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  1502. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  1503. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  1504. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1505. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  1506. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1507. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1508. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1509. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1510. //
  1511. //////////////////////////////////////////////////////////////////////////////////////
  1512. var egret;
  1513. (function (egret) {
  1514. /**
  1515. * ScrollView auxiliary classes for slides, you will pass a display object constructor. It can display more than the range display object within the specified size range. And can easily drag in this range.
  1516. * @version Egret 2.4
  1517. * @platform Web,Native
  1518. * @includeExample extension/game/display/ScrollView.ts
  1519. * @language en_US
  1520. */
  1521. /**
  1522. * ScrollView 是用于滑动的辅助类,将一个显示对象传入构造函数即可。可以在指定的尺寸范围内显示超过该范围的显示对象。并可以在此范围内随意拖动。
  1523. * @version Egret 2.4
  1524. * @platform Web,Native
  1525. * @includeExample extension/game/display/ScrollView.ts
  1526. * @language zh_CN
  1527. */
  1528. var ScrollView = (function (_super) {
  1529. __extends(ScrollView, _super);
  1530. /**
  1531. * Create a egret.ScrollView objects
  1532. * @param content {egret.DisplayObject} You need to scroll object
  1533. * @version Egret 2.4
  1534. * @platform Web,Native
  1535. * @language en_US
  1536. */
  1537. /**
  1538. * 创建一个 egret.ScrollView 对象
  1539. * @param content {egret.DisplayObject} 需要滚动的对象
  1540. * @version Egret 2.4
  1541. * @platform Web,Native
  1542. * @language zh_CN
  1543. */
  1544. function ScrollView(content) {
  1545. if (content === void 0) { content = null; }
  1546. var _this = _super.call(this) || this;
  1547. /**
  1548. * Start rolling threshold when the touch point from the initial touch point at a distance exceeding this value will trigger roll
  1549. * @version Egret 2.4
  1550. * @platform Web,Native
  1551. * @language en_US
  1552. */
  1553. /**
  1554. * 开始滚动的阈值,当触摸点偏离初始触摸点的距离超过这个值时才会触发滚动
  1555. * @version Egret 2.4
  1556. * @platform Web,Native
  1557. * @language zh_CN
  1558. */
  1559. _this.scrollBeginThreshold = 10;
  1560. /**
  1561. * Scrolling speed, the speed is required and the default speed ratio.
  1562. * The range of scrollSpeed> 0 assigned to 2:00, the speed is 2 times the default speed
  1563. * @version Egret 2.4
  1564. * @platform Web,Native
  1565. * @language en_US
  1566. */
  1567. /**
  1568. * 滚动速度,这个值为需要的速度与默认速度的比值。
  1569. * 取值范围为 scrollSpeed > 0 赋值为 2 时,速度是默认速度的 2 倍
  1570. * @version Egret 2.4
  1571. * @platform Web,Native
  1572. * @language zh_CN
  1573. */
  1574. _this.scrollSpeed = 1;
  1575. /**
  1576. * @private
  1577. */
  1578. _this._content = null;
  1579. /**
  1580. * @private
  1581. */
  1582. _this.delayTouchBeginEvent = null;
  1583. /**
  1584. * @private
  1585. */
  1586. _this.touchBeginTimer = null;
  1587. _this.touchEnabled = true;
  1588. _this._ScrV_Props_ = new egret.ScrollViewProperties();
  1589. if (content) {
  1590. _this.setContent(content);
  1591. }
  1592. return _this;
  1593. }
  1594. Object.defineProperty(ScrollView.prototype, "bounces", {
  1595. /**
  1596. * Whether to enable rebound, rebound When enabled, ScrollView contents allowed to continue to drag the border after arriving at the end user drag operation, and then bounce back boundary position
  1597. * @default true
  1598. * @version Egret 2.4
  1599. * @language en_US
  1600. */
  1601. /**
  1602. * 是否启用回弹,当启用回弹后,ScrollView中内容在到达边界后允许继续拖动,在用户拖动操作结束后,再反弹回边界位置
  1603. * @default true
  1604. * @version Egret 2.4
  1605. * @language zh_CN
  1606. */
  1607. get: function () {
  1608. return this._ScrV_Props_._bounces;
  1609. },
  1610. set: function (value) {
  1611. this._ScrV_Props_._bounces = !!value;
  1612. },
  1613. enumerable: true,
  1614. configurable: true
  1615. });
  1616. /**
  1617. * Set to scroll object
  1618. * @param content {egret.DisplayObject} You need to scroll object
  1619. * @version Egret 2.4
  1620. * @platform Web,Native
  1621. * @language en_US
  1622. */
  1623. /**
  1624. * 设置需要滚动的对象
  1625. * @param content {egret.DisplayObject} 需要滚动的对象
  1626. * @version Egret 2.4
  1627. * @platform Web,Native
  1628. * @language zh_CN
  1629. */
  1630. ScrollView.prototype.setContent = function (content) {
  1631. if (this._content === content)
  1632. return;
  1633. this.removeContent();
  1634. if (content) {
  1635. this._content = content;
  1636. _super.prototype.addChild.call(this, content);
  1637. this._addEvents();
  1638. }
  1639. };
  1640. /**
  1641. * Remove rolling objects
  1642. * @version Egret 2.4
  1643. * @platform Web,Native
  1644. * @language en_US
  1645. */
  1646. /**
  1647. * 移除滚动的对象
  1648. * @version Egret 2.4
  1649. * @platform Web,Native
  1650. * @language zh_CN
  1651. */
  1652. ScrollView.prototype.removeContent = function () {
  1653. if (this._content) {
  1654. this._removeEvents();
  1655. _super.prototype.removeChildAt.call(this, 0);
  1656. }
  1657. this._content = null;
  1658. };
  1659. Object.defineProperty(ScrollView.prototype, "verticalScrollPolicy", {
  1660. /**
  1661. * Vertical scroll bar display policy, on / off / auto.
  1662. * @version Egret 2.4
  1663. * @platform Web,Native
  1664. * @language en_US
  1665. */
  1666. /**
  1667. * 垂直滚动条显示策略,on/off/auto。
  1668. * @version Egret 2.4
  1669. * @platform Web,Native
  1670. * @language zh_CN
  1671. */
  1672. get: function () {
  1673. return this._ScrV_Props_._verticalScrollPolicy;
  1674. },
  1675. set: function (value) {
  1676. if (value == this._ScrV_Props_._verticalScrollPolicy)
  1677. return;
  1678. this._ScrV_Props_._verticalScrollPolicy = value;
  1679. },
  1680. enumerable: true,
  1681. configurable: true
  1682. });
  1683. Object.defineProperty(ScrollView.prototype, "horizontalScrollPolicy", {
  1684. /**
  1685. * The horizontal scroll bar display policy, on / off / auto.
  1686. * @version Egret 2.4
  1687. * @platform Web,Native
  1688. * @language en_US
  1689. */
  1690. /**
  1691. * 水平滚动条显示策略,on/off/auto。
  1692. * @version Egret 2.4
  1693. * @platform Web,Native
  1694. * @language zh_CN
  1695. */
  1696. get: function () {
  1697. return this._ScrV_Props_._horizontalScrollPolicy;
  1698. },
  1699. set: function (value) {
  1700. if (value == this._ScrV_Props_._horizontalScrollPolicy)
  1701. return;
  1702. this._ScrV_Props_._horizontalScrollPolicy = value;
  1703. },
  1704. enumerable: true,
  1705. configurable: true
  1706. });
  1707. Object.defineProperty(ScrollView.prototype, "scrollLeft", {
  1708. /**
  1709. * Gets or sets the horizontal scroll position
  1710. * @returns {number}
  1711. * @version Egret 2.4
  1712. * @platform Web,Native
  1713. * @language en_US
  1714. */
  1715. /**
  1716. * 获取或设置水平滚动位置,
  1717. * @returns {number}
  1718. * @version Egret 2.4
  1719. * @platform Web,Native
  1720. * @language zh_CN
  1721. */
  1722. get: function () {
  1723. return this._ScrV_Props_._scrollLeft;
  1724. },
  1725. set: function (value) {
  1726. if (value == this._ScrV_Props_._scrollLeft)
  1727. return;
  1728. this._ScrV_Props_._scrollLeft = value;
  1729. this._validatePosition(false, true);
  1730. this._updateContentPosition();
  1731. },
  1732. enumerable: true,
  1733. configurable: true
  1734. });
  1735. Object.defineProperty(ScrollView.prototype, "scrollTop", {
  1736. /**
  1737. * Gets or sets the vertical scroll position
  1738. * @returns {number}
  1739. * @version Egret 2.4
  1740. * @platform Web,Native
  1741. * @language en_US
  1742. */
  1743. /**
  1744. * 获取或设置垂直滚动位置,
  1745. * @returns {number}
  1746. * @version Egret 2.4
  1747. * @platform Web,Native
  1748. * @language zh_CN
  1749. */
  1750. get: function () {
  1751. return this._ScrV_Props_._scrollTop;
  1752. },
  1753. set: function (value) {
  1754. if (value == this._ScrV_Props_._scrollTop)
  1755. return;
  1756. this._ScrV_Props_._scrollTop = value;
  1757. this._validatePosition(true, false);
  1758. this._updateContentPosition();
  1759. },
  1760. enumerable: true,
  1761. configurable: true
  1762. });
  1763. /**
  1764. * Set scroll position
  1765. * @param top {number} The vertical scroll position
  1766. * @param left {number} The horizontal scroll position
  1767. * @param isOffset {boolean} Optional parameter, the default is false, whether it is the amount of scrolling increase as top = 1 on behalf of one pixel scroll up
  1768. * @version Egret 2.4
  1769. * @platform Web,Native
  1770. * @language en_US
  1771. */
  1772. /**
  1773. * 设置滚动位置
  1774. * @param top {number} 垂直滚动位置
  1775. * @param left {number} 水平滚动位置
  1776. * @param isOffset {boolean} 可选参数,默认是false,是否是滚动增加量,如 top=1 代表往上滚动1像素
  1777. * @version Egret 2.4
  1778. * @platform Web,Native
  1779. * @language zh_CN
  1780. */
  1781. ScrollView.prototype.setScrollPosition = function (top, left, isOffset) {
  1782. if (isOffset === void 0) { isOffset = false; }
  1783. if (isOffset && top == 0 && left == 0)
  1784. return;
  1785. if (!isOffset && this._ScrV_Props_._scrollTop == top
  1786. && this._ScrV_Props_._scrollLeft == left)
  1787. return;
  1788. var oldTop = this._ScrV_Props_._scrollTop, oldLeft = this._ScrV_Props_._scrollLeft;
  1789. if (isOffset) {
  1790. var maxLeft = this.getMaxScrollLeft();
  1791. var maxTop = this.getMaxScrollTop();
  1792. if (oldTop <= 0 || oldTop >= maxTop) {
  1793. top = top / 2;
  1794. }
  1795. if (oldLeft <= 0 || oldLeft >= maxLeft) {
  1796. left = left / 2;
  1797. }
  1798. var newTop = oldTop + top;
  1799. var newLeft = oldLeft + left;
  1800. //判断是否回弹
  1801. var bounces = this._ScrV_Props_._bounces;
  1802. if (!bounces) {
  1803. if (newTop <= 0 || newTop >= maxTop)
  1804. newTop = Math.max(0, Math.min(newTop, maxTop));
  1805. if (newLeft <= 0 || newLeft >= maxLeft)
  1806. newLeft = Math.max(0, Math.min(newLeft, maxLeft));
  1807. }
  1808. this._ScrV_Props_._scrollTop = newTop;
  1809. this._ScrV_Props_._scrollLeft = newLeft;
  1810. }
  1811. else {
  1812. this._ScrV_Props_._scrollTop = top;
  1813. this._ScrV_Props_._scrollLeft = left;
  1814. }
  1815. this._validatePosition(true, true);
  1816. this._updateContentPosition();
  1817. };
  1818. /**
  1819. * @private
  1820. *
  1821. * @param top
  1822. * @param left
  1823. */
  1824. ScrollView.prototype._validatePosition = function (top, left) {
  1825. if (top === void 0) { top = false; }
  1826. if (left === void 0) { left = false; }
  1827. if (top) {
  1828. var height = this.height;
  1829. var contentHeight = this._getContentHeight();
  1830. this._ScrV_Props_._scrollTop = Math.max(this._ScrV_Props_._scrollTop, (0 - height) / 2);
  1831. this._ScrV_Props_._scrollTop = Math.min(this._ScrV_Props_._scrollTop, contentHeight > height ? (contentHeight - height / 2) : height / 2);
  1832. }
  1833. if (left) {
  1834. var width = this.width;
  1835. var contentWidth = this._getContentWidth();
  1836. this._ScrV_Props_._scrollLeft = Math.max(this._ScrV_Props_._scrollLeft, (0 - width) / 2);
  1837. this._ScrV_Props_._scrollLeft = Math.min(this._ScrV_Props_._scrollLeft, contentWidth > width ? (contentWidth - width / 2) : width / 2);
  1838. }
  1839. };
  1840. /**
  1841. * @private
  1842. * @inheritDoc
  1843. */
  1844. ScrollView.prototype.$setWidth = function (value) {
  1845. if (this.$explicitWidth == value) {
  1846. return;
  1847. }
  1848. _super.prototype.$setWidth.call(this, value);
  1849. this._updateContentPosition();
  1850. };
  1851. /**
  1852. * @private
  1853. * @inheritDoc
  1854. */
  1855. ScrollView.prototype.$setHeight = function (value) {
  1856. if (this.$explicitHeight == value) {
  1857. return;
  1858. }
  1859. _super.prototype.$setHeight.call(this, value);
  1860. this._updateContentPosition();
  1861. };
  1862. /**
  1863. * @private
  1864. *
  1865. */
  1866. ScrollView.prototype._updateContentPosition = function () {
  1867. var height = this.height;
  1868. var width = this.width;
  1869. //这里将坐标取整,避免有些浏览器精度低产生“黑线”问题
  1870. this.scrollRect = new egret.Rectangle(Math.round(this._ScrV_Props_._scrollLeft), Math.round(this._ScrV_Props_._scrollTop), width, height);
  1871. this.dispatchEvent(new egret.Event(egret.Event.CHANGE));
  1872. };
  1873. /**
  1874. * @private
  1875. *
  1876. * @returns
  1877. */
  1878. ScrollView.prototype._checkScrollPolicy = function () {
  1879. var hpolicy = this._ScrV_Props_._horizontalScrollPolicy;
  1880. var hCanScroll = this.__checkScrollPolicy(hpolicy, this._getContentWidth(), this.width);
  1881. this._ScrV_Props_._hCanScroll = hCanScroll;
  1882. var vpolicy = this._ScrV_Props_._verticalScrollPolicy;
  1883. var vCanScroll = this.__checkScrollPolicy(vpolicy, this._getContentHeight(), this.height);
  1884. this._ScrV_Props_._vCanScroll = vCanScroll;
  1885. return hCanScroll || vCanScroll;
  1886. };
  1887. /**
  1888. * @private
  1889. *
  1890. * @param policy
  1891. * @param contentLength
  1892. * @param viewLength
  1893. * @returns
  1894. */
  1895. ScrollView.prototype.__checkScrollPolicy = function (policy, contentLength, viewLength) {
  1896. if (policy == "on")
  1897. return true;
  1898. if (policy == "off")
  1899. return false;
  1900. return contentLength > viewLength;
  1901. };
  1902. /**
  1903. * @private
  1904. *
  1905. * @returns
  1906. */
  1907. ScrollView.prototype._addEvents = function () {
  1908. this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBegin, this);
  1909. this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBeginCapture, this, true);
  1910. this.addEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEndCapture, this, true);
  1911. };
  1912. /**
  1913. * @private
  1914. *
  1915. * @returns
  1916. */
  1917. ScrollView.prototype._removeEvents = function () {
  1918. this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBegin, this);
  1919. this.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBeginCapture, this, true);
  1920. this.removeEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEndCapture, this, true);
  1921. };
  1922. /**
  1923. * @private
  1924. *
  1925. * @param e
  1926. */
  1927. ScrollView.prototype._onTouchBegin = function (e) {
  1928. if (e.$isDefaultPrevented) {
  1929. return;
  1930. }
  1931. var canScroll = this._checkScrollPolicy();
  1932. if (!canScroll) {
  1933. return;
  1934. }
  1935. this._ScrV_Props_._touchStartPosition.x = e.stageX;
  1936. this._ScrV_Props_._touchStartPosition.y = e.stageY;
  1937. if (this._ScrV_Props_._isHTweenPlaying || this._ScrV_Props_._isVTweenPlaying) {
  1938. this._onScrollFinished();
  1939. }
  1940. this._tempStage = this.stage;
  1941. this._tempStage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
  1942. this._tempStage.addEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
  1943. this._tempStage.addEventListener(egret.TouchEvent.LEAVE_STAGE, this._onTouchEnd, this);
  1944. this.addEventListener(egret.Event.ENTER_FRAME, this._onEnterFrame, this);
  1945. this._logTouchEvent(e);
  1946. e.preventDefault();
  1947. };
  1948. /**
  1949. * @private
  1950. *
  1951. * @param event
  1952. */
  1953. ScrollView.prototype._onTouchBeginCapture = function (event) {
  1954. var canScroll = this._checkScrollPolicy();
  1955. if (!canScroll) {
  1956. return;
  1957. }
  1958. var target = event.target;
  1959. while (target != this) {
  1960. if ("_checkScrollPolicy" in target) {
  1961. canScroll = target._checkScrollPolicy();
  1962. if (canScroll) {
  1963. return;
  1964. }
  1965. }
  1966. target = target.parent;
  1967. }
  1968. event.stopPropagation();
  1969. var evt = this.cloneTouchEvent(event);
  1970. this.delayTouchBeginEvent = evt;
  1971. if (!this.touchBeginTimer) {
  1972. this.touchBeginTimer = new egret.Timer(100, 1);
  1973. this.touchBeginTimer.addEventListener(egret.TimerEvent.TIMER_COMPLETE, this._onTouchBeginTimer, this);
  1974. }
  1975. this.touchBeginTimer.start();
  1976. this._onTouchBegin(event);
  1977. };
  1978. /**
  1979. * @private
  1980. *
  1981. * @param event
  1982. * @returns
  1983. */
  1984. ScrollView.prototype._onTouchEndCapture = function (event) {
  1985. var _this = this;
  1986. if (!this.delayTouchBeginEvent) {
  1987. return;
  1988. }
  1989. this._onTouchBeginTimer();
  1990. event.stopPropagation();
  1991. var evt = this.cloneTouchEvent(event);
  1992. egret.callLater(function () {
  1993. if (_this.stage) {
  1994. _this.dispatchPropagationEvent(evt);
  1995. }
  1996. }, this);
  1997. };
  1998. /**
  1999. * @private
  2000. *
  2001. */
  2002. ScrollView.prototype._onTouchBeginTimer = function () {
  2003. this.touchBeginTimer.stop();
  2004. var event = this.delayTouchBeginEvent;
  2005. this.delayTouchBeginEvent = null;
  2006. //Dispatch event only if the scroll view is still on the stage
  2007. if (this.stage)
  2008. this.dispatchPropagationEvent(event);
  2009. };
  2010. /**
  2011. * @private
  2012. *
  2013. * @param event
  2014. * @returns
  2015. */
  2016. ScrollView.prototype.dispatchPropagationEvent = function (event) {
  2017. var target = event.$target;
  2018. var list = this.$getPropagationList(target);
  2019. var length = list.length;
  2020. var targetIndex = list.length * 0.5;
  2021. var startIndex = -1;
  2022. for (var i = 0; i < length; i++) {
  2023. if (list[i] === this._content) {
  2024. startIndex = i;
  2025. break;
  2026. }
  2027. }
  2028. list.splice(0, startIndex + 1);
  2029. targetIndex -= startIndex + 1;
  2030. this.$dispatchPropagationEvent(event, list, targetIndex);
  2031. egret.Event.release(event);
  2032. };
  2033. /**
  2034. * @private
  2035. *
  2036. * @param event
  2037. * @returns
  2038. */
  2039. ScrollView.prototype._onTouchMove = function (event) {
  2040. if (this._ScrV_Props_._lastTouchPosition.x == event.stageX && this._ScrV_Props_._lastTouchPosition.y == event.stageY)
  2041. return;
  2042. if (!this._ScrV_Props_._scrollStarted) {
  2043. var x = event.stageX - this._ScrV_Props_._touchStartPosition.x, y = event.stageY - this._ScrV_Props_._touchStartPosition.y;
  2044. var distance = Math.sqrt(x * x + y * y);
  2045. if (distance < this.scrollBeginThreshold) {
  2046. this._logTouchEvent(event);
  2047. return;
  2048. }
  2049. }
  2050. this._ScrV_Props_._scrollStarted = true;
  2051. if (this.delayTouchBeginEvent) {
  2052. this.delayTouchBeginEvent = null;
  2053. this.touchBeginTimer.stop();
  2054. }
  2055. this.touchChildren = false;
  2056. var offset = this._getPointChange(event);
  2057. this.setScrollPosition(offset.y, offset.x, true);
  2058. this._calcVelocitys(event);
  2059. this._logTouchEvent(event);
  2060. };
  2061. /**
  2062. * @private
  2063. *
  2064. * @param event
  2065. * @returns
  2066. */
  2067. ScrollView.prototype._onTouchEnd = function (event) {
  2068. this.touchChildren = true;
  2069. this._ScrV_Props_._scrollStarted = false;
  2070. this._tempStage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
  2071. this._tempStage.removeEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
  2072. this._tempStage.removeEventListener(egret.TouchEvent.LEAVE_STAGE, this._onTouchEnd, this);
  2073. this.removeEventListener(egret.Event.ENTER_FRAME, this._onEnterFrame, this);
  2074. this._moveAfterTouchEnd();
  2075. };
  2076. /**
  2077. * @private
  2078. *
  2079. * @param event
  2080. * @returns
  2081. */
  2082. ScrollView.prototype._onEnterFrame = function (event) {
  2083. var time = egret.getTimer();
  2084. if (time - this._ScrV_Props_._lastTouchTime > 100 && time - this._ScrV_Props_._lastTouchTime < 300) {
  2085. this._calcVelocitys(this._ScrV_Props_._lastTouchEvent);
  2086. }
  2087. };
  2088. /**
  2089. * @private
  2090. *
  2091. * @param e
  2092. * @returns
  2093. */
  2094. ScrollView.prototype._logTouchEvent = function (e) {
  2095. this._ScrV_Props_._lastTouchPosition.x = e.stageX;
  2096. this._ScrV_Props_._lastTouchPosition.y = e.stageY;
  2097. this._ScrV_Props_._lastTouchEvent = this.cloneTouchEvent(e);
  2098. this._ScrV_Props_._lastTouchTime = egret.getTimer();
  2099. };
  2100. /**
  2101. * @private
  2102. *
  2103. * @param e
  2104. * @returns
  2105. */
  2106. ScrollView.prototype._getPointChange = function (e) {
  2107. return {
  2108. x: this._ScrV_Props_._hCanScroll === false ? 0 : (this._ScrV_Props_._lastTouchPosition.x - e.stageX),
  2109. y: this._ScrV_Props_._vCanScroll === false ? 0 : (this._ScrV_Props_._lastTouchPosition.y - e.stageY)
  2110. };
  2111. };
  2112. /**
  2113. * @private
  2114. *
  2115. * @param e
  2116. * @returns
  2117. */
  2118. ScrollView.prototype._calcVelocitys = function (e) {
  2119. var time = egret.getTimer();
  2120. if (this._ScrV_Props_._lastTouchTime == 0) {
  2121. this._ScrV_Props_._lastTouchTime = time;
  2122. return;
  2123. }
  2124. var change = this._getPointChange(e);
  2125. var timeoffset = time - this._ScrV_Props_._lastTouchTime;
  2126. change.x /= timeoffset;
  2127. change.y /= timeoffset;
  2128. this._ScrV_Props_._velocitys.push(change);
  2129. if (this._ScrV_Props_._velocitys.length > 5)
  2130. this._ScrV_Props_._velocitys.shift();
  2131. this._ScrV_Props_._lastTouchPosition.x = e.stageX;
  2132. this._ScrV_Props_._lastTouchPosition.y = e.stageY;
  2133. };
  2134. /**
  2135. * @private
  2136. *
  2137. * @returns
  2138. */
  2139. ScrollView.prototype._getContentWidth = function () {
  2140. return this._content.$explicitWidth || this._content.width;
  2141. };
  2142. /**
  2143. * @private
  2144. *
  2145. * @returns
  2146. */
  2147. ScrollView.prototype._getContentHeight = function () {
  2148. return this._content.$explicitHeight || this._content.height;
  2149. };
  2150. /**
  2151. * The left side of the maximum distance
  2152. * @returns The left side of the maximum distance
  2153. * @version Egret 2.4
  2154. * @platform Web,Native
  2155. * @language en_US
  2156. */
  2157. /**
  2158. * 距离左侧的最大值
  2159. * @returns 距离左侧最大值
  2160. * @version Egret 2.4
  2161. * @platform Web,Native
  2162. * @language zh_CN
  2163. */
  2164. ScrollView.prototype.getMaxScrollLeft = function () {
  2165. var max = this._getContentWidth() - this.width;
  2166. return Math.max(0, max);
  2167. };
  2168. /**
  2169. * Above the maximum distance
  2170. * @returns Above the maximum distance
  2171. * @version Egret 2.4
  2172. * @platform Web,Native
  2173. * @language en_US
  2174. */
  2175. /**
  2176. * 距离上方最大值
  2177. * @returns 距离上方最大值
  2178. * @version Egret 2.4
  2179. * @platform Web,Native
  2180. * @language zh_CN
  2181. */
  2182. ScrollView.prototype.getMaxScrollTop = function () {
  2183. var max = this._getContentHeight() - this.height;
  2184. return Math.max(0, max);
  2185. };
  2186. /**
  2187. * @private
  2188. *
  2189. */
  2190. ScrollView.prototype._moveAfterTouchEnd = function () {
  2191. if (this._ScrV_Props_._velocitys.length == 0)
  2192. return;
  2193. var sum = { x: 0, y: 0 }, totalW = 0;
  2194. for (var i = 0; i < this._ScrV_Props_._velocitys.length; i++) {
  2195. var v = this._ScrV_Props_._velocitys[i];
  2196. var w = ScrollView.weight[i];
  2197. sum.x += v.x * w;
  2198. sum.y += v.y * w;
  2199. totalW += w;
  2200. }
  2201. this._ScrV_Props_._velocitys.length = 0;
  2202. if (this.scrollSpeed <= 0)
  2203. this.scrollSpeed = 1;
  2204. var x = sum.x / totalW * this.scrollSpeed, y = sum.y / totalW * this.scrollSpeed;
  2205. var pixelsPerMSX = Math.abs(x), pixelsPerMSY = Math.abs(y);
  2206. var maxLeft = this.getMaxScrollLeft();
  2207. var maxTop = this.getMaxScrollTop();
  2208. var datax = pixelsPerMSX > 0.02 ? this.getAnimationDatas(x, this._ScrV_Props_._scrollLeft, maxLeft) : {
  2209. position: this._ScrV_Props_._scrollLeft,
  2210. duration: 1
  2211. };
  2212. var datay = pixelsPerMSY > 0.02 ? this.getAnimationDatas(y, this._ScrV_Props_._scrollTop, maxTop) : {
  2213. position: this._ScrV_Props_._scrollTop,
  2214. duration: 1
  2215. };
  2216. this.setScrollLeft(datax.position, datax.duration);
  2217. this.setScrollTop(datay.position, datay.duration);
  2218. };
  2219. /**
  2220. * @private
  2221. *
  2222. * @param tw
  2223. */
  2224. ScrollView.prototype.onTweenFinished = function (tw) {
  2225. if (tw == this._ScrV_Props_._vScrollTween)
  2226. this._ScrV_Props_._isVTweenPlaying = false;
  2227. if (tw == this._ScrV_Props_._hScrollTween)
  2228. this._ScrV_Props_._isHTweenPlaying = false;
  2229. if (this._ScrV_Props_._isHTweenPlaying == false && this._ScrV_Props_._isVTweenPlaying == false) {
  2230. this._onScrollFinished();
  2231. }
  2232. };
  2233. /**
  2234. * @private
  2235. *
  2236. * @returns
  2237. */
  2238. ScrollView.prototype._onScrollStarted = function () {
  2239. };
  2240. /**
  2241. * @private
  2242. *
  2243. * @returns
  2244. */
  2245. ScrollView.prototype._onScrollFinished = function () {
  2246. egret.ScrollTween.removeTweens(this);
  2247. this._ScrV_Props_._hScrollTween = null;
  2248. this._ScrV_Props_._vScrollTween = null;
  2249. this._ScrV_Props_._isHTweenPlaying = false;
  2250. this._ScrV_Props_._isVTweenPlaying = false;
  2251. this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
  2252. };
  2253. /**
  2254. * Set the scroll position above the distance
  2255. * @param scrollTop Position above distance
  2256. * @param duration Easing of time, in milliseconds
  2257. * @returns Get tween vertical scrolling
  2258. * @version Egret 2.4
  2259. * @platform Web,Native
  2260. * @language en_US
  2261. */
  2262. /**
  2263. * 设置滚动距离上方的位置
  2264. * @param scrollTop 距离上方的位置
  2265. * @param duration 缓动时间,毫秒单位
  2266. * @returns 获取垂直滚动的tween
  2267. * @version Egret 2.4
  2268. * @platform Web,Native
  2269. * @language zh_CN
  2270. */
  2271. ScrollView.prototype.setScrollTop = function (scrollTop, duration) {
  2272. if (duration === void 0) { duration = 0; }
  2273. var finalPosition = Math.min(this.getMaxScrollTop(), Math.max(scrollTop, 0));
  2274. if (duration == 0) {
  2275. this.scrollTop = finalPosition;
  2276. return;
  2277. }
  2278. if (this._ScrV_Props_._bounces == false)
  2279. scrollTop = finalPosition;
  2280. var vtween = egret.ScrollTween.get(this).to({ scrollTop: scrollTop }, duration, egret.ScrollEase.quartOut);
  2281. if (finalPosition != scrollTop) {
  2282. vtween.to({ scrollTop: finalPosition }, 300, egret.ScrollEase.quintOut);
  2283. }
  2284. this._ScrV_Props_._isVTweenPlaying = true;
  2285. this._ScrV_Props_._vScrollTween = vtween;
  2286. vtween.call(this.onTweenFinished, this, [vtween]);
  2287. if (!this._ScrV_Props_._isHTweenPlaying)
  2288. this._onScrollStarted();
  2289. };
  2290. /**
  2291. * Set the scroll position from the left side
  2292. * @param scrollLeft From the position on the left side
  2293. * @param duration Get tween vertical scrolling
  2294. * @returns Gets the horizontal scroll tween
  2295. * @version Egret 2.4
  2296. * @platform Web,Native
  2297. * @language en_US
  2298. */
  2299. /**
  2300. * 设置滚动距离左侧的位置
  2301. * @param scrollLeft 距离左侧的位置
  2302. * @param duration 缓动时间,毫秒单位
  2303. * @returns 获取水平滚动的tween
  2304. * @version Egret 2.4
  2305. * @platform Web,Native
  2306. * @language zh_CN
  2307. */
  2308. ScrollView.prototype.setScrollLeft = function (scrollLeft, duration) {
  2309. if (duration === void 0) { duration = 0; }
  2310. var finalPosition = Math.min(this.getMaxScrollLeft(), Math.max(scrollLeft, 0));
  2311. if (duration == 0) {
  2312. this.scrollLeft = finalPosition;
  2313. return;
  2314. }
  2315. if (this._ScrV_Props_._bounces == false)
  2316. scrollLeft = finalPosition;
  2317. var htween = egret.ScrollTween.get(this).to({ scrollLeft: scrollLeft }, duration, egret.ScrollEase.quartOut);
  2318. if (finalPosition != scrollLeft) {
  2319. htween.to({ scrollLeft: finalPosition }, 300, egret.ScrollEase.quintOut);
  2320. }
  2321. this._ScrV_Props_._isHTweenPlaying = true;
  2322. this._ScrV_Props_._hScrollTween = htween;
  2323. htween.call(this.onTweenFinished, this, [htween]);
  2324. if (!this._ScrV_Props_._isVTweenPlaying)
  2325. this._onScrollStarted();
  2326. };
  2327. /**
  2328. * @private
  2329. *
  2330. * @param pixelsPerMS
  2331. * @param curPos
  2332. * @param maxPos
  2333. * @returns
  2334. */
  2335. ScrollView.prototype.getAnimationDatas = function (pixelsPerMS, curPos, maxPos) {
  2336. var absPixelsPerMS = Math.abs(pixelsPerMS);
  2337. var extraFricition = 0.95;
  2338. var duration = 0;
  2339. var friction = 0.998;
  2340. var minVelocity = 0.02;
  2341. var posTo = curPos + pixelsPerMS * 500;
  2342. if (posTo < 0 || posTo > maxPos) {
  2343. posTo = curPos;
  2344. while (Math.abs(pixelsPerMS) != Infinity && Math.abs(pixelsPerMS) > minVelocity) {
  2345. posTo += pixelsPerMS;
  2346. if (posTo < 0 || posTo > maxPos) {
  2347. pixelsPerMS *= friction * extraFricition;
  2348. }
  2349. else {
  2350. pixelsPerMS *= friction;
  2351. }
  2352. duration++;
  2353. }
  2354. }
  2355. else {
  2356. duration = -Math.log(minVelocity / absPixelsPerMS) * 500;
  2357. }
  2358. var result = {
  2359. position: Math.min(maxPos + 50, Math.max(posTo, -50)),
  2360. duration: duration
  2361. };
  2362. return result;
  2363. };
  2364. /**
  2365. * @private
  2366. *
  2367. * @param event
  2368. * @returns
  2369. */
  2370. ScrollView.prototype.cloneTouchEvent = function (event) {
  2371. var evt = new egret.TouchEvent(event.type, event.bubbles, event.cancelable);
  2372. evt.touchPointID = event.touchPointID;
  2373. evt.$stageX = event.stageX;
  2374. evt.$stageY = event.stageY;
  2375. //evt.ctrlKey = event.ctrlKey;
  2376. //evt.altKey = event.altKey;
  2377. //evt.shiftKey = event.shiftKey;
  2378. evt.touchDown = event.touchDown;
  2379. evt.$isDefaultPrevented = false;
  2380. evt.$target = event.target;
  2381. return evt;
  2382. };
  2383. /**
  2384. * @private
  2385. *
  2386. * @returns
  2387. */
  2388. ScrollView.prototype.throwNotSupportedError = function () {
  2389. egret.$error(1023);
  2390. };
  2391. /**
  2392. * @deprecated
  2393. * @inheritDoc
  2394. * @inheritDoc
  2395. * @version Egret 2.4
  2396. * @platform Web,Native
  2397. */
  2398. ScrollView.prototype.addChild = function (child) {
  2399. this.throwNotSupportedError();
  2400. return null;
  2401. };
  2402. /**
  2403. * @deprecated
  2404. * @inheritDoc
  2405. * @version Egret 2.4
  2406. * @platform Web,Native
  2407. */
  2408. ScrollView.prototype.addChildAt = function (child, index) {
  2409. this.throwNotSupportedError();
  2410. return null;
  2411. };
  2412. /**
  2413. * @deprecated
  2414. * @inheritDoc
  2415. * @version Egret 2.4
  2416. * @platform Web,Native
  2417. */
  2418. ScrollView.prototype.removeChild = function (child) {
  2419. this.throwNotSupportedError();
  2420. return null;
  2421. };
  2422. /**
  2423. * @deprecated
  2424. * @inheritDoc
  2425. * @version Egret 2.4
  2426. * @platform Web,Native
  2427. */
  2428. ScrollView.prototype.removeChildAt = function (index) {
  2429. this.throwNotSupportedError();
  2430. return null;
  2431. };
  2432. /**
  2433. * @deprecated
  2434. * @inheritDoc
  2435. * @version Egret 2.4
  2436. * @platform Web,Native
  2437. */
  2438. ScrollView.prototype.setChildIndex = function (child, index) {
  2439. this.throwNotSupportedError();
  2440. };
  2441. /**
  2442. * @deprecated
  2443. * @inheritDoc
  2444. * @version Egret 2.4
  2445. * @platform Web,Native
  2446. */
  2447. ScrollView.prototype.swapChildren = function (child1, child2) {
  2448. this.throwNotSupportedError();
  2449. };
  2450. /**
  2451. * @deprecated
  2452. * @inheritDoc
  2453. * @version Egret 2.4
  2454. * @platform Web,Native
  2455. */
  2456. ScrollView.prototype.swapChildrenAt = function (index1, index2) {
  2457. this.throwNotSupportedError();
  2458. };
  2459. /**
  2460. * @private
  2461. */
  2462. ScrollView.weight = [1, 1.33, 1.66, 2, 2.33];
  2463. return ScrollView;
  2464. }(egret.DisplayObjectContainer));
  2465. egret.ScrollView = ScrollView;
  2466. __reflect(ScrollView.prototype, "egret.ScrollView");
  2467. })(egret || (egret = {}));
  2468. //////////////////////////////////////////////////////////////////////////////////////
  2469. //
  2470. // Copyright (c) 2014-present, Egret Technology.
  2471. // All rights reserved.
  2472. // Redistribution and use in source and binary forms, with or without
  2473. // modification, are permitted provided that the following conditions are met:
  2474. //
  2475. // * Redistributions of source code must retain the above copyright
  2476. // notice, this list of conditions and the following disclaimer.
  2477. // * Redistributions in binary form must reproduce the above copyright
  2478. // notice, this list of conditions and the following disclaimer in the
  2479. // documentation and/or other materials provided with the distribution.
  2480. // * Neither the name of the Egret nor the
  2481. // names of its contributors may be used to endorse or promote products
  2482. // derived from this software without specific prior written permission.
  2483. //
  2484. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2485. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2486. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2487. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2488. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2489. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2490. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2491. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2492. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2493. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2494. //
  2495. //////////////////////////////////////////////////////////////////////////////////////
  2496. var egret;
  2497. (function (egret) {
  2498. /**
  2499. * @private
  2500. * @version Egret 2.4
  2501. * @platform Web,Native
  2502. */
  2503. var ScrollViewProperties = (function () {
  2504. function ScrollViewProperties() {
  2505. /**
  2506. * @private
  2507. */
  2508. this._verticalScrollPolicy = "auto";
  2509. /**
  2510. * @private
  2511. */
  2512. this._horizontalScrollPolicy = "auto";
  2513. /**
  2514. * @private
  2515. */
  2516. this._scrollLeft = 0;
  2517. /**
  2518. * @private
  2519. */
  2520. this._scrollTop = 0;
  2521. /**
  2522. * @private
  2523. */
  2524. this._hCanScroll = false;
  2525. /**
  2526. * @private
  2527. */
  2528. this._vCanScroll = false;
  2529. /**
  2530. * @private
  2531. */
  2532. this._lastTouchPosition = new egret.Point(0, 0);
  2533. /**
  2534. * @private
  2535. */
  2536. this._touchStartPosition = new egret.Point(0, 0);
  2537. /**
  2538. * @private
  2539. */
  2540. this._scrollStarted = false;
  2541. /**
  2542. * @private
  2543. */
  2544. this._lastTouchTime = 0;
  2545. /**
  2546. * @private
  2547. */
  2548. this._lastTouchEvent = null;
  2549. /**
  2550. * @private
  2551. */
  2552. this._velocitys = [];
  2553. /**
  2554. * @private
  2555. */
  2556. this._isHTweenPlaying = false;
  2557. /**
  2558. * @private
  2559. */
  2560. this._isVTweenPlaying = false;
  2561. /**
  2562. * @private
  2563. */
  2564. this._hScrollTween = null;
  2565. /**
  2566. * @private
  2567. */
  2568. this._vScrollTween = null;
  2569. /**
  2570. * @private
  2571. */
  2572. this._bounces = true;
  2573. }
  2574. return ScrollViewProperties;
  2575. }());
  2576. egret.ScrollViewProperties = ScrollViewProperties;
  2577. __reflect(ScrollViewProperties.prototype, "egret.ScrollViewProperties");
  2578. })(egret || (egret = {}));
  2579. //////////////////////////////////////////////////////////////////////////////////////
  2580. //
  2581. // Copyright (c) 2014-present, Egret Technology.
  2582. // All rights reserved.
  2583. // Redistribution and use in source and binary forms, with or without
  2584. // modification, are permitted provided that the following conditions are met:
  2585. //
  2586. // * Redistributions of source code must retain the above copyright
  2587. // notice, this list of conditions and the following disclaimer.
  2588. // * Redistributions in binary form must reproduce the above copyright
  2589. // notice, this list of conditions and the following disclaimer in the
  2590. // documentation and/or other materials provided with the distribution.
  2591. // * Neither the name of the Egret nor the
  2592. // names of its contributors may be used to endorse or promote products
  2593. // derived from this software without specific prior written permission.
  2594. //
  2595. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2596. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2597. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2598. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2599. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2600. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2601. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2602. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2603. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2604. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2605. //
  2606. //////////////////////////////////////////////////////////////////////////////////////
  2607. var egret;
  2608. (function (egret) {
  2609. function $getUrl(request) {
  2610. var url = request.url;
  2611. //get请求没有设置参数,而是设置URLVariables的情况
  2612. if (url.indexOf("?") == -1 && request.method == egret.URLRequestMethod.GET && request.data && request.data instanceof egret.URLVariables) {
  2613. url = url + "?" + request.data.toString();
  2614. }
  2615. return url;
  2616. }
  2617. /**
  2618. * UThe URLLoader class downloads data from a URL as text, binary data, or URL-encoded variables. It is useful for downloading text files, XML, or other information to be used in a dynamic, data-driven application.
  2619. * A URLLoader object downloads all of the data from a URL before making it available to code in the applications. It sends out notifications about the progress of the download,
  2620. * which you can monitor through bytesLoaded and bytesTotal properties, as well as through dispatched events.
  2621. * @see http://edn.egret.com/cn/docs/page/601 Build communication request
  2622. * @event egret.Event.COMPLETE Dispatched when the net request is complete.
  2623. * @event egret.IOErrorEvent.IO_ERROR io error.
  2624. * @version Egret 2.4
  2625. * @platform Web,Native
  2626. * @includeExample extension/game/net/URLLoader.ts
  2627. * @language en_US
  2628. */
  2629. /**
  2630. * URLLoader 类以文本、二进制数据或 URL 编码变量的形式从 URL 下载数据。在下载文本文件、XML 或其他用于动态数据驱动应用程序的信息时,它很有用。
  2631. * URLLoader 对象会先从 URL 中下载所有数据,然后才将数据用于应用程序中的代码。它会发出有关下载进度的通知,
  2632. * 通过 bytesLoaded 和 bytesTotal 属性以及已调度的事件,可以监视下载进度。
  2633. * @see http://edn.egret.com/cn/docs/page/601 构建通信请求
  2634. * @event egret.Event.COMPLETE 加载完成后调度。
  2635. * @event egret.IOErrorEvent.IO_ERROR 加载错误后调度。
  2636. * @version Egret 2.4
  2637. * @platform Web,Native
  2638. * @includeExample extension/game/net/URLLoader.ts
  2639. * @language zh_CN
  2640. */
  2641. var URLLoader = (function (_super) {
  2642. __extends(URLLoader, _super);
  2643. /**
  2644. * Create an egret.URLLoader object
  2645. * @param request {URLRequest} A URLRequest object specifies the URL to be downloaded.
  2646. * If this parameter is omitted, no load operation begins. If a parameter is specified, the load operation begins immediately
  2647. * @version Egret 2.4
  2648. * @platform Web,Native
  2649. * @language en_US
  2650. */
  2651. /**
  2652. * 创建 egret.URLLoader 对象
  2653. * @param request {URLRequest} 一个 URLRequest 对象,指定要下载的 URL。
  2654. * 如果省略该参数,则不开始加载操作。如果已指定参数,则立即开始加载操作
  2655. * @version Egret 2.4
  2656. * @platform Web,Native
  2657. * @language zh_CN
  2658. */
  2659. function URLLoader(request) {
  2660. if (request === void 0) { request = null; }
  2661. var _this = _super.call(this) || this;
  2662. /**
  2663. * Control whether the downloaded data is received as text (URLLoaderDataFormat.TEXT), raw binary data (URLLoaderDataFormat.BINARY), or URL-encoded variables (URLLoaderDataFormat.VARIABLES).
  2664. * If the value of the dataFormat property is URLLoaderDataFormat.TEXT, the received data is a string containing the text of the loaded file.
  2665. * If the value of the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object containing the raw binary data.
  2666. * If the value of the dataFormat property is URLLoaderDataFormat.TEXTURE, the received data is a Texture object containing the bitmap data.
  2667. * If the value of the dataFormat property is URLLoaderDataFormat.VARIABLES, the received data is a URLVariables object containing the URL-encoded variables.
  2668. * The default value is URLLoaderDataFormat.TEXT.
  2669. * @default egret.URLLoaderDataFormat.TEXT
  2670. * @version Egret 2.4
  2671. * @platform Web,Native
  2672. * @language en_US
  2673. */
  2674. /**
  2675. * 控制是以文本 (URLLoaderDataFormat.TEXT)、原始二进制数据 (URLLoaderDataFormat.BINARY) 还是 URL 编码变量 (URLLoaderDataFormat.VARIABLES) 接收下载的数据。
  2676. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.TEXT,则所接收的数据是一个包含已加载文件文本的字符串。
  2677. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.BINARY,则所接收的数据是一个包含原始二进制数据的 ByteArray 对象。
  2678. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.TEXTURE,则所接收的数据是一个包含位图数据的Texture对象。
  2679. * 如果 dataFormat 属性的值是 URLLoaderDataFormat.VARIABLES,则所接收的数据是一个包含 URL 编码变量的 URLVariables 对象。
  2680. * @default egret.URLLoaderDataFormat.TEXT
  2681. * @version Egret 2.4
  2682. * @platform Web,Native
  2683. * @language zh_CN
  2684. */
  2685. _this.dataFormat = egret.URLLoaderDataFormat.TEXT;
  2686. /**
  2687. * The data received from the load operation. This property is populated only when the load operation is complete. The format of the data depends on the setting of the dataFormat property:
  2688. * If the dataFormat property is URLLoaderDataFormat.TEXT, the received data is a string containing the text of the loaded file.
  2689. * If the dataFormat property is URLLoaderDataFormat.BINARY, the received data is a ByteArray object containing the raw binary data.
  2690. * If the dataFormat property is URLLoaderDataFormat.TEXTURE, the received data is a Texture object containing the bitmap data.
  2691. * If the dataFormat property is URLLoaderDataFormat.VARIABLES, the received data is a URLVariables object containing the URL-encoded variables.
  2692. * @version Egret 2.4
  2693. * @platform Web,Native
  2694. * @language en_US
  2695. */
  2696. /**
  2697. * 从加载操作接收的数据。只有完成加载操作时,才会填充该属性。该数据的格式取决于 dataFormat 属性的设置:
  2698. * 如果 dataFormat 属性是 URLLoaderDataFormat.TEXT,则所接收的数据是一个包含已加载文件文本的字符串。
  2699. * 如果 dataFormat 属性是 URLLoaderDataFormat.BINARY,则所接收的数据是一个包含原始二进制数据的 ByteArray 对象。
  2700. * 如果 dataFormat 属性是 URLLoaderDataFormat.TEXTURE,则所接收的数据是一个包含位图数据的Texture对象。
  2701. * 如果 dataFormat 属性是 URLLoaderDataFormat.VARIABLES,则所接收的数据是一个包含 URL 编码变量的 URLVariables 对象。
  2702. * @version Egret 2.4
  2703. * @platform Web,Native
  2704. * @language zh_CN
  2705. */
  2706. _this.data = null;
  2707. /**
  2708. * @private
  2709. */
  2710. _this._request = null;
  2711. /**
  2712. * @private
  2713. */
  2714. _this._status = -1;
  2715. if (request) {
  2716. _this.load(request);
  2717. }
  2718. return _this;
  2719. }
  2720. /**
  2721. * Send and load data from the specified URL. The data can be received as text, raw binary data, or URL-encoded variables, depending on the value you set for the dataFormat property.
  2722. * Note that the default value of the dataFormat property is text. If you want to send data to the specified URL, you can set the data property in the URLRequest object.
  2723. * @param request {URLRequest} A URLRequest object specifies the URL to be downloaded.
  2724. * @version Egret 2.4
  2725. * @platform Web,Native
  2726. * @language en_US
  2727. */
  2728. /**
  2729. * 从指定的 URL 发送和加载数据。可以以文本、原始二进制数据或 URL 编码变量格式接收数据,这取决于为 dataFormat 属性所设置的值。
  2730. * 请注意 dataFormat 属性的默认值为文本。如果想将数据发送至指定的 URL,则可以在 URLRequest 对象中设置 data 属性。
  2731. * @param request {URLRequest} 一个 URLRequest 对象,指定要下载的 URL。
  2732. * @version Egret 2.4
  2733. * @platform Web,Native
  2734. * @language zh_CN
  2735. */
  2736. URLLoader.prototype.load = function (request) {
  2737. this._request = request;
  2738. this.data = null;
  2739. var loader = this;
  2740. if (loader.dataFormat == egret.URLLoaderDataFormat.TEXTURE) {
  2741. this.loadTexture(loader);
  2742. return;
  2743. }
  2744. if (loader.dataFormat == egret.URLLoaderDataFormat.SOUND) {
  2745. this.loadSound(loader);
  2746. return;
  2747. }
  2748. var virtualUrl = $getUrl(request);
  2749. var httpRequest = new egret.HttpRequest();
  2750. httpRequest.open(virtualUrl, request.method == egret.URLRequestMethod.POST ? egret.HttpMethod.POST : egret.HttpMethod.GET);
  2751. var sendData;
  2752. if (request.method == egret.URLRequestMethod.GET || !request.data) {
  2753. }
  2754. else if (request.data instanceof egret.URLVariables) {
  2755. httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  2756. var urlVars = request.data;
  2757. sendData = urlVars.toString();
  2758. }
  2759. else {
  2760. httpRequest.setRequestHeader("Content-Type", "multipart/form-data");
  2761. sendData = request.data;
  2762. }
  2763. var length = request.requestHeaders.length;
  2764. for (var i = 0; i < length; i++) {
  2765. var urlRequestHeader = request.requestHeaders[i];
  2766. httpRequest.setRequestHeader(urlRequestHeader.name, urlRequestHeader.value);
  2767. }
  2768. httpRequest.addEventListener(egret.Event.COMPLETE, function () {
  2769. loader.data = httpRequest.response;
  2770. egret.Event.dispatchEvent(loader, egret.Event.COMPLETE);
  2771. }, this);
  2772. httpRequest.addEventListener(egret.IOErrorEvent.IO_ERROR, function () {
  2773. egret.IOErrorEvent.dispatchIOErrorEvent(loader);
  2774. }, this);
  2775. httpRequest.responseType = loader.dataFormat == egret.URLLoaderDataFormat.BINARY ? egret.HttpResponseType.ARRAY_BUFFER : egret.HttpResponseType.TEXT;
  2776. httpRequest.send(sendData);
  2777. };
  2778. URLLoader.prototype.getResponseType = function (dataFormat) {
  2779. switch (dataFormat) {
  2780. case egret.URLLoaderDataFormat.TEXT:
  2781. case egret.URLLoaderDataFormat.VARIABLES:
  2782. return egret.URLLoaderDataFormat.TEXT;
  2783. case egret.URLLoaderDataFormat.BINARY:
  2784. return "arraybuffer";
  2785. default:
  2786. return dataFormat;
  2787. }
  2788. };
  2789. /**
  2790. * @private
  2791. *
  2792. * @param loader
  2793. */
  2794. URLLoader.prototype.loadSound = function (loader) {
  2795. var self = this;
  2796. var virtualUrl = loader._request.url;
  2797. var sound = new egret.Sound();
  2798. sound.addEventListener(egret.Event.COMPLETE, onLoadComplete, self);
  2799. sound.addEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
  2800. sound.addEventListener(egret.ProgressEvent.PROGRESS, onPostProgress, self);
  2801. sound.load(virtualUrl);
  2802. function onPostProgress(event) {
  2803. loader.dispatchEvent(event);
  2804. }
  2805. function onError(event) {
  2806. removeListeners();
  2807. loader.dispatchEvent(event);
  2808. }
  2809. function onLoadComplete(e) {
  2810. removeListeners();
  2811. loader.data = sound;
  2812. window.setTimeout(function () {
  2813. loader.dispatchEventWith(egret.Event.COMPLETE);
  2814. }, 0);
  2815. }
  2816. function removeListeners() {
  2817. sound.removeEventListener(egret.Event.COMPLETE, onLoadComplete, self);
  2818. sound.removeEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
  2819. sound.removeEventListener(egret.ProgressEvent.PROGRESS, onPostProgress, self);
  2820. }
  2821. };
  2822. /**
  2823. * @private
  2824. *
  2825. * @param loader
  2826. */
  2827. URLLoader.prototype.loadTexture = function (loader) {
  2828. var self = this;
  2829. var virtualUrl = loader._request.url;
  2830. var imageLoader = new egret.ImageLoader();
  2831. imageLoader.addEventListener(egret.Event.COMPLETE, onLoadComplete, self);
  2832. imageLoader.addEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
  2833. imageLoader.addEventListener(egret.ProgressEvent.PROGRESS, onPostProgress, self);
  2834. imageLoader.load(virtualUrl);
  2835. function onPostProgress(event) {
  2836. loader.dispatchEvent(event);
  2837. }
  2838. function onError(event) {
  2839. removeListeners();
  2840. loader.dispatchEvent(event);
  2841. }
  2842. function onLoadComplete(e) {
  2843. removeListeners();
  2844. var bitmapData = imageLoader.data;
  2845. bitmapData.source.setAttribute("bitmapSrc", virtualUrl);
  2846. var texture = new egret.Texture();
  2847. texture._setBitmapData(bitmapData);
  2848. loader.data = texture;
  2849. window.setTimeout(function () {
  2850. loader.dispatchEventWith(egret.Event.COMPLETE);
  2851. }, self);
  2852. }
  2853. function removeListeners() {
  2854. imageLoader.removeEventListener(egret.Event.COMPLETE, onLoadComplete, self);
  2855. imageLoader.removeEventListener(egret.IOErrorEvent.IO_ERROR, onError, self);
  2856. imageLoader.removeEventListener(egret.ProgressEvent.PROGRESS, onPostProgress, self);
  2857. }
  2858. };
  2859. /**
  2860. * @private
  2861. *
  2862. */
  2863. URLLoader.prototype.__recycle = function () {
  2864. this._request = null;
  2865. this.data = null;
  2866. };
  2867. return URLLoader;
  2868. }(egret.EventDispatcher));
  2869. egret.URLLoader = URLLoader;
  2870. __reflect(URLLoader.prototype, "egret.URLLoader");
  2871. })(egret || (egret = {}));
  2872. //////////////////////////////////////////////////////////////////////////////////////
  2873. //
  2874. // Copyright (c) 2014-present, Egret Technology.
  2875. // All rights reserved.
  2876. // Redistribution and use in source and binary forms, with or without
  2877. // modification, are permitted provided that the following conditions are met:
  2878. //
  2879. // * Redistributions of source code must retain the above copyright
  2880. // notice, this list of conditions and the following disclaimer.
  2881. // * Redistributions in binary form must reproduce the above copyright
  2882. // notice, this list of conditions and the following disclaimer in the
  2883. // documentation and/or other materials provided with the distribution.
  2884. // * Neither the name of the Egret nor the
  2885. // names of its contributors may be used to endorse or promote products
  2886. // derived from this software without specific prior written permission.
  2887. //
  2888. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  2889. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  2890. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  2891. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  2892. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2893. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  2894. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2895. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2896. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2897. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2898. //
  2899. //////////////////////////////////////////////////////////////////////////////////////
  2900. var egret;
  2901. (function (egret) {
  2902. /**
  2903. * @version Egret 2.4
  2904. * @platform Web,Native
  2905. * @includeExample extension/game/display/MovieClip.ts
  2906. * @language en_US
  2907. */
  2908. /**
  2909. * 影片剪辑,可以通过影片剪辑播放序列帧动画。MovieClip 类从以下类继承而来:DisplayObject 和 EventDispatcher。不同于 DisplayObject 对象,MovieClip 对象拥有一个时间轴。
  2910. * @extends egret.DisplayObject
  2911. * @event egret.Event.COMPLETE 动画播放完成。
  2912. * @event egret.Event.LOOP_COMPLETE 动画循环播放完成。循环最后一次只派发 COMPLETE 事件,不派发 LOOP_COMPLETE 事件。
  2913. * @see http://edn.egret.com/cn/docs/page/596 MovieClip序列帧动画
  2914. * @version Egret 2.4
  2915. * @platform Web,Native
  2916. * @includeExample extension/game/display/MovieClip.ts
  2917. * @language zh_CN
  2918. */
  2919. var MovieClip = (function (_super) {
  2920. __extends(MovieClip, _super);
  2921. //Construct Function
  2922. /**
  2923. * 创建新的 MovieClip 实例。创建 MovieClip 之后,调用舞台上的显示对象容器的addElement方法。
  2924. * @param movieClipData {movieClipData} 被引用的 movieClipData 对象
  2925. * @version Egret 2.4
  2926. * @platform Web,Native
  2927. */
  2928. function MovieClip(movieClipData) {
  2929. var _this = _super.call(this) || this;
  2930. //Render Property
  2931. _this.$texture = null;
  2932. //Render Property
  2933. _this.offsetPoint = egret.Point.create(0, 0);
  2934. //Data Property
  2935. _this.$movieClipData = null;
  2936. /**
  2937. * @private
  2938. */
  2939. _this.frames = null;
  2940. /**
  2941. * @private
  2942. */
  2943. _this.$totalFrames = 0;
  2944. /**
  2945. * @version Egret 2.4
  2946. * @platform Web,Native
  2947. * @private
  2948. */
  2949. _this.frameLabels = null;
  2950. /**
  2951. * @private
  2952. */
  2953. _this.$frameLabelStart = 0;
  2954. /**
  2955. * @private
  2956. */
  2957. _this.$frameLabelEnd = 0;
  2958. /**
  2959. * @version Egret 2.4
  2960. * @platform Web,Native
  2961. * @private
  2962. */
  2963. _this.frameEvents = null;
  2964. /**
  2965. * @private
  2966. */
  2967. _this.frameIntervalTime = 0;
  2968. /**
  2969. * @private
  2970. */
  2971. _this.$eventPool = null;
  2972. //Animation Property
  2973. _this.$isPlaying = false;
  2974. /**
  2975. * @private
  2976. */
  2977. _this.isStopped = true;
  2978. /**
  2979. * @private
  2980. */
  2981. _this.playTimes = 0;
  2982. /**
  2983. * @private
  2984. */
  2985. _this.$currentFrameNum = 0;
  2986. /**
  2987. * @private
  2988. */
  2989. _this.$nextFrameNum = 1;
  2990. /**
  2991. * @private
  2992. */
  2993. _this.displayedKeyFrameNum = 0;
  2994. /**
  2995. * @private
  2996. */
  2997. _this.passedTime = 0;
  2998. /**
  2999. * @private
  3000. */
  3001. _this.$frameRate = NaN;
  3002. /**
  3003. * @private
  3004. */
  3005. _this.lastTime = 0;
  3006. _this.$smoothing = egret.Bitmap.defaultSmoothing;
  3007. _this.setMovieClipData(movieClipData);
  3008. if (!egret.nativeRender) {
  3009. _this.$renderNode = new egret.sys.NormalBitmapNode();
  3010. }
  3011. return _this;
  3012. }
  3013. MovieClip.prototype.createNativeDisplayObject = function () {
  3014. this.$nativeDisplayObject = new egret_native.NativeDisplayObject(11 /* BITMAP_TEXT */);
  3015. };
  3016. Object.defineProperty(MovieClip.prototype, "smoothing", {
  3017. /**
  3018. * Whether or not is smoothed when scaled.
  3019. * @version Egret 3.0
  3020. * @platform Web
  3021. * @language en_US
  3022. */
  3023. /**
  3024. * 控制在缩放时是否进行平滑处理。
  3025. * @version Egret 3.0
  3026. * @platform Web
  3027. * @language zh_CN
  3028. */
  3029. get: function () {
  3030. return this.$smoothing;
  3031. },
  3032. set: function (value) {
  3033. if (value == this.$smoothing) {
  3034. return;
  3035. }
  3036. this.$smoothing = value;
  3037. },
  3038. enumerable: true,
  3039. configurable: true
  3040. });
  3041. /**
  3042. * @private
  3043. *
  3044. */
  3045. MovieClip.prototype.$init = function () {
  3046. this.$reset();
  3047. var movieClipData = this.$movieClipData;
  3048. if (movieClipData && movieClipData.$isDataValid()) {
  3049. this.frames = movieClipData.frames;
  3050. this.$totalFrames = movieClipData.numFrames;
  3051. this.frameLabels = movieClipData.labels;
  3052. this.frameEvents = movieClipData.events;
  3053. this.$frameRate = movieClipData.frameRate;
  3054. this.frameIntervalTime = 1000 / this.$frameRate;
  3055. this._initFrame();
  3056. }
  3057. };
  3058. /**
  3059. * @private
  3060. *
  3061. */
  3062. MovieClip.prototype.$reset = function () {
  3063. this.frames = null;
  3064. this.playTimes = 0;
  3065. this.$isPlaying = false;
  3066. this.setIsStopped(true);
  3067. this.$currentFrameNum = 0;
  3068. this.$nextFrameNum = 1;
  3069. this.displayedKeyFrameNum = 0;
  3070. this.passedTime = 0;
  3071. this.$eventPool = [];
  3072. };
  3073. /**
  3074. * @private
  3075. *
  3076. */
  3077. MovieClip.prototype._initFrame = function () {
  3078. if (this.$movieClipData.$isTextureValid()) {
  3079. this.advanceFrame();
  3080. this.constructFrame();
  3081. }
  3082. };
  3083. /**
  3084. * @private
  3085. */
  3086. MovieClip.prototype.$updateRenderNode = function () {
  3087. var texture = this.$texture;
  3088. if (texture) {
  3089. var offsetX = Math.round(this.offsetPoint.x);
  3090. var offsetY = Math.round(this.offsetPoint.y);
  3091. var bitmapWidth = texture.$bitmapWidth;
  3092. var bitmapHeight = texture.$bitmapHeight;
  3093. var textureWidth = texture.$getTextureWidth();
  3094. var textureHeight = texture.$getTextureHeight();
  3095. var destW = Math.round(texture.$getScaleBitmapWidth());
  3096. var destH = Math.round(texture.$getScaleBitmapHeight());
  3097. var sourceWidth = texture.$sourceWidth;
  3098. var sourceHeight = texture.$sourceHeight;
  3099. egret.sys.BitmapNode.$updateTextureData(this.$renderNode, texture.$bitmapData, texture.$bitmapX, texture.$bitmapY, bitmapWidth, bitmapHeight, offsetX, offsetY, textureWidth, textureHeight, destW, destH, sourceWidth, sourceHeight, egret.BitmapFillMode.SCALE, this.$smoothing);
  3100. }
  3101. };
  3102. /**
  3103. * @private
  3104. */
  3105. MovieClip.prototype.$measureContentBounds = function (bounds) {
  3106. var texture = this.$texture;
  3107. if (texture) {
  3108. var x = this.offsetPoint.x;
  3109. var y = this.offsetPoint.y;
  3110. var w = texture.$getTextureWidth();
  3111. var h = texture.$getTextureHeight();
  3112. bounds.setTo(x, y, w, h);
  3113. }
  3114. else {
  3115. bounds.setEmpty();
  3116. }
  3117. };
  3118. /**
  3119. * @private
  3120. *
  3121. * @param stage
  3122. * @param nestLevel
  3123. */
  3124. MovieClip.prototype.$onAddToStage = function (stage, nestLevel) {
  3125. _super.prototype.$onAddToStage.call(this, stage, nestLevel);
  3126. if (this.$isPlaying && this.$totalFrames > 1) {
  3127. this.setIsStopped(false);
  3128. }
  3129. };
  3130. /**
  3131. * @private
  3132. *
  3133. */
  3134. MovieClip.prototype.$onRemoveFromStage = function () {
  3135. _super.prototype.$onRemoveFromStage.call(this);
  3136. this.setIsStopped(true);
  3137. };
  3138. //Data Function
  3139. /**
  3140. * @private
  3141. * 返回帧标签为指定字符串的FrameLabel对象
  3142. * @param labelName {string} 帧标签名
  3143. * @param ignoreCase {boolean} 是否忽略大小写,可选参数,默认false
  3144. * @returns {egret.FrameLabel} FrameLabel对象
  3145. */
  3146. MovieClip.prototype.getFrameLabelByName = function (labelName, ignoreCase) {
  3147. if (ignoreCase === void 0) { ignoreCase = false; }
  3148. if (ignoreCase) {
  3149. labelName = labelName.toLowerCase();
  3150. }
  3151. var frameLabels = this.frameLabels;
  3152. if (frameLabels) {
  3153. var outputFramelabel = null;
  3154. for (var i = 0; i < frameLabels.length; i++) {
  3155. outputFramelabel = frameLabels[i];
  3156. if (ignoreCase ? outputFramelabel.name.toLowerCase() == labelName : outputFramelabel.name == labelName) {
  3157. return outputFramelabel;
  3158. }
  3159. }
  3160. }
  3161. return null;
  3162. };
  3163. /**
  3164. * @private
  3165. * 根据帧标签,设置开始和结束的帧数
  3166. * @param labelName {string} 帧标签名
  3167. */
  3168. MovieClip.prototype.getFrameStartEnd = function (labelName) {
  3169. var frameLabels = this.frameLabels;
  3170. if (frameLabels) {
  3171. var outputFramelabel = null;
  3172. for (var i = 0; i < frameLabels.length; i++) {
  3173. outputFramelabel = frameLabels[i];
  3174. if (labelName == outputFramelabel.name) {
  3175. this.$frameLabelStart = outputFramelabel.frame;
  3176. this.$frameLabelEnd = outputFramelabel.end;
  3177. break;
  3178. }
  3179. }
  3180. }
  3181. };
  3182. /**
  3183. * @private
  3184. * 返回指定序号的帧的FrameLabel对象
  3185. * @param frame {number} 帧序号
  3186. * @returns {egret.FrameLabel} FrameLabel对象
  3187. */
  3188. MovieClip.prototype.getFrameLabelByFrame = function (frame) {
  3189. var frameLabels = this.frameLabels;
  3190. if (frameLabels) {
  3191. var outputFramelabel = null;
  3192. for (var i = 0; i < frameLabels.length; i++) {
  3193. outputFramelabel = frameLabels[i];
  3194. if (outputFramelabel.frame == frame) {
  3195. return outputFramelabel;
  3196. }
  3197. }
  3198. }
  3199. return null;
  3200. };
  3201. /**
  3202. * @private
  3203. * 返回指定序号的帧对应的FrameLabel对象,如果当前帧没有标签,则返回前面最近的有标签的帧的FrameLabel对象
  3204. * @method egret.MovieClip#getFrameLabelForFrame
  3205. * @param frame {number} 帧序号
  3206. * @returns {egret.FrameLabel} FrameLabel对象
  3207. */
  3208. MovieClip.prototype.getFrameLabelForFrame = function (frame) {
  3209. var outputFrameLabel = null;
  3210. var tempFrameLabel = null;
  3211. var frameLabels = this.frameLabels;
  3212. if (frameLabels) {
  3213. for (var i = 0; i < frameLabels.length; i++) {
  3214. tempFrameLabel = frameLabels[i];
  3215. if (tempFrameLabel.frame > frame) {
  3216. return outputFrameLabel;
  3217. }
  3218. outputFrameLabel = tempFrameLabel;
  3219. }
  3220. }
  3221. return outputFrameLabel;
  3222. };
  3223. //Animation Function
  3224. /**
  3225. * 继续播放当前动画
  3226. * @param playTimes {number} 播放次数。 参数为整数,可选参数,>=1:设定播放次数,<0:循环播放,默认值 0:不改变播放次数(MovieClip初始播放次数设置为1),
  3227. * @version Egret 2.4
  3228. * @platform Web,Native
  3229. */
  3230. MovieClip.prototype.play = function (playTimes) {
  3231. if (playTimes === void 0) { playTimes = 0; }
  3232. this.lastTime = egret.getTimer();
  3233. this.passedTime = 0;
  3234. this.$isPlaying = true;
  3235. this.setPlayTimes(playTimes);
  3236. if (this.$totalFrames > 1 && this.$stage) {
  3237. this.setIsStopped(false);
  3238. }
  3239. };
  3240. /**
  3241. * 暂停播放动画
  3242. * @version Egret 2.4
  3243. * @platform Web,Native
  3244. */
  3245. MovieClip.prototype.stop = function () {
  3246. this.$isPlaying = false;
  3247. this.setIsStopped(true);
  3248. };
  3249. /**
  3250. * 将播放头移到前一帧并停止
  3251. * @version Egret 2.4
  3252. * @platform Web,Native
  3253. */
  3254. MovieClip.prototype.prevFrame = function () {
  3255. this.gotoAndStop(this.$currentFrameNum - 1);
  3256. };
  3257. /**
  3258. * 跳到后一帧并停止
  3259. * @version Egret 2.4
  3260. * @platform Web,Native
  3261. */
  3262. MovieClip.prototype.nextFrame = function () {
  3263. this.gotoAndStop(this.$currentFrameNum + 1);
  3264. };
  3265. /**
  3266. * 将播放头移到指定帧并播放
  3267. * @param frame {any} 指定帧的帧号或帧标签
  3268. * @param playTimes {number} 播放次数。 参数为整数,可选参数,>=1:设定播放次数,<0:循环播放,默认值 0:不改变播放次数,
  3269. * @version Egret 2.4
  3270. * @platform Web,Native
  3271. */
  3272. MovieClip.prototype.gotoAndPlay = function (frame, playTimes) {
  3273. if (playTimes === void 0) { playTimes = 0; }
  3274. if (arguments.length == 0 || arguments.length > 2) {
  3275. egret.$error(1022, "MovieClip.gotoAndPlay()");
  3276. }
  3277. if (typeof frame === "string") {
  3278. this.getFrameStartEnd(frame);
  3279. }
  3280. else {
  3281. this.$frameLabelStart = 0;
  3282. this.$frameLabelEnd = 0;
  3283. }
  3284. this.play(playTimes);
  3285. this.gotoFrame(frame);
  3286. };
  3287. /**
  3288. * 将播放头移到指定帧并停止
  3289. * @param frame {any} 指定帧的帧号或帧标签
  3290. * @version Egret 2.4
  3291. * @platform Web,Native
  3292. */
  3293. MovieClip.prototype.gotoAndStop = function (frame) {
  3294. if (arguments.length != 1) {
  3295. egret.$error(1022, "MovieClip.gotoAndStop()");
  3296. }
  3297. this.stop();
  3298. this.gotoFrame(frame);
  3299. };
  3300. /**
  3301. * @private
  3302. *
  3303. * @param frame
  3304. */
  3305. MovieClip.prototype.gotoFrame = function (frame) {
  3306. var frameNum;
  3307. if (typeof frame === "string") {
  3308. frameNum = this.getFrameLabelByName(frame).frame;
  3309. }
  3310. else {
  3311. frameNum = parseInt(frame + '', 10);
  3312. if (frameNum != frame) {
  3313. egret.$error(1022, "Frame Label Not Found");
  3314. }
  3315. }
  3316. if (frameNum < 1) {
  3317. frameNum = 1;
  3318. }
  3319. else if (frameNum > this.$totalFrames) {
  3320. frameNum = this.$totalFrames;
  3321. }
  3322. if (frameNum == this.$nextFrameNum) {
  3323. return;
  3324. }
  3325. this.$nextFrameNum = frameNum;
  3326. this.advanceFrame();
  3327. this.constructFrame();
  3328. this.handlePendingEvent();
  3329. };
  3330. /**
  3331. * @private
  3332. *
  3333. * @param advancedTime
  3334. * @returns
  3335. */
  3336. MovieClip.prototype.advanceTime = function (timeStamp) {
  3337. var self = this;
  3338. var advancedTime = timeStamp - self.lastTime;
  3339. self.lastTime = timeStamp;
  3340. var frameIntervalTime = self.frameIntervalTime;
  3341. var currentTime = self.passedTime + advancedTime;
  3342. self.passedTime = currentTime % frameIntervalTime;
  3343. var num = currentTime / frameIntervalTime;
  3344. if (num < 1) {
  3345. return false;
  3346. }
  3347. while (num >= 1) {
  3348. num--;
  3349. self.$nextFrameNum++;
  3350. if (self.$nextFrameNum > self.$totalFrames || (self.$frameLabelStart > 0 && self.$nextFrameNum > self.$frameLabelEnd)) {
  3351. if (self.playTimes == -1) {
  3352. self.$eventPool.push(egret.Event.LOOP_COMPLETE);
  3353. self.$nextFrameNum = 1;
  3354. }
  3355. else {
  3356. self.playTimes--;
  3357. if (self.playTimes > 0) {
  3358. self.$eventPool.push(egret.Event.LOOP_COMPLETE);
  3359. self.$nextFrameNum = 1;
  3360. }
  3361. else {
  3362. self.$nextFrameNum = self.$totalFrames;
  3363. self.$eventPool.push(egret.Event.COMPLETE);
  3364. self.stop();
  3365. break;
  3366. }
  3367. }
  3368. }
  3369. if (self.$currentFrameNum == self.$frameLabelEnd) {
  3370. self.$nextFrameNum = self.$frameLabelStart;
  3371. }
  3372. self.advanceFrame();
  3373. }
  3374. self.constructFrame();
  3375. self.handlePendingEvent();
  3376. return false;
  3377. };
  3378. /**
  3379. * @private
  3380. *
  3381. */
  3382. MovieClip.prototype.advanceFrame = function () {
  3383. this.$currentFrameNum = this.$nextFrameNum;
  3384. var event = this.frameEvents[this.$nextFrameNum];
  3385. if (event && event != "") {
  3386. egret.MovieClipEvent.dispatchMovieClipEvent(this, egret.MovieClipEvent.FRAME_LABEL, event);
  3387. }
  3388. };
  3389. /**
  3390. * @private
  3391. *
  3392. */
  3393. MovieClip.prototype.constructFrame = function () {
  3394. var self = this;
  3395. var currentFrameNum = self.$currentFrameNum;
  3396. if (self.displayedKeyFrameNum == currentFrameNum) {
  3397. return;
  3398. }
  3399. var texture = self.$movieClipData.getTextureByFrame(currentFrameNum);
  3400. self.$texture = texture;
  3401. self.$movieClipData.$getOffsetByFrame(currentFrameNum, self.offsetPoint);
  3402. self.displayedKeyFrameNum = currentFrameNum;
  3403. self.$renderDirty = true;
  3404. if (egret.nativeRender) {
  3405. self.$nativeDisplayObject.setDataToBitmapNode(self.$nativeDisplayObject.id, texture, [texture.$bitmapX, texture.$bitmapY, texture.$bitmapWidth, texture.$bitmapHeight,
  3406. self.offsetPoint.x, self.offsetPoint.y, texture.$getScaleBitmapWidth(), texture.$getScaleBitmapHeight(),
  3407. texture.$sourceWidth, texture.$sourceHeight]);
  3408. //todo 负数offsetPoint
  3409. self.$nativeDisplayObject.setWidth(texture.$getTextureWidth() + self.offsetPoint.x);
  3410. self.$nativeDisplayObject.setHeight(texture.$getTextureHeight() + self.offsetPoint.y);
  3411. }
  3412. else {
  3413. var p = self.$parent;
  3414. if (p && !p.$cacheDirty) {
  3415. p.$cacheDirty = true;
  3416. p.$cacheDirtyUp();
  3417. }
  3418. var maskedObject = self.$maskedObject;
  3419. if (maskedObject && !maskedObject.$cacheDirty) {
  3420. maskedObject.$cacheDirty = true;
  3421. maskedObject.$cacheDirtyUp();
  3422. }
  3423. }
  3424. };
  3425. /**
  3426. * @private
  3427. *
  3428. */
  3429. MovieClip.prototype.$renderFrame = function () {
  3430. var self = this;
  3431. self.$texture = self.$movieClipData.getTextureByFrame(self.$currentFrameNum);
  3432. self.$renderDirty = true;
  3433. var p = self.$parent;
  3434. if (p && !p.$cacheDirty) {
  3435. p.$cacheDirty = true;
  3436. p.$cacheDirtyUp();
  3437. }
  3438. var maskedObject = self.$maskedObject;
  3439. if (maskedObject && !maskedObject.$cacheDirty) {
  3440. maskedObject.$cacheDirty = true;
  3441. maskedObject.$cacheDirtyUp();
  3442. }
  3443. };
  3444. /**
  3445. * @private
  3446. *
  3447. */
  3448. MovieClip.prototype.handlePendingEvent = function () {
  3449. if (this.$eventPool.length != 0) {
  3450. this.$eventPool.reverse();
  3451. var eventPool = this.$eventPool;
  3452. var length_3 = eventPool.length;
  3453. var isComplete = false;
  3454. var isLoopComplete = false;
  3455. for (var i = 0; i < length_3; i++) {
  3456. var event_1 = eventPool.pop();
  3457. if (event_1 == egret.Event.LOOP_COMPLETE) {
  3458. isLoopComplete = true;
  3459. }
  3460. else if (event_1 == egret.Event.COMPLETE) {
  3461. isComplete = true;
  3462. }
  3463. else {
  3464. this.dispatchEventWith(event_1);
  3465. }
  3466. }
  3467. if (isLoopComplete) {
  3468. this.dispatchEventWith(egret.Event.LOOP_COMPLETE);
  3469. }
  3470. if (isComplete) {
  3471. this.dispatchEventWith(egret.Event.COMPLETE);
  3472. }
  3473. }
  3474. };
  3475. Object.defineProperty(MovieClip.prototype, "totalFrames", {
  3476. //Properties
  3477. /**
  3478. * MovieClip 实例中帧的总数
  3479. * @version Egret 2.4
  3480. * @platform Web,Native
  3481. */
  3482. get: function () {
  3483. return this.$totalFrames;
  3484. },
  3485. enumerable: true,
  3486. configurable: true
  3487. });
  3488. Object.defineProperty(MovieClip.prototype, "currentFrame", {
  3489. /**
  3490. * MovieClip 实例当前播放的帧的序号
  3491. * @version Egret 2.4
  3492. * @platform Web,Native
  3493. */
  3494. get: function () {
  3495. return this.$currentFrameNum;
  3496. },
  3497. enumerable: true,
  3498. configurable: true
  3499. });
  3500. Object.defineProperty(MovieClip.prototype, "currentFrameLabel", {
  3501. /**
  3502. * MovieClip 实例当前播放的帧的标签。如果当前帧没有标签,则 currentFrameLabel返回null。
  3503. * @version Egret 2.4
  3504. * @platform Web,Native
  3505. */
  3506. get: function () {
  3507. var label = this.getFrameLabelByFrame(this.$currentFrameNum);
  3508. return label && label.name;
  3509. },
  3510. enumerable: true,
  3511. configurable: true
  3512. });
  3513. Object.defineProperty(MovieClip.prototype, "currentLabel", {
  3514. /**
  3515. * 当前播放的帧对应的标签,如果当前帧没有标签,则currentLabel返回包含标签的先前帧的标签。如果当前帧和先前帧都不包含标签,currentLabel返回null。
  3516. * @version Egret 2.4
  3517. * @platform Web,Native
  3518. */
  3519. get: function () {
  3520. var label = this.getFrameLabelForFrame(this.$currentFrameNum);
  3521. return label ? label.name : null;
  3522. },
  3523. enumerable: true,
  3524. configurable: true
  3525. });
  3526. Object.defineProperty(MovieClip.prototype, "frameRate", {
  3527. /**
  3528. * MovieClip 实例的帧频
  3529. * @version Egret 2.4
  3530. * @platform Web,Native
  3531. */
  3532. get: function () {
  3533. return this.$frameRate;
  3534. },
  3535. set: function (value) {
  3536. if (value == this.$frameRate) {
  3537. return;
  3538. }
  3539. this.$frameRate = value;
  3540. this.frameIntervalTime = 1000 / this.$frameRate;
  3541. },
  3542. enumerable: true,
  3543. configurable: true
  3544. });
  3545. Object.defineProperty(MovieClip.prototype, "isPlaying", {
  3546. /**
  3547. * MovieClip 实例当前是否正在播放
  3548. * @version Egret 2.4
  3549. * @platform Web,Native
  3550. */
  3551. get: function () {
  3552. return this.$isPlaying;
  3553. },
  3554. enumerable: true,
  3555. configurable: true
  3556. });
  3557. Object.defineProperty(MovieClip.prototype, "movieClipData", {
  3558. /**
  3559. * @version Egret 2.4
  3560. * @platform Web,Native
  3561. */
  3562. get: function () {
  3563. return this.$movieClipData;
  3564. },
  3565. /**
  3566. * MovieClip数据源
  3567. */
  3568. set: function (value) {
  3569. this.setMovieClipData(value);
  3570. },
  3571. enumerable: true,
  3572. configurable: true
  3573. });
  3574. /**
  3575. * @private
  3576. *
  3577. * @param value
  3578. */
  3579. MovieClip.prototype.setMovieClipData = function (value) {
  3580. if (this.$movieClipData == value) {
  3581. return;
  3582. }
  3583. this.$movieClipData = value;
  3584. this.$init();
  3585. };
  3586. /**
  3587. * @private
  3588. *
  3589. * @param value
  3590. */
  3591. MovieClip.prototype.setPlayTimes = function (value) {
  3592. if (value < 0 || value >= 1) {
  3593. this.playTimes = value < 0 ? -1 : Math.floor(value);
  3594. }
  3595. };
  3596. /**
  3597. * @private
  3598. *
  3599. * @param value
  3600. */
  3601. MovieClip.prototype.setIsStopped = function (value) {
  3602. if (this.isStopped == value) {
  3603. return;
  3604. }
  3605. this.isStopped = value;
  3606. if (value) {
  3607. egret.ticker.$stopTick(this.advanceTime, this);
  3608. }
  3609. else {
  3610. this.playTimes = this.playTimes == 0 ? 1 : this.playTimes;
  3611. this.lastTime = egret.getTimer();
  3612. egret.ticker.$startTick(this.advanceTime, this);
  3613. }
  3614. };
  3615. return MovieClip;
  3616. }(egret.DisplayObject));
  3617. egret.MovieClip = MovieClip;
  3618. __reflect(MovieClip.prototype, "egret.MovieClip");
  3619. })(egret || (egret = {}));
  3620. //////////////////////////////////////////////////////////////////////////////////////
  3621. //
  3622. // Copyright (c) 2014-present, Egret Technology.
  3623. // All rights reserved.
  3624. // Redistribution and use in source and binary forms, with or without
  3625. // modification, are permitted provided that the following conditions are met:
  3626. //
  3627. // * Redistributions of source code must retain the above copyright
  3628. // notice, this list of conditions and the following disclaimer.
  3629. // * Redistributions in binary form must reproduce the above copyright
  3630. // notice, this list of conditions and the following disclaimer in the
  3631. // documentation and/or other materials provided with the distribution.
  3632. // * Neither the name of the Egret nor the
  3633. // names of its contributors may be used to endorse or promote products
  3634. // derived from this software without specific prior written permission.
  3635. //
  3636. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3637. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3638. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3639. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3640. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3641. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3642. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3643. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3644. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3645. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3646. //
  3647. //////////////////////////////////////////////////////////////////////////////////////
  3648. var egret;
  3649. (function (egret) {
  3650. /**
  3651. * The URLRequest class captures all of the information in a single HTTP request.
  3652. * @see http://edn.egret.com/cn/index.php/article/index/id/601 Build communication request
  3653. * @version Egret 2.4
  3654. * @platform Web,Native
  3655. * @includeExample extension/game/net/URLRequest.ts
  3656. * @language en_US
  3657. */
  3658. /**
  3659. * URLRequest 类可捕获单个 HTTP 请求中的所有信息。
  3660. * @see http://edn.egret.com/cn/index.php/article/index/id/601 构建通信请求
  3661. * @version Egret 2.4
  3662. * @platform Web,Native
  3663. * @includeExample extension/game/net/URLRequest.ts
  3664. * @language zh_CN
  3665. */
  3666. var URLRequest = (function (_super) {
  3667. __extends(URLRequest, _super);
  3668. /**
  3669. * Create an egret.URLRequest object
  3670. * @param url {string} Addresses for URL requests
  3671. * @version Egret 2.4
  3672. * @platform Web,Native
  3673. * @language en_US
  3674. */
  3675. /**
  3676. * 创建一个 egret.URLRequest 对象
  3677. * @param url {string} 进行网络请求的地址
  3678. * @version Egret 2.4
  3679. * @platform Web,Native
  3680. * @language zh_CN
  3681. */
  3682. function URLRequest(url) {
  3683. if (url === void 0) { url = null; }
  3684. var _this = _super.call(this) || this;
  3685. /**
  3686. * An object contains data to be transmitted with the URL request.
  3687. * This property is used in conjunction with the method property. When the value of method is GET, the value of data is appended to the value of URLRequest.url, using HTTP query-string syntax.
  3688. * When the method value is POST (or any value other than GET), the value of data is transmitted in the body of the HTTP request.
  3689. * The URLRequest API offers binary POST support and support for URL-encoded variables, as well as support for strings. The data object can be a ArrayBuffer, URLVariables, or String object.
  3690. * The way in which the data is used depends on the type of object used:
  3691. * If the object is a ArrayBuffer object, the binary data of the ArrayBuffer object is used as POST data. For GET, data of ArrayBuffer type is not supported.
  3692. * If the object is a URLVariables object and the method is POST, then the variables are encoded using x-www-form-urlencoded format and the resulting string is used as POST data.
  3693. * If the object is a URLVariables object and the method is GET, the URLVariables object will define variables to be sent with the URLRequest object.
  3694. * Otherwise, the object is converted into a string, and the string is used as the POST or GET data.
  3695. * @version Egret 2.4
  3696. * @platform Web,Native
  3697. * @language en_US
  3698. */
  3699. /**
  3700. * 一个对象,它包含将随 URL 请求一起传输的数据。
  3701. * 该属性与 method 属性配合使用。当 method 值为 GET 时,将使用 HTTP 查询字符串语法将 data 值追加到 URLRequest.url 值。
  3702. * 当 method 值为 POST(或 GET 之外的任何值)时,将在 HTTP 请求体中传输 data 值。
  3703. * URLRequest API 支持二进制 POST,并支持 URL 编码变量和字符串。该数据对象可以是 ArrayBuffer、URLVariables 或 String 对象。
  3704. * 该数据的使用方式取决于所用对象的类型:
  3705. * 如果该对象为 ArrayBuffer 对象,则 ArrayBuffer 对象的二进制数据用作 POST 数据。对于 GET,不支持 ArrayBuffer 类型的数据。
  3706. * 如果该对象是 URLVariables 对象,并且该方法是 POST,则使用 x-www-form-urlencoded 格式对变量进行编码,并且生成的字符串会用作 POST 数据。
  3707. * 如果该对象是 URLVariables 对象,并且该方法是 GET,则 URLVariables 对象将定义要随 URLRequest 对象一起发送的变量。
  3708. * 否则,该对象会转换为字符串,并且该字符串会用作 POST 或 GET 数据。
  3709. * @version Egret 2.4
  3710. * @platform Web,Native
  3711. * @language zh_CN
  3712. */
  3713. _this.data = null;
  3714. /**
  3715. * Request method, valid values are URLRequestMethod.GET or URLRequestMethod.POST.
  3716. * @version Egret 2.4
  3717. * @platform Web,Native
  3718. * @language en_US
  3719. */
  3720. /**
  3721. * 请求方式,有效值为URLRequestMethod.GET 或 URLRequestMethod.POST。
  3722. * @version Egret 2.4
  3723. * @platform Web,Native
  3724. * @language zh_CN
  3725. */
  3726. _this.method = egret.URLRequestMethod.GET;
  3727. /**
  3728. * The requested URL.
  3729. * @version Egret 2.4
  3730. * @platform Web,Native
  3731. * @language en_US
  3732. */
  3733. /**
  3734. * 所请求的 URL。
  3735. * @version Egret 2.4
  3736. * @platform Web,Native
  3737. * @language zh_CN
  3738. */
  3739. _this.url = "";
  3740. /**
  3741. * The array of HTTP request headers to be appended to the HTTP request. The array is composed of URLRequestHeader objects.
  3742. * Each object in the array must be a URLRequestHeader object that contains a name string and a value string.
  3743. * Because of browser compatibility, this property has not been achieved in html5
  3744. * @version Egret 2.4
  3745. * @platform Web,Native
  3746. * @language en_US
  3747. */
  3748. /**
  3749. * 要追加到 HTTP 请求的 HTTP 请求标头的数组。该数组由 URLRequestHeader 对象组成。
  3750. * 数组中的每一对象必须是包含一个名称字符串和一个值字符串的 URLRequestHeader 对象。
  3751. * 由于浏览器兼容性原因,该属性在 html5 中并未实现
  3752. * @version Egret 2.4
  3753. * @platform Web,Native
  3754. * @language zh_CN
  3755. */
  3756. _this.requestHeaders = [];
  3757. _this.url = url;
  3758. return _this;
  3759. }
  3760. return URLRequest;
  3761. }(egret.HashObject));
  3762. egret.URLRequest = URLRequest;
  3763. __reflect(URLRequest.prototype, "egret.URLRequest");
  3764. })(egret || (egret = {}));
  3765. //////////////////////////////////////////////////////////////////////////////////////
  3766. //
  3767. // Copyright (c) 2014-present, Egret Technology.
  3768. // All rights reserved.
  3769. // Redistribution and use in source and binary forms, with or without
  3770. // modification, are permitted provided that the following conditions are met:
  3771. //
  3772. // * Redistributions of source code must retain the above copyright
  3773. // notice, this list of conditions and the following disclaimer.
  3774. // * Redistributions in binary form must reproduce the above copyright
  3775. // notice, this list of conditions and the following disclaimer in the
  3776. // documentation and/or other materials provided with the distribution.
  3777. // * Neither the name of the Egret nor the
  3778. // names of its contributors may be used to endorse or promote products
  3779. // derived from this software without specific prior written permission.
  3780. //
  3781. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3782. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3783. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3784. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3785. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3786. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3787. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3788. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3789. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3790. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3791. //
  3792. //////////////////////////////////////////////////////////////////////////////////////
  3793. var egret;
  3794. (function (egret) {
  3795. /**
  3796. * A URLRequestHeader object encapsulates a single HTTP request header and consists of a name/value pair. URLRequestHeader objects are used in the requestHeaders property of the URLRequest class.
  3797. * Note: Because of browser compatibility, this property has not been achieved in html5
  3798. * @version Egret 2.4
  3799. * @platform Web,Native
  3800. * @includeExample extension/game/net/URLRequestHeader.ts
  3801. * @language en_US
  3802. */
  3803. /**
  3804. * URLRequestHeader 对象封装了一个 HTTP 请求标头并由一个名称/值对组成。URLRequestHeader 对象在 URLRequest 类的 requestHeaders 属性中使用。
  3805. * 注意:由于浏览器兼容性原因,在 html5 中并未实现
  3806. * @version Egret 2.4
  3807. * @platform Web,Native
  3808. * @includeExample extension/game/net/URLRequestHeader.ts
  3809. * @language zh_CN
  3810. */
  3811. var URLRequestHeader = (function () {
  3812. /**
  3813. * Create an egret.URLRequestHeader object
  3814. * @version Egret 2.4
  3815. * @platform Web,Native
  3816. * @language en_US
  3817. */
  3818. /**
  3819. * 创建一个 egret.URLRequestHeader 对象
  3820. * @version Egret 2.4
  3821. * @platform Web,Native
  3822. * @language zh_CN
  3823. */
  3824. function URLRequestHeader(name, value) {
  3825. /**
  3826. * HTTP request header name, such as Content-Type
  3827. * @version Egret 2.4
  3828. * @platform Web,Native
  3829. * @language en_US
  3830. */
  3831. /**
  3832. * HTTP 请求标头名称,如 Content-Type
  3833. * @version Egret 2.4
  3834. * @platform Web,Native
  3835. * @language zh_CN
  3836. */
  3837. this.name = "";
  3838. /**
  3839. * The values associated with the name property (such as text/plain).
  3840. * @version Egret 2.4
  3841. * @platform Web,Native
  3842. * @language en_US
  3843. */
  3844. /**
  3845. * 与 name 属性相关联的值,如 text/plain
  3846. * @version Egret 2.4
  3847. * @platform Web,Native
  3848. * @language zh_CN
  3849. */
  3850. this.value = "";
  3851. this.name = name;
  3852. this.value = value;
  3853. }
  3854. return URLRequestHeader;
  3855. }());
  3856. egret.URLRequestHeader = URLRequestHeader;
  3857. __reflect(URLRequestHeader.prototype, "egret.URLRequestHeader");
  3858. })(egret || (egret = {}));
  3859. //////////////////////////////////////////////////////////////////////////////////////
  3860. //
  3861. // Copyright (c) 2014-present, Egret Technology.
  3862. // All rights reserved.
  3863. // Redistribution and use in source and binary forms, with or without
  3864. // modification, are permitted provided that the following conditions are met:
  3865. //
  3866. // * Redistributions of source code must retain the above copyright
  3867. // notice, this list of conditions and the following disclaimer.
  3868. // * Redistributions in binary form must reproduce the above copyright
  3869. // notice, this list of conditions and the following disclaimer in the
  3870. // documentation and/or other materials provided with the distribution.
  3871. // * Neither the name of the Egret nor the
  3872. // names of its contributors may be used to endorse or promote products
  3873. // derived from this software without specific prior written permission.
  3874. //
  3875. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3876. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3877. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3878. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3879. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3880. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3881. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3882. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3883. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3884. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3885. //
  3886. //////////////////////////////////////////////////////////////////////////////////////
  3887. var egret;
  3888. (function (egret) {
  3889. /**
  3890. * The URLRequestMethod class provides values that specify whether the
  3891. * URLRequest object should use the POST method or the GET method when sending data to a server.
  3892. * @see http://edn.egret.com/cn/docs/page/599 POST与GET
  3893. * @version Egret 2.4
  3894. * @platform Web,Native
  3895. * @includeExample extension/game/net/URLRequestMethod.ts
  3896. * @language en_US
  3897. */
  3898. /**
  3899. * URLRequestMethod 类提供了一些值,这些值可指定在将数据发送到服务器时,
  3900. * URLRequest 对象应使用 POST 方法还是 GET 方法。
  3901. * @see http://edn.egret.com/cn/docs/page/599 POST与GET
  3902. * @version Egret 2.4
  3903. * @platform Web,Native
  3904. * @includeExample extension/game/net/URLRequestMethod.ts
  3905. * @language zh_CN
  3906. */
  3907. var URLRequestMethod = (function () {
  3908. function URLRequestMethod() {
  3909. }
  3910. /**
  3911. * Specify that the URLRequest object is a GET.
  3912. * @version Egret 2.4
  3913. * @platform Web,Native
  3914. * @language en_US
  3915. */
  3916. /**
  3917. * 表示 URLRequest 对象是一个 GET。
  3918. * @version Egret 2.4
  3919. * @platform Web,Native
  3920. * @language zh_CN
  3921. */
  3922. URLRequestMethod.GET = "get";
  3923. /**
  3924. * Specify that the URLRequest object is a POST.
  3925. * @version Egret 2.4
  3926. * @platform Web,Native
  3927. * @language en_US
  3928. */
  3929. /**
  3930. * 表示 URLRequest 对象是一个 POST。
  3931. * @version Egret 2.4
  3932. * @platform Web,Native
  3933. * @language zh_CN
  3934. */
  3935. URLRequestMethod.POST = "post";
  3936. return URLRequestMethod;
  3937. }());
  3938. egret.URLRequestMethod = URLRequestMethod;
  3939. __reflect(URLRequestMethod.prototype, "egret.URLRequestMethod");
  3940. })(egret || (egret = {}));
  3941. //////////////////////////////////////////////////////////////////////////////////////
  3942. //
  3943. // Copyright (c) 2014-present, Egret Technology.
  3944. // All rights reserved.
  3945. // Redistribution and use in source and binary forms, with or without
  3946. // modification, are permitted provided that the following conditions are met:
  3947. //
  3948. // * Redistributions of source code must retain the above copyright
  3949. // notice, this list of conditions and the following disclaimer.
  3950. // * Redistributions in binary form must reproduce the above copyright
  3951. // notice, this list of conditions and the following disclaimer in the
  3952. // documentation and/or other materials provided with the distribution.
  3953. // * Neither the name of the Egret nor the
  3954. // names of its contributors may be used to endorse or promote products
  3955. // derived from this software without specific prior written permission.
  3956. //
  3957. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  3958. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  3959. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  3960. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  3961. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3962. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  3963. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3964. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3965. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3966. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3967. //
  3968. //////////////////////////////////////////////////////////////////////////////////////
  3969. var egret;
  3970. (function (egret) {
  3971. /**
  3972. * The URLVariables class allows you to transfer variables between an application and a server.
  3973. * Use URLVariables objects with methods of the URLLoader class and the data property of the URLRequest class.
  3974. * @see http://edn.egret.com/cn/docs/page/598 Send the request with parameters
  3975. * @version Egret 2.4
  3976. * @platform Web,Native
  3977. * @includeExample extension/game/net/URLVariables.ts
  3978. * @language en_US
  3979. */
  3980. /**
  3981. * 使用 URLVariables 类可以在应用程序和服务器之间传输变量。
  3982. * 将 URLVariables 对象与 URLLoader 类的方法、URLRequest 类的 data 属性一起使用。
  3983. * @see http://edn.egret.com/cn/docs/page/598 发送带参数的请求
  3984. * @version Egret 2.4
  3985. * @platform Web,Native
  3986. * @includeExample extension/game/net/URLVariables.ts
  3987. * @language zh_CN
  3988. */
  3989. var URLVariables = (function (_super) {
  3990. __extends(URLVariables, _super);
  3991. /**
  3992. * Create an egret.URLVariable object
  3993. * @param source {String} A URL-encoded string containing name/value pairs.
  3994. * @version Egret 2.4
  3995. * @platform Web,Native
  3996. * @language en_US
  3997. */
  3998. /**
  3999. * 创建一个 egret.URLVariables 对象
  4000. * @param source {String} 包含名称/值对的 URL 编码的字符串。
  4001. * @version Egret 2.4
  4002. * @platform Web,Native
  4003. * @language zh_CN
  4004. */
  4005. function URLVariables(source) {
  4006. if (source === void 0) { source = null; }
  4007. var _this = _super.call(this) || this;
  4008. /**
  4009. * Key-value pair data object saved in this URLVariables object
  4010. * @version Egret 2.4
  4011. * @platform Web,Native
  4012. * @language en_US
  4013. */
  4014. /**
  4015. * 此 URLVariables 储存的键值对数据对象。
  4016. * @version Egret 2.4
  4017. * @platform Web,Native
  4018. * @language zh_CN
  4019. */
  4020. _this.variables = null;
  4021. if (source !== null) {
  4022. _this.decode(source);
  4023. }
  4024. return _this;
  4025. }
  4026. /**
  4027. * Convert the variable string into the property of this URLVariables.variables object.
  4028. * @param source {string}
  4029. * @version Egret 2.4
  4030. * @platform Web,Native
  4031. * @language en_US
  4032. */
  4033. /**
  4034. * 将变量字符串转换为此 URLVariables.variables 对象的属性。
  4035. * @param source {string}
  4036. * @version Egret 2.4
  4037. * @platform Web,Native
  4038. * @language zh_CN
  4039. */
  4040. URLVariables.prototype.decode = function (source) {
  4041. if (!this.variables) {
  4042. this.variables = {};
  4043. }
  4044. source = source.split("+").join(" ");
  4045. var tokens, re = /[?&]?([^=]+)=([^&]*)/g;
  4046. while (tokens = re.exec(source)) {
  4047. var key = decodeURIComponent(tokens[1]), val = decodeURIComponent(tokens[2]);
  4048. //没有重复键值,直接赋值
  4049. if ((key in this.variables) == false) {
  4050. this.variables[key] = val;
  4051. continue;
  4052. }
  4053. //有重复键值,如果已经存在数组,直接push到数组,否则创建一个新数组
  4054. var value = this.variables[key];
  4055. if (value instanceof Array) {
  4056. value.push(val);
  4057. }
  4058. else {
  4059. this.variables[key] = [value, val];
  4060. }
  4061. }
  4062. };
  4063. /**
  4064. * Return a string containing all enumerable variables using the MIME content encoding format : application/x-www-form-urlencoded.
  4065. * @version Egret 2.4
  4066. * @platform Web,Native
  4067. * @language en_US
  4068. */
  4069. /**
  4070. * 以 MIME 内容编码格式 application/x-www-form-urlencoded 返回包含所有可枚举变量的字符串。
  4071. * @version Egret 2.4
  4072. * @platform Web,Native
  4073. * @language zh_CN
  4074. */
  4075. URLVariables.prototype.toString = function () {
  4076. if (!this.variables) {
  4077. return "";
  4078. }
  4079. var variables = this.variables;
  4080. var stringArray = [];
  4081. for (var key in variables) {
  4082. stringArray.push(this.encodeValue(key, variables[key]));
  4083. }
  4084. return stringArray.join("&");
  4085. };
  4086. /**
  4087. * @private
  4088. *
  4089. * @param key
  4090. * @param value
  4091. */
  4092. URLVariables.prototype.encodeValue = function (key, value) {
  4093. if (value instanceof Array) {
  4094. return this.encodeArray(key, value);
  4095. }
  4096. else {
  4097. return encodeURIComponent(key) + "=" + encodeURIComponent(value);
  4098. }
  4099. };
  4100. /**
  4101. * @private
  4102. *
  4103. * @param key
  4104. * @param value
  4105. */
  4106. URLVariables.prototype.encodeArray = function (key, value) {
  4107. if (!key)
  4108. return "";
  4109. if (value.length == 0) {
  4110. return encodeURIComponent(key) + "=";
  4111. }
  4112. return value.map(function (v) { return encodeURIComponent(key) + "=" + encodeURIComponent(v); }).join("&");
  4113. };
  4114. return URLVariables;
  4115. }(egret.HashObject));
  4116. egret.URLVariables = URLVariables;
  4117. __reflect(URLVariables.prototype, "egret.URLVariables");
  4118. })(egret || (egret = {}));
  4119. //////////////////////////////////////////////////////////////////////////////////////
  4120. //
  4121. // Copyright (c) 2014-present, Egret Technology.
  4122. // All rights reserved.
  4123. // Redistribution and use in source and binary forms, with or without
  4124. // modification, are permitted provided that the following conditions are met:
  4125. //
  4126. // * Redistributions of source code must retain the above copyright
  4127. // notice, this list of conditions and the following disclaimer.
  4128. // * Redistributions in binary form must reproduce the above copyright
  4129. // notice, this list of conditions and the following disclaimer in the
  4130. // documentation and/or other materials provided with the distribution.
  4131. // * Neither the name of the Egret nor the
  4132. // names of its contributors may be used to endorse or promote products
  4133. // derived from this software without specific prior written permission.
  4134. //
  4135. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4136. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4137. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4138. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4139. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4140. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4141. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4142. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4143. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4144. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4145. //
  4146. //////////////////////////////////////////////////////////////////////////////////////
  4147. var egret;
  4148. (function (egret) {
  4149. /**
  4150. * @version Egret 2.4
  4151. * @platform Web,Native
  4152. * @includeExample extension/game/player/Ticker.ts
  4153. * @language en_US
  4154. */
  4155. /**
  4156. * @version Egret 2.4
  4157. * @platform Web,Native
  4158. * @includeExample extension/game/player/Ticker.ts
  4159. * @language zh_CN
  4160. */
  4161. var Ticker = (function (_super) {
  4162. __extends(Ticker, _super);
  4163. /**
  4164. * @deprecated
  4165. * @version Egret 2.4
  4166. * @platform Web,Native
  4167. */
  4168. function Ticker() {
  4169. var _this = _super.call(this) || this;
  4170. _this._timeScale = 1;
  4171. _this._paused = false;
  4172. _this._callIndex = -1;
  4173. _this._lastTime = 0;
  4174. _this.callBackList = [];
  4175. if (Ticker.instance != null) {
  4176. if (true) {
  4177. egret.$error(1033);
  4178. }
  4179. }
  4180. egret.ticker.$startTick(_this.update, _this);
  4181. _this._lastTime = egret.getTimer();
  4182. return _this;
  4183. }
  4184. Ticker.prototype.update = function (timeStamp) {
  4185. var advancedTime = timeStamp - this._lastTime;
  4186. this._lastTime = timeStamp;
  4187. if (this._paused) {
  4188. return false;
  4189. }
  4190. var frameTime = advancedTime * this._timeScale;
  4191. this._callList = this.callBackList.concat();
  4192. this._callIndex = 0;
  4193. for (; this._callIndex < this._callList.length; this._callIndex++) {
  4194. var eventBin = this._callList[this._callIndex];
  4195. eventBin.listener.call(eventBin.thisObject, frameTime);
  4196. }
  4197. this._callIndex = -1;
  4198. this._callList = null;
  4199. return false;
  4200. };
  4201. /**
  4202. * 注册帧回调事件,同一函数的重复监听会被忽略。推荐使用 egret.startTick 替代此方法。
  4203. * @method egret.Ticker#register
  4204. * @param listener {Function} 帧回调函数,参数返回上一帧和这帧的间隔时间。示例:onEnterFrame(frameTime:number):void
  4205. * @param thisObject {any} 帧回调函数的this对象
  4206. * @param priority {number} 事件优先级,开发者请勿传递 Number.NEGATIVE_INFINITY 和 Number.POSITIVE_INFINITY
  4207. * @version Egret 2.4
  4208. * @platform Web,Native
  4209. * @deprecated
  4210. */
  4211. Ticker.prototype.register = function (listener, thisObject, priority) {
  4212. if (priority === void 0) { priority = 0; }
  4213. this.$insertEventBin(this.callBackList, "", listener, thisObject, false, priority, false);
  4214. };
  4215. /**
  4216. * 取消侦听enterFrame事件。推荐使用 egret.stopTick 替代此方法。
  4217. * @method egret.Ticker#unregister
  4218. * @param listener {Function} 事件侦听函数
  4219. * @param thisObject {any} 侦听函数的this对象
  4220. * @version Egret 2.4
  4221. * @platform Web,Native
  4222. * @deprecated
  4223. */
  4224. Ticker.prototype.unregister = function (listener, thisObject) {
  4225. this.$removeEventBin(this.callBackList, listener, thisObject);
  4226. };
  4227. /**
  4228. * @deprecated
  4229. * @param timeScale {number}
  4230. * @private
  4231. */
  4232. Ticker.prototype.setTimeScale = function (timeScale) {
  4233. this._timeScale = timeScale;
  4234. };
  4235. /**
  4236. * @deprecated
  4237. * @method egret.Ticker#getTimeScale
  4238. * @private
  4239. */
  4240. Ticker.prototype.getTimeScale = function () {
  4241. return this._timeScale;
  4242. };
  4243. /**
  4244. * 暂停
  4245. * @deprecated
  4246. * @method egret.Ticker#pause
  4247. */
  4248. Ticker.prototype.pause = function () {
  4249. this._paused = true;
  4250. };
  4251. /**
  4252. * 继续
  4253. * @deprecated
  4254. * @method egret.Ticker#resume
  4255. */
  4256. Ticker.prototype.resume = function () {
  4257. this._paused = false;
  4258. };
  4259. /**
  4260. * @method egret.Ticker.getInstance
  4261. * @returns {Ticker}
  4262. * @version Egret 2.4
  4263. * @platform Web,Native
  4264. * @deprecated
  4265. */
  4266. Ticker.getInstance = function () {
  4267. if (Ticker.instance == null) {
  4268. Ticker.instance = new Ticker();
  4269. }
  4270. return Ticker.instance;
  4271. };
  4272. return Ticker;
  4273. }(egret.EventDispatcher));
  4274. egret.Ticker = Ticker;
  4275. __reflect(Ticker.prototype, "egret.Ticker");
  4276. })(egret || (egret = {}));
  4277. //////////////////////////////////////////////////////////////////////////////////////
  4278. //
  4279. // Copyright (c) 2014-present, Egret Technology.
  4280. // All rights reserved.
  4281. // Redistribution and use in source and binary forms, with or without
  4282. // modification, are permitted provided that the following conditions are met:
  4283. //
  4284. // * Redistributions of source code must retain the above copyright
  4285. // notice, this list of conditions and the following disclaimer.
  4286. // * Redistributions in binary form must reproduce the above copyright
  4287. // notice, this list of conditions and the following disclaimer in the
  4288. // documentation and/or other materials provided with the distribution.
  4289. // * Neither the name of the Egret nor the
  4290. // names of its contributors may be used to endorse or promote products
  4291. // derived from this software without specific prior written permission.
  4292. //
  4293. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4294. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4295. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4296. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4297. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4298. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4299. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4300. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4301. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4302. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4303. //
  4304. //////////////////////////////////////////////////////////////////////////////////////
  4305. var egret;
  4306. (function (egret) {
  4307. /**
  4308. * @class egret.MainContext
  4309. * @classdesc
  4310. * MainContext是游戏的核心跨平台接口,组合了多个功能Context,并是游戏启动的主入口
  4311. * @extends egret.EventDispatcher
  4312. * @private
  4313. * @version Egret 2.4
  4314. * @platform Web,Native
  4315. */
  4316. var MainContext = (function (_super) {
  4317. __extends(MainContext, _super);
  4318. /**
  4319. * @version Egret 2.4
  4320. * @platform Web,Native
  4321. */
  4322. function MainContext() {
  4323. return _super.call(this) || this;
  4324. }
  4325. Object.defineProperty(MainContext.prototype, "stage", {
  4326. /**
  4327. * 渲染Context
  4328. * @member egret.MainContext#rendererContext
  4329. * @version Egret 2.4
  4330. * @platform Web,Native
  4331. */
  4332. //public rendererContext:RendererContext = null;
  4333. /**
  4334. * 触摸Context
  4335. * @member egret.MainContext#touchContext
  4336. * @version Egret 2.4
  4337. * @platform Web,Native
  4338. */
  4339. //public touchContext:TouchContext = null;
  4340. /**
  4341. * 设备divice
  4342. * @member egret.MainContext#deviceContext
  4343. * @version Egret 2.4
  4344. * @platform Web,Native
  4345. */
  4346. //public deviceContext:DeviceContext = null;
  4347. /**
  4348. * 舞台
  4349. * @member egret.MainContext#stage
  4350. * @version Egret 2.4
  4351. * @platform Web,Native
  4352. */
  4353. get: function () {
  4354. return egret.sys.$TempStage;
  4355. },
  4356. enumerable: true,
  4357. configurable: true
  4358. });
  4359. Object.defineProperty(MainContext, "instance", {
  4360. /**
  4361. * @method egret.Ticker.getInstance
  4362. * @returns {Ticker}
  4363. * @version Egret 2.4
  4364. * @platform Web,Native
  4365. */
  4366. get: function () {
  4367. if (MainContext._instance == null) {
  4368. MainContext._instance = new MainContext();
  4369. }
  4370. return MainContext._instance;
  4371. },
  4372. enumerable: true,
  4373. configurable: true
  4374. });
  4375. /**
  4376. * @version Egret 2.4
  4377. * @platform Web,Native
  4378. */
  4379. MainContext.deviceType = null;
  4380. /**
  4381. * @version Egret 2.4
  4382. * @platform Web,Native
  4383. */
  4384. MainContext.DEVICE_PC = "web";
  4385. /**
  4386. * @version Egret 2.4
  4387. * @platform Web,Native
  4388. */
  4389. MainContext.DEVICE_MOBILE = "native";
  4390. return MainContext;
  4391. }(egret.EventDispatcher));
  4392. egret.MainContext = MainContext;
  4393. __reflect(MainContext.prototype, "egret.MainContext");
  4394. })(egret || (egret = {}));
  4395. /**
  4396. * @private
  4397. */
  4398. egret["testDeviceType1"] = function () {
  4399. if (!window["navigator"]) {
  4400. return true;
  4401. }
  4402. var ua = navigator.userAgent.toLowerCase();
  4403. return (ua.indexOf('mobile') != -1 || ua.indexOf('android') != -1);
  4404. };
  4405. egret.MainContext.deviceType = egret["testDeviceType1"]() ? egret.MainContext.DEVICE_MOBILE : egret.MainContext.DEVICE_PC;
  4406. delete egret["testDeviceType1"];
  4407. //////////////////////////////////////////////////////////////////////////////////////
  4408. //
  4409. // Copyright (c) 2014-present, Egret Technology.
  4410. // All rights reserved.
  4411. // Redistribution and use in source and binary forms, with or without
  4412. // modification, are permitted provided that the following conditions are met:
  4413. //
  4414. // * Redistributions of source code must retain the above copyright
  4415. // notice, this list of conditions and the following disclaimer.
  4416. // * Redistributions in binary form must reproduce the above copyright
  4417. // notice, this list of conditions and the following disclaimer in the
  4418. // documentation and/or other materials provided with the distribution.
  4419. // * Neither the name of the Egret nor the
  4420. // names of its contributors may be used to endorse or promote products
  4421. // derived from this software without specific prior written permission.
  4422. //
  4423. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4424. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4425. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4426. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4427. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4428. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4429. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4430. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4431. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4432. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4433. //
  4434. //////////////////////////////////////////////////////////////////////////////////////
  4435. var egret;
  4436. (function (egret) {
  4437. /**
  4438. * Tool class for object cache repeat use, which can be used to construct an object pool. Objects are automatically recycled after a certain duration.
  4439. * @version Egret 2.4
  4440. * @platform Web,Native
  4441. * @includeExample extension/game/utils/Recycler.ts
  4442. * @private
  4443. * @language en_US
  4444. */
  4445. /**
  4446. * 对象缓存复用工具类,可用于构建对象池,一段时间后会自动回收对象。
  4447. * @version Egret 2.4
  4448. * @platform Web,Native
  4449. * @includeExample extension/game/utils/Recycler.ts
  4450. * @private
  4451. * @language zh_CN
  4452. */
  4453. var Recycler = (function (_super) {
  4454. __extends(Recycler, _super);
  4455. /**
  4456. * Create an egret.Recycler object
  4457. * @param autoDisposeTime {number} Number of frames when objects are destroyed automatically. Default value: 300
  4458. * @version Egret 2.4
  4459. * @platform Web,Native
  4460. * @language en_US
  4461. */
  4462. /**
  4463. * 创建一个 egret.Recycler 对象
  4464. * @param autoDisposeTime {number} 多少帧后自动销毁对象,默认值300
  4465. * @version Egret 2.4
  4466. * @platform Web,Native
  4467. * @language zh_CN
  4468. */
  4469. function Recycler(autoDisposeTime) {
  4470. if (autoDisposeTime === void 0) { autoDisposeTime = 300; }
  4471. var _this = _super.call(this) || this;
  4472. /**
  4473. * @private
  4474. */
  4475. _this.objectPool = [];
  4476. /**
  4477. * @private
  4478. */
  4479. _this._length = 0;
  4480. if (autoDisposeTime < 1)
  4481. autoDisposeTime = 1;
  4482. _this.autoDisposeTime = autoDisposeTime;
  4483. _this.frameCount = 0;
  4484. return _this;
  4485. }
  4486. Recycler.$init = function () {
  4487. egret.ticker.$startTick(Recycler.onUpdate, Recycler);
  4488. };
  4489. Recycler.onUpdate = function (timeStamp) {
  4490. var list = Recycler._callBackList;
  4491. for (var i = list.length - 1; i >= 0; i--) {
  4492. list[i].$checkFrame();
  4493. }
  4494. return false;
  4495. };
  4496. /**
  4497. * @private
  4498. *
  4499. */
  4500. Recycler.prototype.$checkFrame = function () {
  4501. this.frameCount--;
  4502. if (this.frameCount <= 0) {
  4503. this.dispose();
  4504. }
  4505. };
  4506. Object.defineProperty(Recycler.prototype, "length", {
  4507. /**
  4508. * Number of cached objects"
  4509. * @version Egret 2.4
  4510. * @platform Web,Native
  4511. * @language en_US
  4512. */
  4513. /**
  4514. * 缓存的对象数量
  4515. * @version Egret 2.4
  4516. * @platform Web,Native
  4517. * @language zh_CN
  4518. */
  4519. get: function () {
  4520. return this._length;
  4521. },
  4522. enumerable: true,
  4523. configurable: true
  4524. });
  4525. /**
  4526. * Cache an object for repeat use
  4527. * @param object {any} The object to be cached
  4528. * @version Egret 2.4
  4529. * @platform Web,Native
  4530. * @language en_US
  4531. */
  4532. /**
  4533. * 缓存一个对象以复用
  4534. * @param object {any} 需要缓存的对象
  4535. * @version Egret 2.4
  4536. * @platform Web,Native
  4537. * @language zh_CN
  4538. */
  4539. Recycler.prototype.push = function (object) {
  4540. var pool = this.objectPool;
  4541. if (pool.indexOf(object) == -1) {
  4542. pool.push(object);
  4543. if (object.__recycle) {
  4544. object.__recycle();
  4545. }
  4546. this._length++;
  4547. if (this.frameCount == 0) {
  4548. this.frameCount = this.autoDisposeTime;
  4549. Recycler._callBackList.push(this);
  4550. }
  4551. }
  4552. };
  4553. /**
  4554. * Obtain a cached object
  4555. * @returns {any} The obtained cached object
  4556. * @version Egret 2.4
  4557. * @platform Web,Native
  4558. * @language en_US
  4559. */
  4560. /**
  4561. * 获取一个缓存的对象
  4562. * @returns {any} 获得的缓存对象
  4563. * @version Egret 2.4
  4564. * @platform Web,Native
  4565. * @language zh_CN
  4566. */
  4567. Recycler.prototype.pop = function () {
  4568. if (this._length == 0)
  4569. return null;
  4570. this._length--;
  4571. return this.objectPool.pop();
  4572. };
  4573. /**
  4574. * Immediately clear all cached objects.
  4575. * @version Egret 2.4
  4576. * @platform Web,Native
  4577. * @language en_US
  4578. */
  4579. /**
  4580. * 立即清空所有缓存的对象。
  4581. * @version Egret 2.4
  4582. * @platform Web,Native
  4583. * @language zh_CN
  4584. */
  4585. Recycler.prototype.dispose = function () {
  4586. if (this._length > 0) {
  4587. this.objectPool = [];
  4588. this._length = 0;
  4589. }
  4590. this.frameCount = 0;
  4591. var list = Recycler._callBackList;
  4592. var index = list.indexOf(this);
  4593. if (index != -1) {
  4594. list.splice(index, 1);
  4595. }
  4596. };
  4597. /**
  4598. * @private
  4599. */
  4600. Recycler._callBackList = [];
  4601. return Recycler;
  4602. }(egret.HashObject));
  4603. egret.Recycler = Recycler;
  4604. __reflect(Recycler.prototype, "egret.Recycler");
  4605. Recycler.$init();
  4606. })(egret || (egret = {}));
  4607. var egret;
  4608. (function (egret) {
  4609. var setIntervalCache = {};
  4610. var setIntervalIndex = 0;
  4611. var setIntervalCount = 0;
  4612. var lastTime = 0;
  4613. /**
  4614. * To specify a delay (in milliseconds) calls the function specified interval loop.
  4615. * @param listener {Function} Listener function
  4616. * @param thisObject {any} this object
  4617. * @param delay {number} Delay time, in milliseconds
  4618. * @param ...args {any} Parameter list
  4619. * @returns {number} Return index which can be used for clearInterval
  4620. * @version Egret 2.4
  4621. * @platform Web,Native
  4622. * @includeExample extension/game/utils/setInterval.ts
  4623. * @language en_US
  4624. */
  4625. /**
  4626. * 以指定的延迟(以毫秒为单位)间隔循环调用指定的函数。
  4627. * @param listener {Function} 侦听函数
  4628. * @param thisObject {any} this对象
  4629. * @param delay {number} 延迟时间,以毫秒为单位
  4630. * @param ...args {any} 参数列表
  4631. * @returns {number} 返回索引,可以用于 clearInterval
  4632. * @version Egret 2.4
  4633. * @platform Web,Native
  4634. * @includeExample extension/game/utils/setInterval.ts
  4635. * @language zh_CN
  4636. */
  4637. function setInterval(listener, thisObject, delay) {
  4638. var args = [];
  4639. for (var _i = 3; _i < arguments.length; _i++) {
  4640. args[_i - 3] = arguments[_i];
  4641. }
  4642. var data = { listener: listener, thisObject: thisObject, delay: delay, originDelay: delay, params: args };
  4643. setIntervalCount++;
  4644. if (setIntervalCount == 1) {
  4645. lastTime = egret.getTimer();
  4646. egret.ticker.$startTick(intervalUpdate, null);
  4647. }
  4648. setIntervalIndex++;
  4649. setIntervalCache[setIntervalIndex] = data;
  4650. return setIntervalIndex;
  4651. }
  4652. egret.setInterval = setInterval;
  4653. /**
  4654. * Clear function to run after a specified delay.
  4655. * @param key {number} Index that egret.setInterval returns
  4656. * @version Egret 2.4
  4657. * @platform Web,Native
  4658. * @includeExample egret/utils/setInterval.ts
  4659. * @language en_US
  4660. */
  4661. /**
  4662. * 清除指定延迟后运行的函数。
  4663. * @param key {number} egret.setInterval所返回的索引
  4664. * @version Egret 2.4
  4665. * @platform Web,Native
  4666. * @includeExample egret/utils/setInterval.ts
  4667. * @language zh_CN
  4668. */
  4669. function clearInterval(key) {
  4670. if (setIntervalCache[key]) {
  4671. setIntervalCount--;
  4672. delete setIntervalCache[key];
  4673. if (setIntervalCount == 0) {
  4674. egret.ticker.$stopTick(intervalUpdate, null);
  4675. }
  4676. }
  4677. }
  4678. egret.clearInterval = clearInterval;
  4679. /**
  4680. * @private
  4681. *
  4682. * @param dt
  4683. */
  4684. function intervalUpdate(timeStamp) {
  4685. var dt = timeStamp - lastTime;
  4686. lastTime = timeStamp;
  4687. for (var key in setIntervalCache) {
  4688. var data = setIntervalCache[key];
  4689. data.delay -= dt;
  4690. if (data.delay <= 0) {
  4691. data.delay = data.originDelay;
  4692. data.listener.apply(data.thisObject, data.params);
  4693. }
  4694. }
  4695. return false;
  4696. }
  4697. })(egret || (egret = {}));
  4698. //////////////////////////////////////////////////////////////////////////////////////
  4699. //
  4700. // Copyright (c) 2014-present, Egret Technology.
  4701. // All rights reserved.
  4702. // Redistribution and use in source and binary forms, with or without
  4703. // modification, are permitted provided that the following conditions are met:
  4704. //
  4705. // * Redistributions of source code must retain the above copyright
  4706. // notice, this list of conditions and the following disclaimer.
  4707. // * Redistributions in binary form must reproduce the above copyright
  4708. // notice, this list of conditions and the following disclaimer in the
  4709. // documentation and/or other materials provided with the distribution.
  4710. // * Neither the name of the Egret nor the
  4711. // names of its contributors may be used to endorse or promote products
  4712. // derived from this software without specific prior written permission.
  4713. //
  4714. // THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  4715. // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  4716. // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  4717. // IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  4718. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4719. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
  4720. // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4721. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4722. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4723. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4724. //
  4725. //////////////////////////////////////////////////////////////////////////////////////
  4726. var egret;
  4727. (function (egret) {
  4728. var setTimeoutCache = {};
  4729. var setTimeoutIndex = 0;
  4730. var setTimeoutCount = 0;
  4731. var lastTime = 0;
  4732. /**
  4733. * Run the designated function in specified delay (in milliseconds).
  4734. * @param listener {Function} Listener function
  4735. * @param thisObject {any} this object
  4736. * @param delay {number} Delay time, in milliseconds
  4737. * @param ...args {any} Parameter list
  4738. * @returns {number} Return index which can be used for clearTimeout
  4739. * @version Egret 2.4
  4740. * @platform Web,Native
  4741. * @includeExample extension/game/utils/setTimeout.ts
  4742. * @language en_US
  4743. */
  4744. /**
  4745. * 在指定的延迟(以毫秒为单位)后运行指定的函数。
  4746. * @param listener {Function} 侦听函数
  4747. * @param thisObject {any} this对象
  4748. * @param delay {number} 延迟时间,以毫秒为单位
  4749. * @param ...args {any} 参数列表
  4750. * @returns {number} 返回索引,可以用于 clearTimeout
  4751. * @version Egret 2.4
  4752. * @platform Web,Native
  4753. * @includeExample extension/game/utils/setTimeout.ts
  4754. * @language zh_CN
  4755. */
  4756. function setTimeout(listener, thisObject, delay) {
  4757. var args = [];
  4758. for (var _i = 3; _i < arguments.length; _i++) {
  4759. args[_i - 3] = arguments[_i];
  4760. }
  4761. var data = { listener: listener, thisObject: thisObject, delay: delay, params: args };
  4762. setTimeoutCount++;
  4763. if (setTimeoutCount == 1 && egret.ticker) {
  4764. lastTime = egret.getTimer();
  4765. egret.ticker.$startTick(timeoutUpdate, null);
  4766. }
  4767. setTimeoutIndex++;
  4768. setTimeoutCache[setTimeoutIndex] = data;
  4769. return setTimeoutIndex;
  4770. }
  4771. egret.setTimeout = setTimeout;
  4772. /**
  4773. * Function run after the specified delay is cleared.
  4774. * @param key {number} Index that egret.setTimeout returns
  4775. * @version Egret 2.4
  4776. * @platform Web,Native
  4777. * @language en_US
  4778. */
  4779. /**
  4780. * 清除指定延迟后运行的函数。
  4781. * @param key {number} egret.setTimeout所返回的索引
  4782. * @version Egret 2.4
  4783. * @platform Web,Native
  4784. * @language zh_CN
  4785. */
  4786. function clearTimeout(key) {
  4787. if (setTimeoutCache[key]) {
  4788. setTimeoutCount--;
  4789. delete setTimeoutCache[key];
  4790. if (setTimeoutCount == 0 && egret.ticker) {
  4791. egret.ticker.$stopTick(timeoutUpdate, null);
  4792. }
  4793. }
  4794. }
  4795. egret.clearTimeout = clearTimeout;
  4796. /**
  4797. * @private
  4798. *
  4799. * @param dt
  4800. */
  4801. function timeoutUpdate(timeStamp) {
  4802. var dt = timeStamp - lastTime;
  4803. lastTime = timeStamp;
  4804. for (var key in setTimeoutCache) {
  4805. var key2 = key;
  4806. var data = setTimeoutCache[key2];
  4807. data.delay -= dt;
  4808. if (data.delay <= 0) {
  4809. data.listener.apply(data.thisObject, data.params);
  4810. clearTimeout(key2);
  4811. }
  4812. }
  4813. return false;
  4814. }
  4815. })(egret || (egret = {}));