| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703 |
- var cc = cc || {};
- cc._tmp = cc._tmp || {};
- cc._LogInfos = {};
- var _p = window;
- _p.gl;
- _p.WebGLRenderingContext;
- _p.DeviceOrientationEvent;
- _p.DeviceMotionEvent;
- _p.AudioContext;
- if (!_p.AudioContext) {
- _p.webkitAudioContext;
- }
- _p.mozAudioContext;
- _p = Object.prototype;
- _p._super;
- _p.ctor;
- _p = null;
- cc.ORIENTATION_PORTRAIT = 0;
- cc.ORIENTATION_PORTRAIT_UPSIDE_DOWN = 1;
- cc.ORIENTATION_LANDSCAPE_LEFT = 2;
- cc.ORIENTATION_LANDSCAPE_RIGHT = 3;
- cc._drawingUtil = null;
- cc._renderContext = null;
- cc._supportRender = false;
- cc._canvas = null;
- cc.container = null;
- cc._gameDiv = null;
- cc.newElement = function (x) {
- return document.createElement(x);
- };
- cc.each = function (obj, iterator, context) {
- if (!obj)
- return;
- if (obj instanceof Array) {
- for (var i = 0, li = obj.length; i < li; i++) {
- if (iterator.call(context, obj[i], i) === false)
- return;
- }
- } else {
- for (var key in obj) {
- if (iterator.call(context, obj[key], key) === false)
- return;
- }
- }
- };
- cc.extend = function(target) {
- var sources = arguments.length >= 2 ? Array.prototype.slice.call(arguments, 1) : [];
- cc.each(sources, function(src) {
- for(var key in src) {
- if (src.hasOwnProperty(key)) {
- target[key] = src[key];
- }
- }
- });
- return target;
- };
- cc.isFunction = function(obj) {
- return typeof obj === 'function';
- };
- cc.isNumber = function(obj) {
- return typeof obj === 'number' || Object.prototype.toString.call(obj) === '[object Number]';
- };
- cc.isString = function(obj) {
- return typeof obj === 'string' || Object.prototype.toString.call(obj) === '[object String]';
- };
- cc.isArray = function(obj) {
- return Array.isArray(obj) ||
- (typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Array]');
- };
- cc.isUndefined = function(obj) {
- return typeof obj === 'undefined';
- };
- cc.isObject = function(obj) {
- return typeof obj === "object" && Object.prototype.toString.call(obj) === '[object Object]';
- };
- cc.isCrossOrigin = function (url) {
- if (!url) {
- cc.log("invalid URL");
- return false;
- }
- var startIndex = url.indexOf("://");
- if (startIndex === -1)
- return false;
- var endIndex = url.indexOf("/", startIndex + 3);
- var urlOrigin = (endIndex === -1) ? url : url.substring(0, endIndex);
- return urlOrigin !== location.origin;
- };
- cc.AsyncPool = function(srcObj, limit, iterator, onEnd, target){
- var self = this;
- self._srcObj = srcObj;
- self._limit = limit;
- self._pool = [];
- self._iterator = iterator;
- self._iteratorTarget = target;
- self._onEnd = onEnd;
- self._onEndTarget = target;
- self._results = srcObj instanceof Array ? [] : {};
- self._errors = srcObj instanceof Array ? [] : {};
- cc.each(srcObj, function(value, index){
- self._pool.push({index : index, value : value});
- });
- self.size = self._pool.length;
- self.finishedSize = 0;
- self._workingSize = 0;
- self._limit = self._limit || self.size;
- self.onIterator = function(iterator, target){
- self._iterator = iterator;
- self._iteratorTarget = target;
- };
- self.onEnd = function(endCb, endCbTarget){
- self._onEnd = endCb;
- self._onEndTarget = endCbTarget;
- };
- self._handleItem = function(){
- var self = this;
- if(self._pool.length === 0 || self._workingSize >= self._limit)
- return;
- var item = self._pool.shift();
- var value = item.value, index = item.index;
- self._workingSize++;
- self._iterator.call(self._iteratorTarget, value, index,
- function(err, result) {
- self.finishedSize++;
- self._workingSize--;
- if (err) {
- self._errors[this.index] = err;
- }
- else {
- self._results[this.index] = result;
- }
- if (self.finishedSize === self.size) {
- if (self._onEnd) {
- var errors = self._errors.length === 0 ? null : self._errors;
- self._onEnd.call(self._onEndTarget, errors, self._results);
- }
- return;
- }
- self._handleItem();
- }.bind(item),
- self);
- };
- self.flow = function(){
- var self = this;
- if(self._pool.length === 0) {
- if(self._onEnd)
- self._onEnd.call(self._onEndTarget, null, []);
- return;
- }
- for(var i = 0; i < self._limit; i++)
- self._handleItem();
- };
- };
- cc.async = {
- series : function(tasks, cb, target){
- var asyncPool = new cc.AsyncPool(tasks, 1, function(func, index, cb1){
- func.call(target, cb1);
- }, cb, target);
- asyncPool.flow();
- return asyncPool;
- },
- parallel : function(tasks, cb, target){
- var asyncPool = new cc.AsyncPool(tasks, 0, function(func, index, cb1){
- func.call(target, cb1);
- }, cb, target);
- asyncPool.flow();
- return asyncPool;
- },
- waterfall : function(tasks, cb, target){
- var args = [];
- var lastResults = [null];//the array to store the last results
- var asyncPool = new cc.AsyncPool(tasks, 1,
- function (func, index, cb1) {
- args.push(function (err) {
- args = Array.prototype.slice.call(arguments, 1);
- if(tasks.length - 1 === index) lastResults = lastResults.concat(args);//while the last task
- cb1.apply(null, arguments);
- });
- func.apply(target, args);
- }, function (err) {
- if (!cb)
- return;
- if (err)
- return cb.call(target, err);
- cb.apply(target, lastResults);
- });
- asyncPool.flow();
- return asyncPool;
- },
- map : function(tasks, iterator, callback, target){
- var locIterator = iterator;
- if(typeof(iterator) === "object"){
- callback = iterator.cb;
- target = iterator.iteratorTarget;
- locIterator = iterator.iterator;
- }
- var asyncPool = new cc.AsyncPool(tasks, 0, locIterator, callback, target);
- asyncPool.flow();
- return asyncPool;
- },
- mapLimit : function(tasks, limit, iterator, cb, target){
- var asyncPool = new cc.AsyncPool(tasks, limit, iterator, cb, target);
- asyncPool.flow();
- return asyncPool;
- }
- };
- cc.path = {
- normalizeRE: /[^\.\/]+\/\.\.\//,
- join: function () {
- var l = arguments.length;
- var result = "";
- for (var i = 0; i < l; i++) {
- result = (result + (result === "" ? "" : "/") + arguments[i]).replace(/(\/|\\\\)$/, "");
- }
- return result;
- },
- extname: function (pathStr) {
- var temp = /(\.[^\.\/\?\\]*)(\?.*)?$/.exec(pathStr);
- return temp ? temp[1] : null;
- },
- mainFileName: function(fileName){
- if(fileName){
- var idx = fileName.lastIndexOf(".");
- if(idx !== -1)
- return fileName.substring(0,idx);
- }
- return fileName;
- },
- basename: function (pathStr, extname) {
- var index = pathStr.indexOf("?");
- if (index > 0) pathStr = pathStr.substring(0, index);
- var reg = /(\/|\\\\)([^(\/|\\\\)]+)$/g;
- var result = reg.exec(pathStr.replace(/(\/|\\\\)$/, ""));
- if (!result) return null;
- var baseName = result[2];
- if (extname && pathStr.substring(pathStr.length - extname.length).toLowerCase() === extname.toLowerCase())
- return baseName.substring(0, baseName.length - extname.length);
- return baseName;
- },
- dirname: function (pathStr) {
- return pathStr.replace(/((.*)(\/|\\|\\\\))?(.*?\..*$)?/, '$2');
- },
- changeExtname: function (pathStr, extname) {
- extname = extname || "";
- var index = pathStr.indexOf("?");
- var tempStr = "";
- if (index > 0) {
- tempStr = pathStr.substring(index);
- pathStr = pathStr.substring(0, index);
- }
- index = pathStr.lastIndexOf(".");
- if (index < 0) return pathStr + extname + tempStr;
- return pathStr.substring(0, index) + extname + tempStr;
- },
- changeBasename: function (pathStr, basename, isSameExt) {
- if (basename.indexOf(".") === 0) return this.changeExtname(pathStr, basename);
- var index = pathStr.indexOf("?");
- var tempStr = "";
- var ext = isSameExt ? this.extname(pathStr) : "";
- if (index > 0) {
- tempStr = pathStr.substring(index);
- pathStr = pathStr.substring(0, index);
- }
- index = pathStr.lastIndexOf("/");
- index = index <= 0 ? 0 : index + 1;
- return pathStr.substring(0, index) + basename + ext + tempStr;
- },
- _normalize: function(url){
- var oldUrl = url = String(url);
- do {
- oldUrl = url;
- url = url.replace(this.normalizeRE, "");
- } while(oldUrl.length !== url.length);
- return url;
- }
- };
- cc.loader = (function () {
- var _jsCache = {},
- _register = {},
- _langPathCache = {},
- _aliases = {},
- _queue = {},
- _urlRegExp = new RegExp(
- "^" +
- "(?:(?:https?|ftp)://)" +
- "(?:\\S+(?::\\S*)?@)?" +
- "(?:" +
- "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
- "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
- "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
- "|" +
- "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
- "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
- "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
- "|" +
- "(?:localhost)" +
- ")" +
- "(?::\\d{2,5})?" +
- "(?:/\\S*)?" +
- "$", "i"
- );
- return {
- resPath: "",
- audioPath: "",
- cache: {},
- getXMLHttpRequest: function () {
- return window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
- },
- _getArgs4Js: function (args) {
- var a0 = args[0], a1 = args[1], a2 = args[2], results = ["", null, null];
- if (args.length === 1) {
- results[1] = a0 instanceof Array ? a0 : [a0];
- } else if (args.length === 2) {
- if (typeof a1 === "function") {
- results[1] = a0 instanceof Array ? a0 : [a0];
- results[2] = a1;
- } else {
- results[0] = a0 || "";
- results[1] = a1 instanceof Array ? a1 : [a1];
- }
- } else if (args.length === 3) {
- results[0] = a0 || "";
- results[1] = a1 instanceof Array ? a1 : [a1];
- results[2] = a2;
- } else throw new Error("arguments error to load js!");
- return results;
- },
- isLoading: function (url) {
- return (_queue[url] !== undefined);
- },
- loadJs: function (baseDir, jsList, cb) {
- var self = this,
- args = self._getArgs4Js(arguments);
- var preDir = args[0], list = args[1], callback = args[2];
- if (navigator.userAgent.indexOf("Trident/5") > -1) {
- self._loadJs4Dependency(preDir, list, 0, callback);
- } else {
- cc.async.map(list, function (item, index, cb1) {
- var jsPath = cc.path.join(preDir, item);
- if (_jsCache[jsPath]) return cb1(null);
- self._createScript(jsPath, false, cb1);
- }, callback);
- }
- },
- loadJsWithImg: function (baseDir, jsList, cb) {
- var self = this, jsLoadingImg = self._loadJsImg(),
- args = self._getArgs4Js(arguments);
- this.loadJs(args[0], args[1], function (err) {
- if (err) throw new Error(err);
- jsLoadingImg.parentNode.removeChild(jsLoadingImg);//remove loading gif
- if (args[2]) args[2]();
- });
- },
- _createScript: function (jsPath, isAsync, cb) {
- var d = document, self = this, s = document.createElement('script');
- s.async = isAsync;
- _jsCache[jsPath] = true;
- if(cc.game.config["noCache"] && typeof jsPath === "string"){
- if(self._noCacheRex.test(jsPath))
- s.src = jsPath + "&_t=" + (new Date() - 0);
- else
- s.src = jsPath + "?_t=" + (new Date() - 0);
- }else{
- s.src = jsPath;
- }
- s.addEventListener('load', function () {
- s.parentNode.removeChild(s);
- this.removeEventListener('load', arguments.callee, false);
- cb();
- }, false);
- s.addEventListener('error', function () {
- s.parentNode.removeChild(s);
- cb("Load " + jsPath + " failed!");
- }, false);
- d.body.appendChild(s);
- },
- _loadJs4Dependency: function (baseDir, jsList, index, cb) {
- if (index >= jsList.length) {
- if (cb) cb();
- return;
- }
- var self = this;
- self._createScript(cc.path.join(baseDir, jsList[index]), false, function (err) {
- if (err) return cb(err);
- self._loadJs4Dependency(baseDir, jsList, index + 1, cb);
- });
- },
- _loadJsImg: function () {
- var d = document, jsLoadingImg = d.getElementById("cocos2d_loadJsImg");
- if (!jsLoadingImg) {
- jsLoadingImg = document.createElement('img');
- if (cc._loadingImage)
- jsLoadingImg.src = cc._loadingImage;
- var canvasNode = d.getElementById(cc.game.config["id"]);
- canvasNode.style.backgroundColor = "transparent";
- canvasNode.parentNode.appendChild(jsLoadingImg);
- var canvasStyle = getComputedStyle ? getComputedStyle(canvasNode) : canvasNode.currentStyle;
- if (!canvasStyle)
- canvasStyle = {width: canvasNode.width, height: canvasNode.height};
- jsLoadingImg.style.left = canvasNode.offsetLeft + (parseFloat(canvasStyle.width) - jsLoadingImg.width) / 2 + "px";
- jsLoadingImg.style.top = canvasNode.offsetTop + (parseFloat(canvasStyle.height) - jsLoadingImg.height) / 2 + "px";
- jsLoadingImg.style.position = "absolute";
- }
- return jsLoadingImg;
- },
- loadTxt: function (url, cb) {
- if (!cc._isNodeJs) {
- var xhr = this.getXMLHttpRequest(),
- errInfo = "load " + url + " failed!";
- xhr.open("GET", url, true);
- if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
- xhr.setRequestHeader("Accept-Charset", "utf-8");
- xhr.onreadystatechange = function () {
- if(xhr.readyState === 4)
- xhr.status === 200 ? cb(null, xhr.responseText) : cb({status:xhr.status, errorMessage:errInfo}, null);
- };
- } else {
- if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8");
- xhr.onload = function () {
- if(xhr.readyState === 4)
- xhr.status === 200 ? cb(null, xhr.responseText) : cb({status:xhr.status, errorMessage:errInfo}, null);
- };
- xhr.onerror = function(){
- cb({status:xhr.status, errorMessage:errInfo}, null);
- };
- }
- xhr.send(null);
- } else {
- var fs = require("fs");
- fs.readFile(url, function (err, data) {
- err ? cb(err) : cb(null, data.toString());
- });
- }
- },
- _loadTxtSync: function (url) {
- if (!cc._isNodeJs) {
- var xhr = this.getXMLHttpRequest();
- xhr.open("GET", url, false);
- if (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
- xhr.setRequestHeader("Accept-Charset", "utf-8");
- } else {
- if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=utf-8");
- }
- xhr.send(null);
- if (!xhr.readyState === 4 || xhr.status !== 200) {
- return null;
- }
- return xhr.responseText;
- } else {
- var fs = require("fs");
- return fs.readFileSync(url).toString();
- }
- },
- loadCsb: function(url, cb){
- var xhr = new XMLHttpRequest(),
- errInfo = "load " + url + " failed!";
- xhr.open("GET", url, true);
- xhr.responseType = "arraybuffer";
- xhr.onload = function () {
- var arrayBuffer = xhr.response;
- if (arrayBuffer) {
- window.msg = arrayBuffer;
- }
- if(xhr.readyState === 4)
- xhr.status === 200 ? cb(null, xhr.response) : cb({status:xhr.status, errorMessage:errInfo}, null);
- };
- xhr.onerror = function(){
- cb({status:xhr.status, errorMessage:errInfo}, null);
- };
- xhr.send(null);
- },
- loadJson: function (url, cb) {
- this.loadTxt(url, function (err, txt) {
- if (err) {
- cb(err);
- }
- else {
- try {
- var result = JSON.parse(txt);
- }
- catch (e) {
- throw new Error("parse json [" + url + "] failed : " + e);
- return;
- }
- cb(null, result);
- }
- });
- },
- _checkIsImageURL: function (url) {
- var ext = /(\.png)|(\.jpg)|(\.bmp)|(\.jpeg)|(\.gif)/.exec(url);
- return (ext != null);
- },
- loadImg: function (url, option, callback) {
- var opt = {
- isCrossOrigin: true
- };
- if (callback !== undefined)
- opt.isCrossOrigin = option.isCrossOrigin === undefined ? opt.isCrossOrigin : option.isCrossOrigin;
- else if (option !== undefined)
- callback = option;
- var img = this.getRes(url);
- if (img) {
- callback && callback(null, img);
- return img;
- }
- var queue = _queue[url];
- if (queue) {
- queue.callbacks.push(callback);
- return queue.img;
- }
- img = new Image();
- if (opt.isCrossOrigin && location.origin !== "file://")
- img.crossOrigin = "Anonymous";
- var loadCallback = function () {
- this.removeEventListener('load', loadCallback, false);
- this.removeEventListener('error', errorCallback, false);
- if (!_urlRegExp.test(url)) {
- cc.loader.cache[url] = img;
- }
- var queue = _queue[url];
- if (queue) {
- var callbacks = queue.callbacks;
- for (var i = 0; i < callbacks.length; ++i) {
- var cb = callbacks[i];
- if (cb) {
- cb(null, img);
- }
- }
- queue.img = null;
- delete _queue[url];
- }
- };
- var self = this;
- var errorCallback = function () {
- this.removeEventListener('error', errorCallback, false);
- if (img.crossOrigin && img.crossOrigin.toLowerCase() === "anonymous") {
- opt.isCrossOrigin = false;
- self.release(url);
- cc.loader.loadImg(url, opt, callback);
- } else {
- var queue = _queue[url];
- if (queue) {
- var callbacks = queue.callbacks;
- for (var i = 0; i < callbacks.length; ++i) {
- var cb = callbacks[i];
- if (cb) {
- cb("load image failed");
- }
- }
- queue.img = null;
- delete _queue[url];
- }
- }
- };
- _queue[url] = {
- img: img,
- callbacks: callback ? [callback] : []
- };
- img.addEventListener("load", loadCallback);
- img.addEventListener("error", errorCallback);
- img.src = url;
- return img;
- },
- _loadResIterator: function (item, index, cb) {
- var self = this, url = null;
- var type = item.type;
- if (type) {
- type = "." + type.toLowerCase();
- url = item.src ? item.src : item.name + type;
- } else {
- url = item;
- type = cc.path.extname(url);
- }
- var obj = self.getRes(url);
- if (obj)
- return cb(null, obj);
- var loader = null;
- if (type) {
- loader = _register[type.toLowerCase()];
- }
- if (!loader) {
- cc.error("loader for [" + type + "] not exists!");
- return cb();
- }
- var realUrl = url;
- if (!_urlRegExp.test(url))
- {
- var basePath = loader.getBasePath ? loader.getBasePath() : self.resPath;
- realUrl = self.getUrl(basePath, url);
- }
- if(cc.game.config["noCache"] && typeof realUrl === "string"){
- if(self._noCacheRex.test(realUrl))
- realUrl += "&_t=" + (new Date() - 0);
- else
- realUrl += "?_t=" + (new Date() - 0);
- }
- loader.load(realUrl, url, item, function (err, data) {
- if (err) {
- cc.log(err);
- self.cache[url] = null;
- delete self.cache[url];
- cb({status:520, errorMessage:err}, null);
- } else {
- self.cache[url] = data;
- cb(null, data);
- }
- });
- },
- _noCacheRex: /\?/,
- getUrl: function (basePath, url) {
- var self = this, path = cc.path;
- if (basePath !== undefined && url === undefined) {
- url = basePath;
- var type = path.extname(url);
- type = type ? type.toLowerCase() : "";
- var loader = _register[type];
- if (!loader)
- basePath = self.resPath;
- else
- basePath = loader.getBasePath ? loader.getBasePath() : self.resPath;
- }
- url = cc.path.join(basePath || "", url);
- if (url.match(/[\/(\\\\)]lang[\/(\\\\)]/i)) {
- if (_langPathCache[url])
- return _langPathCache[url];
- var extname = path.extname(url) || "";
- url = _langPathCache[url] = url.substring(0, url.length - extname.length) + "_" + cc.sys.language + extname;
- }
- return url;
- },
- load : function(resources, option, loadCallback){
- var self = this;
- var len = arguments.length;
- if(len === 0)
- throw new Error("arguments error!");
- if(len === 3){
- if(typeof option === "function"){
- if(typeof loadCallback === "function")
- option = {trigger : option, cb : loadCallback };
- else
- option = { cb : option, cbTarget : loadCallback};
- }
- }else if(len === 2){
- if(typeof option === "function")
- option = {cb : option};
- }else if(len === 1){
- option = {};
- }
- if(!(resources instanceof Array))
- resources = [resources];
- var asyncPool = new cc.AsyncPool(
- resources, 0,
- function (value, index, AsyncPoolCallback, aPool) {
- self._loadResIterator(value, index, function (err) {
- var arr = Array.prototype.slice.call(arguments, 1);
- if (option.trigger)
- option.trigger.call(option.triggerTarget, arr[0], aPool.size, aPool.finishedSize);
- AsyncPoolCallback(err, arr[0]);
- });
- },
- option.cb, option.cbTarget);
- asyncPool.flow();
- return asyncPool;
- },
- _handleAliases: function (fileNames, cb) {
- var self = this;
- var resList = [];
- for (var key in fileNames) {
- var value = fileNames[key];
- _aliases[key] = value;
- resList.push(value);
- }
- this.load(resList, cb);
- },
- loadAliases: function (url, callback) {
- var self = this, dict = self.getRes(url);
- if (!dict) {
- self.load(url, function (err, results) {
- self._handleAliases(results[0]["filenames"], callback);
- });
- } else
- self._handleAliases(dict["filenames"], callback);
- },
- register: function (extNames, loader) {
- if (!extNames || !loader) return;
- var self = this;
- if (typeof extNames === "string")
- return _register[extNames.trim().toLowerCase()] = loader;
- for (var i = 0, li = extNames.length; i < li; i++) {
- _register["." + extNames[i].trim().toLowerCase()] = loader;
- }
- },
- getRes: function (url) {
- return this.cache[url] || this.cache[_aliases[url]];
- },
- _getAliase: function (url) {
- return _aliases[url];
- },
- release: function (url) {
- var cache = this.cache;
- var queue = _queue[url];
- if (queue) {
- queue.img = null;
- delete _queue[url];
- }
- delete cache[url];
- delete cache[_aliases[url]];
- delete _aliases[url];
- },
- releaseAll: function () {
- var locCache = this.cache;
- for (var key in locCache)
- delete locCache[key];
- for (var key in _aliases)
- delete _aliases[key];
- }
- };
- })();
- cc.formatStr = function(){
- var args = arguments;
- var l = args.length;
- if(l < 1)
- return "";
- var str = args[0];
- var needToFormat = true;
- if(typeof str === "object"){
- needToFormat = false;
- }
- for(var i = 1; i < l; ++i){
- var arg = args[i];
- if(needToFormat){
- while(true){
- var result = null;
- if(typeof arg === "number"){
- result = str.match(/(%d)|(%s)/);
- if(result){
- str = str.replace(/(%d)|(%s)/, arg);
- break;
- }
- }
- result = str.match(/%s/);
- if(result)
- str = str.replace(/%s/, arg);
- else
- str += " " + arg;
- break;
- }
- }else
- str += " " + arg;
- }
- return str;
- };
- (function () {
- var _tmpCanvas1 = document.createElement("canvas"),
- _tmpCanvas2 = document.createElement("canvas");
- cc.create3DContext = function (canvas, opt_attribs) {
- var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
- var context = null;
- for (var ii = 0; ii < names.length; ++ii) {
- try {
- context = canvas.getContext(names[ii], opt_attribs);
- } catch (e) {
- }
- if (context) {
- break;
- }
- }
- return context;
- };
- var _initSys = function () {
- cc.sys = {};
- var sys = cc.sys;
- sys.LANGUAGE_ENGLISH = "en";
- sys.LANGUAGE_CHINESE = "zh";
- sys.LANGUAGE_FRENCH = "fr";
- sys.LANGUAGE_ITALIAN = "it";
- sys.LANGUAGE_GERMAN = "de";
- sys.LANGUAGE_SPANISH = "es";
- sys.LANGUAGE_DUTCH = "du";
- sys.LANGUAGE_RUSSIAN = "ru";
- sys.LANGUAGE_KOREAN = "ko";
- sys.LANGUAGE_JAPANESE = "ja";
- sys.LANGUAGE_HUNGARIAN = "hu";
- sys.LANGUAGE_PORTUGUESE = "pt";
- sys.LANGUAGE_ARABIC = "ar";
- sys.LANGUAGE_NORWEGIAN = "no";
- sys.LANGUAGE_POLISH = "pl";
- sys.LANGUAGE_UNKNOWN = "unkonwn";
- sys.OS_IOS = "iOS";
- sys.OS_ANDROID = "Android";
- sys.OS_WINDOWS = "Windows";
- sys.OS_MARMALADE = "Marmalade";
- sys.OS_LINUX = "Linux";
- sys.OS_BADA = "Bada";
- sys.OS_BLACKBERRY = "Blackberry";
- sys.OS_OSX = "OS X";
- sys.OS_WP8 = "WP8";
- sys.OS_WINRT = "WINRT";
- sys.OS_UNKNOWN = "Unknown";
- sys.UNKNOWN = -1;
- sys.WIN32 = 0;
- sys.LINUX = 1;
- sys.MACOS = 2;
- sys.ANDROID = 3;
- sys.IPHONE = 4;
- sys.IPAD = 5;
- sys.BLACKBERRY = 6;
- sys.NACL = 7;
- sys.EMSCRIPTEN = 8;
- sys.TIZEN = 9;
- sys.WINRT = 10;
- sys.WP8 = 11;
- sys.MOBILE_BROWSER = 100;
- sys.DESKTOP_BROWSER = 101;
- sys.BROWSER_TYPE_WECHAT = "wechat";
- sys.BROWSER_TYPE_ANDROID = "androidbrowser";
- sys.BROWSER_TYPE_IE = "ie";
- sys.BROWSER_TYPE_QQ = "qqbrowser";
- sys.BROWSER_TYPE_MOBILE_QQ = "mqqbrowser";
- sys.BROWSER_TYPE_UC = "ucbrowser";
- sys.BROWSER_TYPE_360 = "360browser";
- sys.BROWSER_TYPE_BAIDU_APP = "baiduboxapp";
- sys.BROWSER_TYPE_BAIDU = "baidubrowser";
- sys.BROWSER_TYPE_MAXTHON = "maxthon";
- sys.BROWSER_TYPE_OPERA = "opera";
- sys.BROWSER_TYPE_OUPENG = "oupeng";
- sys.BROWSER_TYPE_MIUI = "miuibrowser";
- sys.BROWSER_TYPE_FIREFOX = "firefox";
- sys.BROWSER_TYPE_SAFARI = "safari";
- sys.BROWSER_TYPE_CHROME = "chrome";
- sys.BROWSER_TYPE_LIEBAO = "liebao";
- sys.BROWSER_TYPE_QZONE = "qzone";
- sys.BROWSER_TYPE_SOUGOU = "sogou";
- sys.BROWSER_TYPE_UNKNOWN = "unknown";
- sys.isNative = false;
- var win = window, nav = win.navigator, doc = document, docEle = doc.documentElement;
- var ua = nav.userAgent.toLowerCase();
- sys.isMobile = ua.indexOf('mobile') !== -1 || ua.indexOf('android') !== -1;
- sys.platform = sys.isMobile ? sys.MOBILE_BROWSER : sys.DESKTOP_BROWSER;
- var currLanguage = nav.language;
- currLanguage = currLanguage ? currLanguage : nav.browserLanguage;
- currLanguage = currLanguage ? currLanguage.split("-")[0] : sys.LANGUAGE_ENGLISH;
- sys.language = currLanguage;
- var isAndroid = false, iOS = false, osVersion = '', osMainVersion = 0;
- var uaResult = /android (\d+(?:\.\d+)+)/i.exec(ua) || /android (\d+(?:\.\d+)+)/i.exec(nav.platform);
- if (uaResult) {
- isAndroid = true;
- osVersion = uaResult[1] || '';
- osMainVersion = parseInt(osVersion) || 0;
- }
- uaResult = /(iPad|iPhone|iPod).*OS ((\d+_?){2,3})/i.exec(ua);
- if (uaResult) {
- iOS = true;
- osVersion = uaResult[2] || '';
- osMainVersion = parseInt(osVersion) || 0;
- }
- var osName = sys.OS_UNKNOWN;
- if (nav.appVersion.indexOf("Win") !== -1) osName = sys.OS_WINDOWS;
- else if (iOS) osName = sys.OS_IOS;
- else if (nav.appVersion.indexOf("Mac") !== -1) osName = sys.OS_OSX;
- else if (nav.appVersion.indexOf("X11") !== -1 && nav.appVersion.indexOf("Linux") === -1) osName = sys.OS_UNIX;
- else if (isAndroid) osName = sys.OS_ANDROID;
- else if (nav.appVersion.indexOf("Linux") !== -1) osName = sys.OS_LINUX;
- sys.os = osName;
- sys.osVersion = osVersion;
- sys.osMainVersion = osMainVersion;
- sys.browserType = sys.BROWSER_TYPE_UNKNOWN;
- (function(){
- var typeReg1 = /mqqbrowser|sogou|qzone|liebao|micromessenger|ucbrowser|360 aphone|360browser|baiduboxapp|baidubrowser|maxthon|mxbrowser|trident|miuibrowser/i;
- var typeReg2 = /qqbrowser|chrome|safari|firefox|opr|oupeng|opera/i;
- var browserTypes = typeReg1.exec(ua);
- if(!browserTypes) browserTypes = typeReg2.exec(ua);
- var browserType = browserTypes ? browserTypes[0] : sys.BROWSER_TYPE_UNKNOWN;
- if (browserType === 'micromessenger')
- browserType = sys.BROWSER_TYPE_WECHAT;
- else if (browserType === "safari" && (ua.match(/android.*applewebkit/)))
- browserType = sys.BROWSER_TYPE_ANDROID;
- else if (browserType === "trident")
- browserType = sys.BROWSER_TYPE_IE;
- else if (browserType === "360 aphone")
- browserType = sys.BROWSER_TYPE_360;
- else if (browserType === "mxbrowser")
- browserType = sys.BROWSER_TYPE_MAXTHON;
- else if (browserType === "opr")
- browserType = sys.BROWSER_TYPE_OPERA;
- sys.browserType = browserType;
- })();
- sys.browserVersion = "";
- (function(){
- var versionReg1 = /(micromessenger|qq|mx|maxthon|baidu|sogou)(mobile)?(browser)?\/?([\d.]+)/i;
- var versionReg2 = /(msie |rv:|firefox|chrome|ucbrowser|oupeng|opera|opr|safari|miui)(mobile)?(browser)?\/?([\d.]+)/i;
- var tmp = ua.match(versionReg1);
- if(!tmp) tmp = ua.match(versionReg2);
- sys.browserVersion = tmp ? tmp[4] : "";
- })();
- var w = window.innerWidth || document.documentElement.clientWidth;
- var h = window.innerHeight || document.documentElement.clientHeight;
- var ratio = window.devicePixelRatio || 1;
- sys.windowPixelResolution = {
- width: ratio * w,
- height: ratio * h
- };
- sys._checkWebGLRenderMode = function () {
- if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL)
- throw new Error("This feature supports WebGL render mode only.");
- };
- sys._supportCanvasNewBlendModes = (function(){
- var canvas = _tmpCanvas1;
- canvas.width = 1;
- canvas.height = 1;
- var context = canvas.getContext('2d');
- context.fillStyle = '#000';
- context.fillRect(0,0,1,1);
- context.globalCompositeOperation = 'multiply';
- var canvas2 = _tmpCanvas2;
- canvas2.width = 1;
- canvas2.height = 1;
- var context2 = canvas2.getContext('2d');
- context2.fillStyle = '#fff';
- context2.fillRect(0,0,1,1);
- context.drawImage(canvas2, 0, 0, 1, 1);
- return context.getImageData(0,0,1,1).data[0] === 0;
- })();
- if (cc.sys.isMobile) {
- var fontStyle = document.createElement("style");
- fontStyle.type = "text/css";
- document.body.appendChild(fontStyle);
- fontStyle.textContent = "body,canvas,div{ -moz-user-select: none;-webkit-user-select: none;-ms-user-select: none;-khtml-user-select: none;"
- + "-webkit-tap-highlight-color:rgba(0,0,0,0);}";
- }
- try {
- var localStorage = sys.localStorage = win.localStorage;
- localStorage.setItem("storage", "");
- localStorage.removeItem("storage");
- localStorage = null;
- } catch (e) {
- var warn = function () {
- cc.warn("Warning: localStorage isn't enabled. Please confirm browser cookie or privacy option");
- };
- sys.localStorage = {
- getItem : warn,
- setItem : warn,
- removeItem : warn,
- clear : warn
- };
- }
- var _supportCanvas = !!_tmpCanvas1.getContext("2d");
- var _supportWebGL = false;
- if (win.WebGLRenderingContext) {
- var tmpCanvas = document.createElement("CANVAS");
- try{
- var context = cc.create3DContext(tmpCanvas, {'stencil': true});
- if(context) {
- _supportWebGL = true;
- }
- if (_supportWebGL && sys.os === sys.OS_ANDROID) {
- var browserVer = parseFloat(sys.browserVersion);
- switch (sys.browserType) {
- case sys.BROWSER_TYPE_MOBILE_QQ:
- case sys.BROWSER_TYPE_BAIDU:
- case sys.BROWSER_TYPE_BAIDU_APP:
- if (browserVer >= 6.2) {
- _supportWebGL = true;
- }
- else {
- _supportWebGL = false;
- }
- break;
- case sys.BROWSER_TYPE_CHROME:
- if(browserVer >= 30.0) {
- _supportWebGL = true;
- } else {
- _supportWebGL = false;
- }
- break;
- case sys.BROWSER_TYPE_ANDROID:
- if (sys.osMainVersion && sys.osMainVersion >= 5) {
- _supportWebGL = true;
- }
- break;
- case sys.BROWSER_TYPE_UNKNOWN:
- case sys.BROWSER_TYPE_360:
- case sys.BROWSER_TYPE_MIUI:
- case sys.BROWSER_TYPE_UC:
- _supportWebGL = false;
- }
- }
- }
- catch (e) {}
- tmpCanvas = null;
- }
- var capabilities = sys.capabilities = {
- "canvas": _supportCanvas,
- "opengl": _supportWebGL
- };
- if (docEle['ontouchstart'] !== undefined || doc['ontouchstart'] !== undefined || nav.msPointerEnabled)
- capabilities["touches"] = true;
- if (docEle['onmouseup'] !== undefined)
- capabilities["mouse"] = true;
- if (docEle['onkeyup'] !== undefined)
- capabilities["keyboard"] = true;
- if (win.DeviceMotionEvent || win.DeviceOrientationEvent)
- capabilities["accelerometer"] = true;
- sys.garbageCollect = function () {
- };
- sys.dumpRoot = function () {
- };
- sys.restartVM = function () {
- };
- sys.cleanScript = function (jsfile) {
- };
- sys.isObjectValid = function (obj) {
- if (obj) return true;
- else return false;
- };
- sys.dump = function () {
- var self = this;
- var str = "";
- str += "isMobile : " + self.isMobile + "\r\n";
- str += "language : " + self.language + "\r\n";
- str += "browserType : " + self.browserType + "\r\n";
- str += "browserVersion : " + self.browserVersion + "\r\n";
- str += "capabilities : " + JSON.stringify(self.capabilities) + "\r\n";
- str += "os : " + self.os + "\r\n";
- str += "osVersion : " + self.osVersion + "\r\n";
- str += "platform : " + self.platform + "\r\n";
- str += "Using " + (cc._renderType === cc.game.RENDER_TYPE_WEBGL ? "WEBGL" : "CANVAS") + " renderer." + "\r\n";
- cc.log(str);
- };
- sys.openURL = function(url){
- window.open(url);
- };
- };
- _initSys();
- _tmpCanvas1 = null;
- _tmpCanvas2 = null;
- cc.log = cc.warn = cc.error = cc.assert = function () {
- };
- var _config = null,
- _jsAddedCache = {},
- _engineInitCalled = false,
- _engineLoadedCallback = null;
- cc._engineLoaded = false;
- function _determineRenderType(config) {
- var CONFIG_KEY = cc.game.CONFIG_KEY,
- userRenderMode = parseInt(config[CONFIG_KEY.renderMode]) || 0;
- if (isNaN(userRenderMode) || userRenderMode > 2 || userRenderMode < 0)
- config[CONFIG_KEY.renderMode] = 0;
- cc._renderType = cc.game.RENDER_TYPE_CANVAS;
- cc._supportRender = false;
- if (userRenderMode === 0) {
- if (cc.sys.capabilities["opengl"]) {
- cc._renderType = cc.game.RENDER_TYPE_WEBGL;
- cc._supportRender = true;
- }
- else if (cc.sys.capabilities["canvas"]) {
- cc._renderType = cc.game.RENDER_TYPE_CANVAS;
- cc._supportRender = true;
- }
- }
- else if (userRenderMode === 1 && cc.sys.capabilities["canvas"]) {
- cc._renderType = cc.game.RENDER_TYPE_CANVAS;
- cc._supportRender = true;
- }
- else if (userRenderMode === 2 && cc.sys.capabilities["opengl"]) {
- cc._renderType = cc.game.RENDER_TYPE_WEBGL;
- cc._supportRender = true;
- }
- }
- function _getJsListOfModule(moduleMap, moduleName, dir) {
- if (_jsAddedCache[moduleName]) return null;
- dir = dir || "";
- var jsList = [];
- var tempList = moduleMap[moduleName];
- if (!tempList) throw new Error("can not find module [" + moduleName + "]");
- var ccPath = cc.path;
- for (var i = 0, li = tempList.length; i < li; i++) {
- var item = tempList[i];
- if (_jsAddedCache[item]) continue;
- var extname = ccPath.extname(item);
- if (!extname) {
- var arr = _getJsListOfModule(moduleMap, item, dir);
- if (arr) jsList = jsList.concat(arr);
- } else if (extname.toLowerCase() === ".js") jsList.push(ccPath.join(dir, item));
- _jsAddedCache[item] = 1;
- }
- return jsList;
- }
- function _afterEngineLoaded(config) {
- if (cc._initDebugSetting)
- cc._initDebugSetting(config[cc.game.CONFIG_KEY.debugMode]);
- cc._engineLoaded = true;
- cc.log(cc.ENGINE_VERSION);
- if (_engineLoadedCallback) _engineLoadedCallback();
- }
- function _load(config) {
- var self = this;
- var CONFIG_KEY = cc.game.CONFIG_KEY, engineDir = config[CONFIG_KEY.engineDir], loader = cc.loader;
- if (cc.Class) {
- _afterEngineLoaded(config);
- } else {
- var ccModulesPath = cc.path.join(engineDir, "moduleConfig.json");
- loader.loadJson(ccModulesPath, function (err, modulesJson) {
- if (err) throw new Error(err);
- var modules = config["modules"] || [];
- var moduleMap = modulesJson["module"];
- var jsList = [];
- if (cc.sys.capabilities["opengl"] && modules.indexOf("base4webgl") < 0) modules.splice(0, 0, "base4webgl");
- else if (modules.indexOf("core") < 0) modules.splice(0, 0, "core");
- for (var i = 0, li = modules.length; i < li; i++) {
- var arr = _getJsListOfModule(moduleMap, modules[i], engineDir);
- if (arr) jsList = jsList.concat(arr);
- }
- cc.loader.loadJsWithImg(jsList, function (err) {
- if (err) throw err;
- _afterEngineLoaded(config);
- });
- });
- }
- }
- function _windowLoaded() {
- this.removeEventListener('load', _windowLoaded, false);
- _load(cc.game.config);
- }
- cc.initEngine = function (config, cb) {
- if (_engineInitCalled) {
- var previousCallback = _engineLoadedCallback;
- _engineLoadedCallback = function () {
- previousCallback && previousCallback();
- cb && cb();
- }
- return;
- }
- _engineLoadedCallback = cb;
- if (!cc.game.config && config) {
- cc.game.config = config;
- }
- else if (!cc.game.config) {
- cc.game._loadConfig();
- }
- config = cc.game.config;
- _determineRenderType(config);
- document.body ? _load(config) : cc._addEventListener(window, 'load', _windowLoaded, false);
- _engineInitCalled = true;
- };
- })();
- cc.game = {
- DEBUG_MODE_NONE: 0,
- DEBUG_MODE_INFO: 1,
- DEBUG_MODE_WARN: 2,
- DEBUG_MODE_ERROR: 3,
- DEBUG_MODE_INFO_FOR_WEB_PAGE: 4,
- DEBUG_MODE_WARN_FOR_WEB_PAGE: 5,
- DEBUG_MODE_ERROR_FOR_WEB_PAGE: 6,
- EVENT_HIDE: "game_on_hide",
- EVENT_SHOW: "game_on_show",
- EVENT_RESIZE: "game_on_resize",
- EVENT_RENDERER_INITED: "renderer_inited",
- RENDER_TYPE_CANVAS: 0,
- RENDER_TYPE_WEBGL: 1,
- RENDER_TYPE_OPENGL: 2,
- _eventHide: null,
- _eventShow: null,
- CONFIG_KEY: {
- width: "width",
- height: "height",
- engineDir: "engineDir",
- modules: "modules",
- debugMode: "debugMode",
- showFPS: "showFPS",
- frameRate: "frameRate",
- id: "id",
- renderMode: "renderMode",
- jsList: "jsList"
- },
- _paused: true,//whether the game is paused
- _prepareCalled: false,//whether the prepare function has been called
- _prepared: false,//whether the engine has prepared
- _rendererInitialized: false,
- _renderContext: null,
- _intervalId: null,//interval target of main
- _lastTime: null,
- _frameTime: null,
- frame: null,
- container: null,
- canvas: null,
- config: null,
- onStart: null,
- onStop: null,
- setFrameRate: function (frameRate) {
- var self = this, config = self.config, CONFIG_KEY = self.CONFIG_KEY;
- config[CONFIG_KEY.frameRate] = frameRate;
- if (self._intervalId)
- window.cancelAnimationFrame(self._intervalId);
- self._paused = true;
- self._setAnimFrame();
- self._runMainLoop();
- },
- step: function () {
- cc.director.mainLoop();
- },
- pause: function () {
- if (this._paused) return;
- this._paused = true;
- if (cc.audioEngine) {
- cc.audioEngine.stopAllEffects();
- cc.audioEngine.pauseMusic();
- }
- if (this._intervalId)
- window.cancelAnimationFrame(this._intervalId);
- this._intervalId = 0;
- },
- resume: function () {
- if (!this._paused) return;
- this._paused = false;
- if (cc.audioEngine) {
- cc.audioEngine.resumeMusic();
- }
- this._runMainLoop();
- },
- isPaused: function () {
- return this._paused;
- },
- restart: function () {
- cc.director.popToSceneStackLevel(0);
- cc.audioEngine && cc.audioEngine.end();
- cc.game.onStart();
- },
- end: function () {
- close();
- },
- prepare: function (cb) {
- var self = this,
- config = self.config,
- CONFIG_KEY = self.CONFIG_KEY;
- this._loadConfig();
- if (this._prepared) {
- if (cb) cb();
- return;
- }
- if (this._prepareCalled) {
- return;
- }
- if (cc._engineLoaded) {
- this._prepareCalled = true;
- this._initRenderer(config[CONFIG_KEY.width], config[CONFIG_KEY.height]);
- cc.view = cc.EGLView._getInstance();
- cc.director = cc.Director._getInstance();
- if (cc.director.setOpenGLView)
- cc.director.setOpenGLView(cc.view);
- cc.winSize = cc.director.getWinSize();
- this._initEvents();
- this._setAnimFrame();
- this._runMainLoop();
- var jsList = config[CONFIG_KEY.jsList];
- if (jsList) {
- cc.loader.loadJsWithImg(jsList, function (err) {
- if (err) throw new Error(err);
- self._prepared = true;
- if (cb) cb();
- });
- }
- else {
- if (cb) cb();
- }
- return;
- }
- cc.initEngine(this.config, function () {
- self.prepare(cb);
- });
- },
- run: function (config, onStart) {
- if (typeof config === 'function') {
- cc.game.onStart = config;
- }
- else {
- if (config) {
- if (typeof config === 'string') {
- if (!cc.game.config) this._loadConfig();
- cc.game.config[cc.game.CONFIG_KEY.id] = config;
- } else {
- cc.game.config = config;
- }
- }
- if (typeof onStart === 'function') {
- cc.game.onStart = onStart;
- }
- }
- this.prepare(cc.game.onStart && cc.game.onStart.bind(cc.game));
- },
- _setAnimFrame: function () {
- this._lastTime = new Date();
- this._frameTime = 1000 / cc.game.config[cc.game.CONFIG_KEY.frameRate];
- if((cc.sys.os === cc.sys.OS_IOS && cc.sys.browserType === cc.sys.BROWSER_TYPE_WECHAT) || cc.game.config[cc.game.CONFIG_KEY.frameRate] !== 60) {
- window.requestAnimFrame = this._stTime;
- window.cancelAnimationFrame = this._ctTime;
- }
- else {
- window.requestAnimFrame = window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- window.msRequestAnimationFrame ||
- this._stTime;
- window.cancelAnimationFrame = window.cancelAnimationFrame ||
- window.cancelRequestAnimationFrame ||
- window.msCancelRequestAnimationFrame ||
- window.mozCancelRequestAnimationFrame ||
- window.oCancelRequestAnimationFrame ||
- window.webkitCancelRequestAnimationFrame ||
- window.msCancelAnimationFrame ||
- window.mozCancelAnimationFrame ||
- window.webkitCancelAnimationFrame ||
- window.oCancelAnimationFrame ||
- this._ctTime;
- }
- },
- _stTime: function(callback){
- var currTime = new Date().getTime();
- var timeToCall = Math.max(0, cc.game._frameTime - (currTime - cc.game._lastTime));
- var id = window.setTimeout(function() { callback(); },
- timeToCall);
- cc.game._lastTime = currTime + timeToCall;
- return id;
- },
- _ctTime: function(id){
- window.clearTimeout(id);
- },
- _runMainLoop: function () {
- var self = this, callback, config = self.config, CONFIG_KEY = self.CONFIG_KEY,
- director = cc.director;
- director.setDisplayStats(config[CONFIG_KEY.showFPS]);
- callback = function () {
- if (!self._paused) {
- director.mainLoop();
- if(self._intervalId)
- window.cancelAnimationFrame(self._intervalId);
- self._intervalId = window.requestAnimFrame(callback);
- }
- };
- window.requestAnimFrame(callback);
- self._paused = false;
- },
- _loadConfig: function () {
- if (this.config) {
- this._initConfig(this.config);
- return;
- }
- if (document["ccConfig"]) {
- this._initConfig(document["ccConfig"]);
- }
- else {
- var data = {};
- try {
- var cocos_script = document.getElementsByTagName('script');
- for(var i = 0; i < cocos_script.length; i++){
- var _t = cocos_script[i].getAttribute('cocos');
- if(_t === '' || _t) {
- break;
- }
- }
- var _src, txt, _resPath;
- if(i < cocos_script.length){
- _src = cocos_script[i].src;
- if(_src){
- _resPath = /(.*)\//.exec(_src)[0];
- cc.loader.resPath = _resPath;
- _src = cc.path.join(_resPath, 'project.json');
- }
- txt = cc.loader._loadTxtSync(_src);
- }
- if(!txt){
- txt = cc.loader._loadTxtSync("project.json");
- }
- data = JSON.parse(txt);
- } catch (e) {
- cc.log("Failed to read or parse project.json");
- }
- this._initConfig(data);
- }
- },
- _initConfig: function (config) {
- var CONFIG_KEY = this.CONFIG_KEY,
- modules = config[CONFIG_KEY.modules];
- config[CONFIG_KEY.showFPS] = typeof config[CONFIG_KEY.showFPS] === 'undefined' ? true : config[CONFIG_KEY.showFPS];
- config[CONFIG_KEY.engineDir] = config[CONFIG_KEY.engineDir] || "frameworks/cocos2d-html5";
- if (config[CONFIG_KEY.debugMode] == null)
- config[CONFIG_KEY.debugMode] = 0;
- config[CONFIG_KEY.frameRate] = config[CONFIG_KEY.frameRate] || 60;
- if (config[CONFIG_KEY.renderMode] == null)
- config[CONFIG_KEY.renderMode] = 0;
- if (config[CONFIG_KEY.registerSystemEvent] == null)
- config[CONFIG_KEY.registerSystemEvent] = true;
- if (modules && modules.indexOf("core") < 0) modules.splice(0, 0, "core");
- modules && (config[CONFIG_KEY.modules] = modules);
- this.config = config;
- },
- _initRenderer: function (width, height) {
- if (this._rendererInitialized) return;
- if (!cc._supportRender) {
- throw new Error("The renderer doesn't support the renderMode " + this.config[this.CONFIG_KEY.renderMode]);
- }
- var el = this.config[cc.game.CONFIG_KEY.id],
- win = window,
- element = cc.$(el) || cc.$('#' + el),
- localCanvas, localContainer, localConStyle;
- if (element.tagName === "CANVAS") {
- width = width || element.width;
- height = height || element.height;
- this.canvas = cc._canvas = localCanvas = element;
- this.container = cc.container = localContainer = document.createElement("DIV");
- if (localCanvas.parentNode)
- localCanvas.parentNode.insertBefore(localContainer, localCanvas);
- } else {
- if (element.tagName !== "DIV") {
- cc.log("Warning: target element is not a DIV or CANVAS");
- }
- width = width || element.clientWidth;
- height = height || element.clientHeight;
- this.canvas = cc._canvas = localCanvas = document.createElement("CANVAS");
- this.container = cc.container = localContainer = document.createElement("DIV");
- element.appendChild(localContainer);
- }
- localContainer.setAttribute('id', 'Cocos2dGameContainer');
- localContainer.appendChild(localCanvas);
- this.frame = (localContainer.parentNode === document.body) ? document.documentElement : localContainer.parentNode;
- localCanvas.addClass("gameCanvas");
- localCanvas.setAttribute("width", width || 480);
- localCanvas.setAttribute("height", height || 320);
- localCanvas.setAttribute("tabindex", 99);
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
- this._renderContext = cc._renderContext = cc.webglContext
- = cc.create3DContext(localCanvas, {
- 'stencil': true,
- 'antialias': !cc.sys.isMobile,
- 'alpha': false
- });
- }
- if (this._renderContext) {
- cc.renderer = cc.rendererWebGL;
- win.gl = this._renderContext;
- cc.renderer.init();
- cc.shaderCache._init();
- cc._drawingUtil = new cc.DrawingPrimitiveWebGL(this._renderContext);
- cc.textureCache._initializingRenderer();
- cc.glExt = {};
- cc.glExt.instanced_arrays = win.gl.getExtension("ANGLE_instanced_arrays");
- cc.glExt.element_uint = win.gl.getExtension("OES_element_index_uint");
- } else {
- cc._renderType = cc.game.RENDER_TYPE_CANVAS;
- cc.renderer = cc.rendererCanvas;
- this._renderContext = cc._renderContext = new cc.CanvasContextWrapper(localCanvas.getContext("2d"));
- cc._drawingUtil = cc.DrawingPrimitiveCanvas ? new cc.DrawingPrimitiveCanvas(this._renderContext) : null;
- }
- cc._gameDiv = localContainer;
- cc.game.canvas.oncontextmenu = function () {
- if (!cc._isContextMenuEnable) return false;
- };
- this.dispatchEvent(this.EVENT_RENDERER_INITED, true);
- this._rendererInitialized = true;
- },
- _initEvents: function () {
- var win = window, self = this, hidden, visibilityChange, _undef = "undefined";
- this._eventHide = this._eventHide || new cc.EventCustom(this.EVENT_HIDE);
- this._eventHide.setUserData(this);
- this._eventShow = this._eventShow || new cc.EventCustom(this.EVENT_SHOW);
- this._eventShow.setUserData(this);
- if (this.config[this.CONFIG_KEY.registerSystemEvent])
- cc.inputManager.registerSystemEvent(this.canvas);
- if (!cc.isUndefined(document.hidden)) {
- hidden = "hidden";
- visibilityChange = "visibilitychange";
- } else if (!cc.isUndefined(document.mozHidden)) {
- hidden = "mozHidden";
- visibilityChange = "mozvisibilitychange";
- } else if (!cc.isUndefined(document.msHidden)) {
- hidden = "msHidden";
- visibilityChange = "msvisibilitychange";
- } else if (!cc.isUndefined(document.webkitHidden)) {
- hidden = "webkitHidden";
- visibilityChange = "webkitvisibilitychange";
- }
- var onHidden = function () {
- if (cc.eventManager && cc.game._eventHide)
- cc.eventManager.dispatchEvent(cc.game._eventHide);
- };
- var onShow = function () {
- if (cc.eventManager && cc.game._eventShow)
- cc.eventManager.dispatchEvent(cc.game._eventShow);
- };
- if (hidden) {
- document.addEventListener(visibilityChange, function () {
- if (document[hidden]) onHidden();
- else onShow();
- }, false);
- } else {
- win.addEventListener("blur", onHidden, false);
- win.addEventListener("focus", onShow, false);
- }
- if(navigator.userAgent.indexOf("MicroMessenger") > -1){
- win.onfocus = function(){ onShow() };
- }
- if ("onpageshow" in window && "onpagehide" in window) {
- win.addEventListener("pagehide", onHidden, false);
- win.addEventListener("pageshow", onShow, false);
- }
- cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () {
- cc.game.pause();
- });
- cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () {
- cc.game.resume();
- });
- }
- };
- Function.prototype.bind = Function.prototype.bind || function (oThis) {
- if (!cc.isFunction(this)) {
- throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
- }
- var aArgs = Array.prototype.slice.call(arguments, 1),
- fToBind = this,
- fNOP = function () {},
- fBound = function () {
- return fToBind.apply(this instanceof fNOP && oThis
- ? this
- : oThis,
- aArgs.concat(Array.prototype.slice.call(arguments)));
- };
- fNOP.prototype = this.prototype;
- fBound.prototype = new fNOP();
- return fBound;
- };
- cc._urlRegExp = new RegExp(
- "^" +
- "(?:(?:https?|ftp)://)" +
- "(?:\\S+(?::\\S*)?@)?" +
- "(?:" +
- "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
- "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
- "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
- "|" +
- "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
- "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
- "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
- "|" +
- "(?:localhost)" +
- ")" +
- "(?::\\d{2,5})?" +
- "(?:/\\S*)?" +
- "$", "i"
- );
- cc.SimplePool = function () {
- this._pool = [];
- };
- cc.SimplePool.prototype = {
- constructor: cc.SimplePool,
- size: function () {
- return this._pool.length;
- },
- put: function (obj) {
- if (obj && this._pool.indexOf(obj) === -1) {
- this._pool.unshift(obj);
- }
- },
- get: function () {
- var last = this._pool.length-1;
- if (last < 0) {
- return null;
- }
- else {
- var obj = this._pool[last];
- this._pool.length = last;
- return obj;
- }
- },
- find: function (finder, end) {
- var found, i, obj, pool = this._pool, last = pool.length-1;
- for (i = pool.length; i >= 0; --i) {
- obj = pool[i];
- found = finder(i, obj);
- if (found) {
- pool[i] = pool[last];
- pool.length = last;
- return obj;
- }
- }
- if (end) {
- var index = end();
- if (index >= 0) {
- pool[index] = pool[last];
- pool.length = last;
- return obj;
- }
- }
- return null;
- }
- };
- cc.EventHelper = function(){};
- cc.EventHelper.prototype = {
- constructor: cc.EventHelper,
- apply: function ( object ) {
- object.addEventListener = cc.EventHelper.prototype.addEventListener;
- object.hasEventListener = cc.EventHelper.prototype.hasEventListener;
- object.removeEventListener = cc.EventHelper.prototype.removeEventListener;
- object.dispatchEvent = cc.EventHelper.prototype.dispatchEvent;
- },
- addEventListener: function ( type, listener, target ) {
- if(type === "load" && this._textureLoaded){
- setTimeout(function(){
- listener.call(target);
- }, 0);
- return;
- }
- if ( this._listeners === undefined )
- this._listeners = {};
- var listeners = this._listeners;
- if ( listeners[ type ] === undefined )
- listeners[ type ] = [];
- if ( !this.hasEventListener(type, listener, target))
- listeners[ type ].push( {callback:listener, eventTarget: target} );
- },
- hasEventListener: function ( type, listener, target ) {
- if ( this._listeners === undefined )
- return false;
- var listeners = this._listeners;
- if ( listeners[ type ] !== undefined ) {
- for(var i = 0, len = listeners.length; i < len ; i++){
- var selListener = listeners[i];
- if(selListener.callback === listener && selListener.eventTarget === target)
- return true;
- }
- }
- return false;
- },
- removeEventListener: function( type, listener, target){
- if ( this._listeners === undefined )
- return;
- var listeners = this._listeners;
- var listenerArray = listeners[ type ];
- if ( listenerArray !== undefined ) {
- for(var i = 0; i < listenerArray.length ; ){
- var selListener = listenerArray[i];
- if(selListener.eventTarget === target && selListener.callback === listener)
- listenerArray.splice( i, 1 );
- else
- i++
- }
- }
- },
- removeEventTarget: function( type, listener, target){
- if ( this._listeners === undefined )
- return;
- var listeners = this._listeners;
- var listenerArray = listeners[ type ];
- if ( listenerArray !== undefined ) {
- for(var i = 0; i < listenerArray.length ; ){
- var selListener = listenerArray[i];
- if(selListener.eventTarget === target)
- listenerArray.splice( i, 1 );
- else
- i++
- }
- }
- },
- dispatchEvent: function ( event, clearAfterDispatch ) {
- if ( this._listeners === undefined )
- return;
- if(clearAfterDispatch == null)
- clearAfterDispatch = true;
- var listeners = this._listeners;
- var listenerArray = listeners[ event];
- if ( listenerArray !== undefined ) {
- var array = [];
- var length = listenerArray.length;
- for ( var i = 0; i < length; i ++ ) {
- array[ i ] = listenerArray[ i ];
- }
- for ( i = 0; i < length; i ++ ) {
- array[ i ].callback.call( array[i].eventTarget, this );
- }
- if(clearAfterDispatch)
- listenerArray.length = 0;
- }
- }
- };
- cc.EventHelper.prototype.apply(cc.game);
- var cc = cc || {};
- cc._loadingImage = "data:image/gif;base64,R0lGODlhEAAQALMNAD8/P7+/vyoqKlVVVX9/fxUVFUBAQGBgYMDAwC8vL5CQkP///wAAAP///wAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFAAANACwAAAAAEAAQAAAEO5DJSau9OOvNex0IMnDIsiCkiW6g6BmKYlBFkhSUEgQKlQCARG6nEBwOgl+QApMdCIRD7YZ5RjlGpCUCACH5BAUAAA0ALAAAAgAOAA4AAAQ6kLGB0JA4M7QW0hrngRllkYyhKAYqKUGguAws0ypLS8JxCLQDgXAIDg+FRKIA6v0SAECCBpXSkstMBAAh+QQFAAANACwAAAAACgAQAAAEOJDJORAac6K1kDSKYmydpASBUl0mqmRfaGTCcQgwcxDEke+9XO2WkxQSiUIuAQAkls0n7JgsWq8RACH5BAUAAA0ALAAAAAAOAA4AAAQ6kMlplDIzTxWC0oxwHALnDQgySAdBHNWFLAvCukc215JIZihVIZEogDIJACBxnCSXTcmwGK1ar1hrBAAh+QQFAAANACwAAAAAEAAKAAAEN5DJKc4RM+tDyNFTkSQF5xmKYmQJACTVpQSBwrpJNteZSGYoFWjIGCAQA2IGsVgglBOmEyoxIiMAIfkEBQAADQAsAgAAAA4ADgAABDmQSVZSKjPPBEDSGucJxyGA1XUQxAFma/tOpDlnhqIYN6MEAUXvF+zldrMBAjHoIRYLhBMqvSmZkggAIfkEBQAADQAsBgAAAAoAEAAABDeQyUmrnSWlYhMASfeFVbZdjHAcgnUQxOHCcqWylKEohqUEAYVkgEAMfkEJYrFA6HhKJsJCNFoiACH5BAUAAA0ALAIAAgAOAA4AAAQ3kMlJq704611SKloCAEk4lln3DQgyUMJxCBKyLAh1EMRR3wiDQmHY9SQslyIQUMRmlmVTIyRaIgA7";
- cc._fpsImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAAgCAYAAAD9qabkAAAKQ2lDQ1BJQ0MgcHJvZmlsZQAAeNqdU3dYk/cWPt/3ZQ9WQtjwsZdsgQAiI6wIyBBZohCSAGGEEBJAxYWIClYUFRGcSFXEgtUKSJ2I4qAouGdBiohai1VcOO4f3Ke1fXrv7e371/u855zn/M55zw+AERImkeaiagA5UoU8Otgfj09IxMm9gAIVSOAEIBDmy8JnBcUAAPADeXh+dLA//AGvbwACAHDVLiQSx+H/g7pQJlcAIJEA4CIS5wsBkFIAyC5UyBQAyBgAsFOzZAoAlAAAbHl8QiIAqg0A7PRJPgUA2KmT3BcA2KIcqQgAjQEAmShHJAJAuwBgVYFSLALAwgCgrEAiLgTArgGAWbYyRwKAvQUAdo5YkA9AYACAmUIszAAgOAIAQx4TzQMgTAOgMNK/4KlfcIW4SAEAwMuVzZdL0jMUuJXQGnfy8ODiIeLCbLFCYRcpEGYJ5CKcl5sjE0jnA0zODAAAGvnRwf44P5Dn5uTh5mbnbO/0xaL+a/BvIj4h8d/+vIwCBAAQTs/v2l/l5dYDcMcBsHW/a6lbANpWAGjf+V0z2wmgWgrQevmLeTj8QB6eoVDIPB0cCgsL7SViob0w44s+/zPhb+CLfvb8QB7+23rwAHGaQJmtwKOD/XFhbnauUo7nywRCMW735yP+x4V//Y4p0eI0sVwsFYrxWIm4UCJNx3m5UpFEIcmV4hLpfzLxH5b9CZN3DQCshk/ATrYHtctswH7uAQKLDljSdgBAfvMtjBoLkQAQZzQyefcAAJO/+Y9AKwEAzZek4wAAvOgYXKiUF0zGCAAARKCBKrBBBwzBFKzADpzBHbzAFwJhBkRADCTAPBBCBuSAHAqhGJZBGVTAOtgEtbADGqARmuEQtMExOA3n4BJcgetwFwZgGJ7CGLyGCQRByAgTYSE6iBFijtgizggXmY4EImFINJKApCDpiBRRIsXIcqQCqUJqkV1II/ItchQ5jVxA+pDbyCAyivyKvEcxlIGyUQPUAnVAuagfGorGoHPRdDQPXYCWomvRGrQePYC2oqfRS+h1dAB9io5jgNExDmaM2WFcjIdFYIlYGibHFmPlWDVWjzVjHVg3dhUbwJ5h7wgkAouAE+wIXoQQwmyCkJBHWExYQ6gl7CO0EroIVwmDhDHCJyKTqE+0JXoS+cR4YjqxkFhGrCbuIR4hniVeJw4TX5NIJA7JkuROCiElkDJJC0lrSNtILaRTpD7SEGmcTCbrkG3J3uQIsoCsIJeRt5APkE+S+8nD5LcUOsWI4kwJoiRSpJQSSjVlP+UEpZ8yQpmgqlHNqZ7UCKqIOp9aSW2gdlAvU4epEzR1miXNmxZDy6Qto9XQmmlnafdoL+l0ugndgx5Fl9CX0mvoB+nn6YP0dwwNhg2Dx0hiKBlrGXsZpxi3GS+ZTKYF05eZyFQw1zIbmWeYD5hvVVgq9ip8FZHKEpU6lVaVfpXnqlRVc1U/1XmqC1SrVQ+rXlZ9pkZVs1DjqQnUFqvVqR1Vu6k2rs5Sd1KPUM9RX6O+X/2C+mMNsoaFRqCGSKNUY7fGGY0hFsYyZfFYQtZyVgPrLGuYTWJbsvnsTHYF+xt2L3tMU0NzqmasZpFmneZxzQEOxrHg8DnZnErOIc4NznstAy0/LbHWaq1mrX6tN9p62r7aYu1y7Rbt69rvdXCdQJ0snfU6bTr3dQm6NrpRuoW623XP6j7TY+t56Qn1yvUO6d3RR/Vt9KP1F+rv1u/RHzcwNAg2kBlsMThj8MyQY+hrmGm40fCE4agRy2i6kcRoo9FJoye4Ju6HZ+M1eBc+ZqxvHGKsNN5l3Gs8YWJpMtukxKTF5L4pzZRrmma60bTTdMzMyCzcrNisyeyOOdWca55hvtm82/yNhaVFnMVKizaLx5balnzLBZZNlvesmFY+VnlW9VbXrEnWXOss623WV2xQG1ebDJs6m8u2qK2brcR2m23fFOIUjynSKfVTbtox7PzsCuya7AbtOfZh9iX2bfbPHcwcEh3WO3Q7fHJ0dcx2bHC866ThNMOpxKnD6VdnG2ehc53zNRemS5DLEpd2lxdTbaeKp26fesuV5RruutK10/Wjm7ub3K3ZbdTdzD3Ffav7TS6bG8ldwz3vQfTw91jicczjnaebp8LzkOcvXnZeWV77vR5Ps5wmntYwbcjbxFvgvct7YDo+PWX6zukDPsY+Ap96n4e+pr4i3z2+I37Wfpl+B/ye+zv6y/2P+L/hefIW8U4FYAHBAeUBvYEagbMDawMfBJkEpQc1BY0FuwYvDD4VQgwJDVkfcpNvwBfyG/ljM9xnLJrRFcoInRVaG/owzCZMHtYRjobPCN8Qfm+m+UzpzLYIiOBHbIi4H2kZmRf5fRQpKjKqLupRtFN0cXT3LNas5Fn7Z72O8Y+pjLk722q2cnZnrGpsUmxj7Ju4gLiquIF4h/hF8ZcSdBMkCe2J5MTYxD2J43MC52yaM5zkmlSWdGOu5dyiuRfm6c7Lnnc8WTVZkHw4hZgSl7I/5YMgQlAvGE/lp25NHRPyhJuFT0W+oo2iUbG3uEo8kuadVpX2ON07fUP6aIZPRnXGMwlPUit5kRmSuSPzTVZE1t6sz9lx2S05lJyUnKNSDWmWtCvXMLcot09mKyuTDeR55m3KG5OHyvfkI/lz89sVbIVM0aO0Uq5QDhZML6greFsYW3i4SL1IWtQz32b+6vkjC4IWfL2QsFC4sLPYuHhZ8eAiv0W7FiOLUxd3LjFdUrpkeGnw0n3LaMuylv1Q4lhSVfJqedzyjlKD0qWlQyuCVzSVqZTJy26u9Fq5YxVhlWRV72qX1VtWfyoXlV+scKyorviwRrjm4ldOX9V89Xlt2treSrfK7etI66Trbqz3Wb+vSr1qQdXQhvANrRvxjeUbX21K3nShemr1js20zcrNAzVhNe1bzLas2/KhNqP2ep1/XctW/a2rt77ZJtrWv913e/MOgx0VO97vlOy8tSt4V2u9RX31btLugt2PGmIbur/mft24R3dPxZ6Pe6V7B/ZF7+tqdG9s3K+/v7IJbVI2jR5IOnDlm4Bv2pvtmne1cFoqDsJB5cEn36Z8e+NQ6KHOw9zDzd+Zf7f1COtIeSvSOr91rC2jbaA9ob3v6IyjnR1eHUe+t/9+7zHjY3XHNY9XnqCdKD3x+eSCk+OnZKeenU4/PdSZ3Hn3TPyZa11RXb1nQ8+ePxd07ky3X/fJ897nj13wvHD0Ivdi2yW3S609rj1HfnD94UivW2/rZffL7Vc8rnT0Tes70e/Tf/pqwNVz1/jXLl2feb3vxuwbt24m3Ry4Jbr1+Hb27Rd3Cu5M3F16j3iv/L7a/eoH+g/qf7T+sWXAbeD4YMBgz8NZD+8OCYee/pT/04fh0kfMR9UjRiONj50fHxsNGr3yZM6T4aeypxPPyn5W/3nrc6vn3/3i+0vPWPzY8Av5i8+/rnmp83Lvq6mvOscjxx+8znk98ab8rc7bfe+477rfx70fmSj8QP5Q89H6Y8en0E/3Pud8/vwv94Tz+4A5JREAAAAGYktHRAD/AP8A/6C9p5MAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfcAgcQLxxUBNp/AAAQZ0lEQVR42u2be3QVVZbGv1N17829eRLyIKAEOiISEtPhJTJAYuyBDmhWjAEx4iAGBhxA4wABbVAMWUAeykMCM+HRTcBRWkNH2l5moS0LCCrQTkYeQWBQSCAIgYRXEpKbW/XNH5zS4noR7faPEeu31l0h4dSpvc+t/Z199jkFWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhY/H9D/MR9qfKnLj/00U71aqfJn9+HCkCR/Wk36ddsgyJ/1wF4fkDfqqm9/gPsUeTnVr6a2xlQfnxdI7zs0W7irzD17Ytb2WT7EeNv/r4ox1O3Quf2QP2pgt9utwfout4FQE8AVBSlnaRmfvAURQkg2RlAbwB9AThlW5L0GaiKojhJhgOIBqDa7XaPrusdPtr5kQwF0BVAAoBIABRCKDd5aFUhRDAAw57eAOwAhKIoupft3zoqhB1AqLwuHIBut9uFt02qqvqRDJR2dAEQJj/BAOjn56dqmma+xiaECAEQAWAggLsB6A6HQ2iaZggBhBAqgEAAnQB0kzaEmT4hAITT6VQ8Ho/HJAKKECJQtr8LwD1y/A1/vcdfEUIEyfZ9AcQbYvZ942Px88L2UwlJR0dH0EMPPbRj5syZPUeNGrXR7Xb/641xIwJ1XY9NSUlZm52dfW+XLl1w8uRJzJ8//+OGhoYJqqqe1TSt1Wsm9NN1PSIqKmr12rVrR5WUlHy1bdu2AQCumWc3IYRD1/UwVVXnFRQUTIuNjUVzczN2797dWFJSkq8oymZd15sAGAEnFEUJ1nX9nzIzM1dnZmZGh4SE4OTJk5g5c+Zf29vbp9pstrMej6fVOyhIhgAYU1hY+B+hoaGoqKg4XVlZea+XTULTNFdCQsLGiRMnPuR2u3UhBOV9eeDAAWXTpk095DUe6WsoyRE5OTlr0tLSAux2O/bs2cO5c+e+pijKUpIXSHaQVAGkvPLKK++6XK4OksJLCFlXV2cvKSlJBFAjhU+x2WwhHo9nUHp6+urMzMy7wsLCUF9fjxdffPHjxsbGiTab7WuPx9NiEutOuq4PyMjI+M+srKyYqKgoHD58GDNmzNjq8XhyVFU9b/q+LH7hBAEYu3PnTlZVVRFAGgCX6f/tAHoOHDjwa0p27txp/JO9e/f+QM7cipw9nfL3kQBKt2zZQpJ87rnn6mQmoHilw2EACs+cOUOSrK+vZ1NTE0nyo48+IoBpxswoBcMJ4Ndjx471kOTFixe5d+9ekqTH42H//v13A4jyzpAURfEH0H/OnDnthu1z5sw558MmFUCPWbNmnaMP3nrrLZoyDmP8Hl68eDFJ8siRI9/Yc+zYMQKYKdtAztrTrl27xptRXV1NAKMAOAyBBBA/Y8aMdpLs6Ojgxx9//E37+++//29yvFXppwvAwMcee8xjtDHsuXLlCqOjo//ia3wsfpkoALqFhoZuIckJEyackimm3dQmEMDUmpoakmRISMhhAHOHDx/eQJIbN24kgKEyMAHAFRMTs2XXrl1saWkhSZ0kp0+ffhrAr3wEW/S8efOukORLL72kA1gKYMPWrVtJkk899dRJAHeYrgsEsIQkjx8/TgDvAPjd448/3kaSb7zxBmUa7vC6z53BwcFbSHL9+vU6Sc6aNes8gF5ewWAH0PfVV18lSQL4DMBGIcQ6AKtcLleBFC2jXtFt8ODBe0iyoqKCAJYByC8qKmJDQwOzsrK+MAmqo1OnTveHhoa+GRkZ+XZkZOSWiIiIvzgcjk9mzpypkWRmZuZpmbYbGV4AgPnNzc1sa2sjgN0A5iQmJtaSZHl5OQHcb/K3s81mW0uSTU1NBFAFYFbfvn1Pk+Tbb79NAA8IIVzW42/hByA+Pz/fLR/2ZXIda05NI/z9/TeR5J49ewhgqlxTrtI0jY2NjQQw3zTLuWJiYjaUlJToS5Ys6fjkk080kwDEeAmADcA9GzZsIElGRUW9CyAWwLApU6Y0kOSKFSsog9QICGdERMTGsrIyZmVlEcC9AB4IDw/fTpLbtm0jgN94CUAnAJmVlZVcs2aNZ/LkyRdJcvbs2b4EwAkgZfPmzTxw4AABFAN4BkC6vFeUSewcAO5duXIlSTIhIaEawGMAxgKYAmAGgCS73e5vrKVk/yGythANYEhCQsIhkly+fDkBpKqqGmL6DgIALDKN/3yZpVWQZGVlJQE8aPI3KiMjo5okV61aRQAjAPQBMPfIkSN0u90EUCBtsPiFEwpgbn19PdetW2fM5N4zQ9ekpKQqkty0aRMBpMjiWM6JEydIkoqirJUFJ6iq6pAPVy8A6cZMehMBUACEuVyuFwG8HBwcPEIWx367ZMkSjSQXLVrUJouTRorrkAHdA8BdQogsAOsKCwtJkmPGjDkvMw2bDDo/ADEjRoz4XylyFbm5uY0mAbjLyyZ/AOOrq6tZVlbWsWDBgo69e/eyoqKCgwcPPg4gSQaoIRbp27dvN7KF+tLSUr28vJwFBQXtMpvpYRIM7+wrAkDeqVOnePbsWQIoNKfzpiXPg8uXLydJJicnNwF4f+nSpW6STEtLq5fjYwhk1wkTJtSQ5Ouvv04AqTKj+N2xY8dIkgEBAW/Ie1v8wncRegwZMmQvSfbr12+3Ua33WqPfOWbMmP0kWVpaSgCDZAqcfejQIWNZsEGKgvnh9gfQb9myZd8nAEJVVZtMkUNk8CcNHTq0liR1XWdYWNhmH1mJIme80OnTp18x1rp5eXkEsNJms92Fb7e/IgEsvHz5Mp999tkmAI/l5uZeMC0B7vEqqAYAyL106RJJsra2lpWVld+sucePH38ZQG+5NncBeOrgwYMkqbe3t/Po0aOsra011wAWyl0H7x0JJ4DE+fPnu0kyPT29DsDdUrBuyNKEEAkAdpw/f/6GeoEM8GUmfwEgPCIiopwkGxsbabPZPgOw6L777vvm4p49e26VGYjFLxUhhD+ApLKyMp44ccIoVnXybgbgzkcfffRzklyzZg0BDJYCMMmoCwQFBXkLgLGWvvcWAgBToSsKwNPTp09vMR7UuLi4rwH0lgU8c/Db5ezbeeTIkRWzZ8++aMxu+fn5BPCADBwHgP4LFy701NXVEUAJgAnPP/98kyxMNgHo53A4zH77BQQETMvPz7+Um5vbBuAlAFMSExPPmdbVL0qh8Acw8fDhw5SCchVAEYAVb775JknyhRdeaJYztHfxMwLAaqNwCGC2FArv8x0hAHKNLGPKlCme5OTk/Zs3bzb7O0wKiiG8KXl5ed8IxenTp0mSR48e1UmyW7duWywBuD2xyQcgFECgoih+8H1gyJgZV5Lkyy+/3CbTRIePtl2HDBmyw1QBHyGDdXZdXR1JUghRKkXBjOMHCoBdpr0L3nvvPZLkF198wejo6O0A4lVVDTb74HQ6AwD8Wq7Jh8rgGgDgQ13XjVR8qaxJuADMbmlpYXl5uV5UVNRWUFDgfv/993Vj/ZydnU1c37eHXML4S3viAcQqitJD2l104cIFY8lTKsXSBWBMVVWVcd9yed2A1NTUQ6Zl00CvLMMOoHdubm6zFIlWOf5+PsY/Kj09vdrU11QAwwGsv3jxIk21m2DZr10I0RXAuAcffPBgaWkpV69eTYfDcdiwUxY0w6xw+flX8L1xApjevXv3lREREaW6rofB93aPDUDQpEmTMgHgtddeqwBwEd/utZvpqK6uPgEAcXFxkA94NwB9unfvjrNnz4LklwDcf08iIqv66Zs2bXrl4YcfxooVKxAbG7uqrq5uAYA2TdOEqqpGYIi2tjbl6aeffu/YsWPv5uTk7JaC1wHg4Pnz542MwoVvTx+21dbWYvjw4WLixIl+2dnZ9lGjRgmSTE1NRUpKCkwFTGiaxtTU1OXTpk3707Bhw/6g67pDipnT4biuj7qut+Lbk3Vf1tTUXI9qu91Pjq1QFEUBgJaWFgBo8yGOQ8eNGxcAAOvXr/8QwBUfYygAKL169eoCABcuXACAWtn2hOGv0+kMNO1KiPDw8F4A4rZv3/7R1KlTR0+bNu1ht9u9r1+/fqitrQXJgwDarRC6/QjPzs4+QJIffPCB9/aQmSAA43ft2mW0e1QGoi8CAPyLsZccExNTC2BlRkbGRdOyYJCP2csBIN6UAZzCd7cBbQCijYp/dXU1ExMTz6SmptaMHj36f9LS0vYlJCRsl6mxIWSdu3fv/g5J7t+/nwC2AShMTk6+SJKff/45AWRLYbD7+fndAeDf5BJnLoCCyZMnt5JkdnZ2C4B/F0KEm1Pu+Pj4rST55ZdfEsBWAK+mpaVdMo3raDn7KwDuSEpK+m+S3LBhAwG8DuCtHTt2UBbpjgC408vvcFVV15HkuXPnjMp+p5uMf0RcXNyHJNnQ0EBVVfcCWBQXF3fG+Jv0yxABPwB5LS0tRmFxN4BlTzzxxGWSXLx4sS5F3GGFy+1Hp5SUlJq6ujoWFxdTpsZ2H+0iIyMj/0iSWVlZX5mr5jfJFroPGzasxlhTnjp1iiTZ3NxMl8tlrCd9pfa9SkpKSJI5OTmnZOageLUZZqxvfVFWVkZcPwdgNwnSCKPqb17jkmR8fPzfZMDZ5CRsFBmNI7h95s2b1yhT7/MAYmStwCx4vy0uLqa3v5qmEcCfvSr1QQAeXb16NY3Cm3HQ55133iGAp+SxZTNhKSkpfzUddkrFjYevzAQCeGjp0qXfsYckY2NjTwD4leGDLCL2HTdunNtoY+zWSHFcIHdsFCtcfuZ1vO9Eqs3m7/F47sb1k2qX/f3997W2tl7BjWfpBYDOzzzzzIVJkyZh0KBBCwEsB3AJvl9AETabLcDj8dwRFRW1ctasWb8JCgpSzp07d62wsPC/Wltb8xRFadR1/ZqPXYbgAQMGbI2Pjw/+6quv9ldVVT0r01ezuPRJSUn5Y9euXXVd11WzDaqq6kePHm3+7LPPRgO4KlNuxWazhXo8nuTk5OSXMjIyEl0uFxoaGtqKior+dPXq1VdUVT0jj7r68ieoT58+vx8yZMjdx48fP1JVVTVF9m20VW02WyfZf97YsWPjXS4X6urqWvPy8jYCWCyEuEDS8FdVFKWzruv//OSTTy5OTk7uqWkaPv3007qysrJ8RVH+LI8ym8/rB3Tu3HnRI488knLo0KG2ffv2ZQI4C98vP6mqqoZqmpaclpa2cOTIkX39/f3R0NDQUVxc/G5TU9PLqqrWa5rWLH1QVFUN0TStX1JSUvH48eP7BwYG4uDBg1cKCgpeBbBe2u+2Qug2EwD5N5sMPuNtMe8XP4TT6Qxoa2sbIGeXvUKIK7d4IISiKC5d1wPljOfA9bPwzYqiXNV13dd6Uqiq6qdpml2mpe02m63d4/G4vcTF5fF47LJf71nJA6BZVVW3pmntuPHlmAD5wk6Q9NnbHp9vHaqq6tA0zU/64PZhk1FfCZB9G/23ALiqKEqzD39tpvbGUqoFwFUhRLP3yzpCCDtJpxyXDulfG27+pqRR3DXsUWVd4Yq0x/taVQjhIhksC8L+ABpM9ljBf5sKwI8pIBr75L5E4vvu+UNeG/a+hv+AL7yFH8qPtOfHjtOP6V/Bja8D6z/B2Nys/1u9Xv33tLf4GfF/LC4GCJwByWIAAAAASUVORK5CYII=";
- cc._loaderImage = "data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAAlAAD/4QMpaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjAtYzA2MCA2MS4xMzQ3NzcsIDIwMTAvMDIvMTItMTc6MzI6MDAgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjM4MDBEMDY2QTU1MjExRTFBQTAzQjEzMUNFNzMxRkQwIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjM4MDBEMDY1QTU1MjExRTFBQTAzQjEzMUNFNzMxRkQwIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkU2RTk0OEM4OERCNDExRTE5NEUyRkE3M0M3QkE1NTlEIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkU2RTk0OEM5OERCNDExRTE5NEUyRkE3M0M3QkE1NTlEIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+/+4ADkFkb2JlAGTAAAAAAf/bAIQADQkJCQoJDQoKDRMMCwwTFhENDREWGhUVFhUVGhkUFhUVFhQZGR0fIB8dGScnKionJzk4ODg5QEBAQEBAQEBAQAEODAwOEA4RDw8RFA4RDhQVERISERUfFRUXFRUfKB0ZGRkZHSgjJiAgICYjLCwoKCwsNzc1NzdAQEBAQEBAQEBA/8AAEQgAyACgAwEiAAIRAQMRAf/EALAAAAEFAQEAAAAAAAAAAAAAAAQAAgMFBgcBAQEAAwEBAAAAAAAAAAAAAAAAAQMEAgUQAAIBAgIEBwoLBgQGAwAAAAECAwAEEQUhMRIGQVFxsTITFGGBwdEiQlKSMzWRoeFicqKyI1NzFYJjJDQWB9KjVCbxwkNkJWXik3QRAAIBAgMFBQcDBQEAAAAAAAABAhEDIRIEMUFRcTJhwVIUBZGhsSJyEzOB0ULhYpIjUxX/2gAMAwEAAhEDEQA/AMJSpUqAVKlXuFAeUq9wpUB5XuFe4V6ooDzZHDox0CnGMinzwl7Z8NajaHeoO3vmTBZBtp9YUIqTEV5ROxHKnWRnaU8VRMhFBUjpV7hSoSeUq9pUB5Sr2lhQHlKvcK8oBV7hSFSRrtaKAZs07YNPM1pG2xJIAw1jSeandry/8X4m8VCKkWwaWwam7Xl/4v1W8VLtmX/i/VbxUoKkWwakSM407tmX/i/VbxUmzGwjQsjdY41IARie/U0IbZO0kNtCXnOCkEBeFu4KI3Bs7DNb27ya+jDx3kJeEnpJJEcQVbWDsk17u5urd591ucZkWhym2Vnd9RkCDEpFxDRpbw0bunu5mlp2De2FMLYXOD2wB2xbOeraUcYGJ72mlSUiqzzdzMd3Z3mixltA2yzcK/NlHM1DQyRXce1HocdNOEfJXZ88y9ZojOqhiBszIRiHQ8Y4cK5TvHuzLljHNMqxNoDjLFraHHnjPxcNCGVbxEUzYNTx5jZSxhpW6qTzlwJ+DCvO2Zf+L9VvFSgqyHYNLYNTdssPxfibxUu15f8Ai/VPiqCakOwa82DU/a8v/F+JvFTDdWPBL8R8VKCvYRYV5UzoMAy6QdIIqI0B4KJtxiRQwou16QoGUkntH5Tz0RbZbmF2hktraSVBo2lUkY8tDye0flPPXTslVUyiyVRsjqUOA4yMT8dW2ram2m6UVTNq9S7EIyUVJydMTn/6DnP+im9Wl+g5z/opvVrpteEhQWY4AaSTwAVf5WPiZh/9S5/zj7zltzlmYWkfWXNvJDGTgGcYDHirR7i7mSbwXParsFMrgb7w6jKw/wCmnc9I14kF3vpvCljbMyWMOJL4aEiB8qU/ObUK7HYWVrl1pFZWiCOCBQqKOLjPGTrNZZqKbUXVHq2nNwTuJRk1VpbgXN8s7Rk5ym0UQQzhIG2NAjhxHWbI+gCBVjBBFbwxwQqEiiUJGg1BVGAFe7dV28WYLYZFmF2Th1UD7JGjymGyn1iK5OyzIBGB1HgrLZhamzumQAGJwSqnSCh1q3GOCodxt4cxurdcpzuN4cyhiWaF5Bg09udUmnWw1H/jV9nFuJ7Quo+8h8peThFA+047vduyMtk7fYqTl07YFdfUufMPzT5p71UdtlmYXaGS2t3mQHAsgxANdadYJopLe4QS2867EsZ4QfCNYrCFbjdDPmgkYyWFxgVf04ifJf6ScNdRUW1XBb6FU5TjF5EpSSrGu/s5lN+g5z/opvVpfoOc/wCim9WtdHnatvObJXDW7xLGhB8nrPaY9/HCr+tEdPCVaSeDoYLnqF63lzW4/PFSW3ecxbI84VSzWUwUaSdg0DXXK5nvAipnd6qgKvWnQO7pri9ZUEmm3Vl2j1kr8pRlFRyquBNZjGxQ/S56Y1S2fu9OVueon11Szahoou06QoQUXadIVCD2FJJ7R+U89dMydv8Axdn+TH9muZye0flPPXQstlK5Tbka1gUjlC1q0vVLkeb6r+O3Tx9xcY1nt8c0NrZCyiOE1108NYjGv1joo7Js1jzKyScYLIvkzL6LDwHXVJksH9Sb49dKNq0tj1jA6uriOCL+02FWX7iVtZX1/AzaHTyeoauKn2MX9W79zebiZCuR5MjSrhfXuEtwTrUeZH+yNfdrRNcxI6IzhXlJEak6WIGJ2Rw4ChWnChndtlVBLMdQA0k1gbXNMzzDfDLs6mjaPKppJbWwJ1bOwwxw43OnHh71YT3DpfWUJmFlb5jHHDdeXBHIsrRea5TSqvxqG04cNN62vetoCS4tre5mgnkGE9q+3DKOkuI2WX6LDQRRHWDh1UCtwj7QRg2wdl8Djgw1qe7XvW0BQ3kfZ7mSLgU+T9E6RVbnuVrnWVSWqj+Lt8ZbRuHEdKPkYVcZ2MJY5fSGyeVar45+rkWQHAqccalPE5km1htWK5nK4Wnt5FuUBUwOMG4nGkA/BXUrW4S6torlOjMgcd/xVn7rLo7zKs0uEjCNeSvdwoBhgsZxX1l2j36k3Lu+uyprdj5Vs5A+i/lD48a0aaVJOPi7jB6lbzWozpjB48pf1NDXNN4vfl7+Z4BXS65pvF78vfzPAK71XTHmZ/S/yT+jvJ7L3fHytz1E+upbL+Qj5W56jfXWRnsIYKLtekKEFGWvSFQgyjk9o/Keet3YthlMP/5x9msJJ7R+U89biyb/AMXEv7gD6tadL1T+kwepRrC39ZkLDMbiwMvUHRPG0bjlGg8ore/23sxBldxfMPLupNhT8yL/AORNZbdzJ484scytxgLqJY5LZj6Q2sV5G1Vud1mjjyG0ij0NEGSZToKyhjtqw4waztuiXA3qKTbSxltfGhbZlE95ZtZqxVbgiOZhrER9ph3Svk9+pJILZ4Y4DGBFCUMKjRsGPobPFhUfW0NJmljE2xJcIrcI2vFUEln1lRXd6lrazXT9GCNpD+yNqoI7mOVduNw6nzlOIoPOUa6yye1XXcbMR5GdQ3xY0BSbj31/FcTQZirJ+q431q7anbHCTZ72Bw7lbPrKBMcBWNNgbMBBh+bsjBdni0VJ1lARZs6yWiupxCuMDy6KpS2IwOo6DTr3Mre3e5tZZVUM4ZBjqOOJoWO4jkXajcOOMHGgDISvWIrdAkKR80+TzVl908bPPL3LzxOuHdifxVfiTAg92qI/w+/8gGgSyN/mR7XPVlp0lF/3L3mbVKtu5Hjbk/8AHE2Fc03i9+Xv5ngFdKNc13i9+Xv5ngFaNV0x5nn+l/kn9HeEWXu+PlbnqJ9dS2Xu9OVueon11kZ7CGCjLXpCgxRlr0hUIPYUcntH5Tz1s8vb+Bt1/dqPirGSe0flPPWusG/g4Py15q06XqlyMWvVYQ+ruI9xJOqzO9hOto/sP8tbGOFIrmWeM7IuMDMnAXXQJOUjQeOsJk0nY96ip0CYunrjaHx1t+srPJUbXBm2LrFPikwTOb+T+VhbZxGMrDXp83x1QSy2tucJpUjPETp+Cn5/ftaRvKvtp3Kx48HG3erHMzOxZiWZtLMdJNQSbbL71Vk6yynViOkqnEEfOWtPbXi3EQkGg6mXiNckjeSJxJGxR10qw0GtxuxmvbImD4CZMFlA4fRfv0BqesqqzTMZNMEDbIHtHH2QeCiZJSqMQdOGiue53mz3czQwsRbIcNHnkec3c4qAMuriz68gTIToxwOOnlp0MjxMJYW741Gs3RVldtbygE/dMcHX/moDaxTiWNZB53B3arb8/wC+4SOF4sf/AKxU9kcBsfOGHfoUHtG/RbzY5Die5HHhXdvavqiZ9Q8Jdlq4/gbKua7xe/L38zwCuhpf2Uk/Zo50kmwJKIdogDjw1VzzeL35e/meAVp1LTgqY4nn+mRauzqmqwrjzCLL3fHytz1E+upLL+Qj5W56jfXWRnroYKLtekKEFF2vSFQg9hSSe0flPPWosm/hIfoLzVl5PaPynnrRWb/w0X0F5q06XqlyM2sVYx5gmbFre/t71NY2T+0h8VbSO5SWNJUOKSAMp7jDGspmMPaLRlXS6eWve1/FRO7WYdbZm1Y/eW/R7qHxHRXGojlm3ulid6aVbaW+OALvgCLq2Hm9WxHKWqjhj6xsK1e8dm15l4niG1LZkswGsxtrPeOmsvayBJA1VItlWjptLuTdPMo7LtjRDq9naK4+WF9IrUW7BaHOljGqVHB7w2hzVoZt87d8vaNYSLl02CcRsDEbJbj71Uu7UBkvJ7/D7q2QoDxySaAO8MTXdxRVMpRp5XZOWdF/ms7R5XdyKfKWJsO/5PhrG5XlNxmEywW6bTnTxAAcJNbGSMXkM1pjgbiNo1PziPJ+Os7u7m/6ReM00ZOgxSpqYYHT3wRXMKN4ll9zUG4bQfNshu8sZVuEA2hirA4qe/VOwwrVbzbww5mI44UKRRYkbWG0S3JWctbd7u5WFfOOLHiUdJqmaipfLsIsObhWe001lMkMVvJNjhghIALMcBxCs7fxXQmkupx1bXDswGPlaTidVaEyKNXkoo4eBV+Sq7L7Vs9zcBgeyQ4GQ/MB1crmoim2orezqcowTuSeEY48jQ7oZX2PLzdyLhNd6RjrEY6I7+uspvH78vfzPAK6UAAAFGAGgAcArmu8Xvy9/M8ArTfio24RW5nnaG67uou3H/KPuqT2X8hHytz1G+upLL3enK3PUb66ys9RDBRdr0hQgou06QqEGUkntH5Tz1e238vF9BeaqKT2j8p56vbb+Xi+gvNWjTdUuRn1XTHmTh8KrJTJlt8t1CPIY44cGnpJVjTJYkmjaN9Ib4u7V923njTethRauZJV3PaW1rfLIiXEDYg6R4VYc9CXW7thfOZbKdbGZtLW8uPVY/u3GrkNUkM9zlcxUjbhfWOA90cRq4gv4LhdqN+VToNYWmnRm9NNVWNTyHc6VWBv8wt4YeHqm6xyPmroq1Z7WGFLSxTq7WLSuPSdjrkfumq5yHXDUeA92oO2SKpVumNAaoJLMXH3myp0rpJ4uKhc3tbDM5BMri1zAj79j7KTiY8TcdBpcsith0286o+sPCagEX9Pzg4zXUCp6QYse8oouCG3tk6m1BYv05W6T+IdyolxbHDAAa2OgDlNCz3ryN2WxBd5PJMg1t81eId2ukqnLlTBbfcuY+9uJLiRcvtPvHdsHK+cfRHcHDWsyawjyy0WBcDI3lTP6TeIcFV+S5OmXx9bJg1048o8Cj0V8Jq2DVu09nL80up7OxHi+oal3P8AXB/IsZS8T/YOV65zvCcc7vfzPAK3ivWCz445zeH954BXOr6I8yfSfyz+jvCLP3fHytz1G+upLP3fHytz1E+usbPaQ0UXadIUIKLtekKhB7Ckk9o/Keer22/l4/oLzVRSe0flPPV7b/y8X0F5q0abqlyM+q6Y8yQsBTDMor1o8aiaE1pbluMqS3sbLLHIhSRQyngqukhaJ9uBjo+H5aOa3ao2t34qouRlLajTalGP8v0IY8ylXQ+PKPFU/bYXOLPge6CKia0LaxTOxHu1Q7cuBd9yPEJ7TbjXKO8CajbMIF6CNIeNvJHjqIWJ7tSpYkalqVblwIdyG+RGXur0hXYJFxal+Dhq5y3slkv3Y2pD0pTr+QUClpJRUdo9XW4OLrTHtM16cZLLWkeC7y4jvlNEpcRtw1Ux27Ci448NZrTFy3nn3IQWxlgGrDZ3pza7/M8ArZo+ArF5171uvp+CqdV0R5l/psUrs2vB3hdl7vTlbnqJ9dS2Xu+PlbnqJ9dY2eshooq16QoQUXa9IVCD2FLJ7RuU89WNtmUSQqkgYMgw0accKrpPaPynnrZWG4Vi+VWmY5tnMWXG+XrIYnA0rhj0mdcTgdNdwnKDqjmduM1SRR/qlr8/4KX6pa8T/BVzDuLZXudRZblmbxXcPUNPc3KqCIwrbOzgrHEnHjoyD+3eSXkht7DeKG4umDGOJVUklfouThXfmbnZ7Cvy1vt9pmv1W1+d8FL9VteJvgq5yrcOGfLmzHN80iyyETPbptAEFo2ZG8pmUa1OFNn3Ky6W/sbDKM5hv5bx2WTZA+7RF2y52WOPJTzE+z2Dy1vt9pT/AKpacTerS/U7Tib1a04/t7kDXPY03jhN0W6sQ7K7W3q2dnrMccaDy/8At80kuZfqWYxWNtlcvUPPhiGYhWDeUy7IwYU8xPs9g8tb7faUn6pacTerTxm9oOBvVq3v9z927aynuId44LiWKNnjhAXF2UYhRg516qpsryjLr21665zFLSTaK9U2GOA87SwqY37knRU+BzOzags0s1Oyr+BKM6sxwP6tSDPLMen6vy0rvdm3Sxlu7K/S7WDDrFUDUTxgnTU826eXW7KlxmqQuwDBXUKcD+1Xee/wXuKX5XDGWLapSVcOyhEM/seJ/V+WnjeGx4pPV+Wkm6kKZlFay3Jlt7iFpYZY8ASVK6DjtDDA0f8A0Tl340/1f8Ndx8xJVWXB0KbktFFpNzdVXAC/qOwA0CQni2flrO3Vwbm5lnI2TKxbDirX/wBE5d+NcfV/wVR7xZPa5U9utvI8nWhmbbw0YEAYYAVxfhfy5rlKR4Fulu6X7mW1mzT8S4Yis/5CPlbnqJ9dSWfu9OVueon11mZvQ2i7XpChKKtekKhBlNJ7R+U89bDfGTb3a3ZX0Lcj6kdY+T2j8p560288m1kWQr6MJ+ylSAr+2cnV5renjs3H1loX+3j9XvbbtxLN9lqW4UnV5jdnjtXHxihtyZNjeSBu5J9k1BJe7xy7W5CJ/wCzuD/mTVTf2+fq97LJuLrPsNRueS7W6aJ/38x+vLVXuY+xvHaNxbf2GoCezf8A36j/APsSf8w1sLnqczTefJluYoLm5uo5F61sBshItP1cNFYe1f8A3ir/APfE/wCZUe9bB94r5jwuPsrQFhmG4l/Z2M17HdW90tuu3IkTHaCjWdIw0VVZdks9/C06yJFEp2dp+E1bbqybGTZ8vpQD7L1XRv8A7blT96Oda7tpNuuNE37Cq9KSisjyuUoxrStKllHbLlWTXsMs8chuSuwEPDqwoLe5y+YRE/gLzmqRekvKKtd4327yM/ulHxmrHJStySWVRyrjxKI2XC/CTlnlPPKTpTdFbP0L1bgrf5Lp0G3dPhQHwV0S1lzBsns3sESR8Crh9WAJGjSOKuU3E+zdZQ3oJh8IArdZXFDmOTpHa3i2+YrI2KtKy4ricBsBuHHgFXSo440+Wa2qqxjvM9uMoy+WvzWpLCWWWE28HxL6e43ojgkeSCBY1Ri5BGIUDT51cl3vm276BBqSEH4WbxV0tlkyXJcxTMb+OW6uY9mGHrCzDQwwAbTp2uKuTZ9N1uYsfRRR8WPhrm419mSSjRyiqxVK7y23B/ftuTm2oSdJyzNVw3BFn7vTlbnqF9dS2fu9OVueon11lZuQ2iLdsGFD05H2dNQGV0ntG5Tz1dWm9N1b2kVq8EVwsI2UaQaQOKhmitZGLOmk68DhSFvY+gfWNSAg7z3Qvo7yKCKIohiaNR5LKxx8qpxvjcqS0VpbxvwOAcRQPZ7D0G9Y0uz2HoH1jUCpLY7zXlpbm3eKO5QuzjrBqZji3x17PvNcyT288VvDBJbMWUovS2hslW7mFQ9nsPQPrGl2ew9A+saCod/WNxtbYsrfb17WBxx5ddD2281xC88klvDcSXEnWuzrqOGGC9zRUPZ7D0G9Y0uzWHoH1jQVCLreq6ntZbaO3it1mGy7RjTs1X2mYy20ZiCq8ZOODcdEdmsPQb1jS7PYegfWNdJuLqnQiSUlRqpFLmryxtH1Ma7Qw2gNNPOdSt0oI27p007s9h6B9Y0uz2HoH1jXX3Z+I4+1b8IJdX89xLHKQFMXQUahpxoiPN5P+onfU+A0/s9h6DesaXZ7D0D6xpG7OLbUtu0StW5JJx2bBsmbtiSiEk+cxoCWWSaVpZOk2vDVo0VYdnsPQb1jSNvZcCH1jSd2c+p1XAmFqEOmOPEfaH+BQd1ueo211IzrgFUYKNAAqI1WztCpUqVCRUqVKgFSpUqAVKlSoBUqVKgFSpUqAVKlSoBUqVKgFSpUqAVKlSoD/9k=";
- cc.loader.loadBinary = function (url, cb) {
- var self = this;
- var xhr = this.getXMLHttpRequest(),
- errInfo = "load " + url + " failed!";
- xhr.open("GET", url, true);
- if (cc.loader.loadBinary._IEFilter) {
- xhr.setRequestHeader("Accept-Charset", "x-user-defined");
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- var fileContents = cc._convertResponseBodyToText(xhr["responseBody"]);
- cb(null, self._str2Uint8Array(fileContents));
- } else cb(errInfo);
- };
- } else {
- if (xhr.overrideMimeType) xhr.overrideMimeType("text\/plain; charset=x-user-defined");
- xhr.onload = function () {
- xhr.readyState === 4 && xhr.status === 200 ? cb(null, self._str2Uint8Array(xhr.responseText)) : cb(errInfo);
- };
- }
- xhr.send(null);
- };
- cc.loader.loadBinary._IEFilter = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) && window.IEBinaryToArray_ByteStr && window.IEBinaryToArray_ByteStr_Last);
- cc.loader._str2Uint8Array = function (strData) {
- if (!strData)
- return null;
- var arrData = new Uint8Array(strData.length);
- for (var i = 0; i < strData.length; i++) {
- arrData[i] = strData.charCodeAt(i) & 0xff;
- }
- return arrData;
- };
- cc.loader.loadBinarySync = function (url) {
- var self = this;
- var req = this.getXMLHttpRequest();
- var errInfo = "load " + url + " failed!";
- req.open('GET', url, false);
- var arrayInfo = null;
- if (cc.loader.loadBinary._IEFilter) {
- req.setRequestHeader("Accept-Charset", "x-user-defined");
- req.send(null);
- if (req.status !== 200) {
- cc.log(errInfo);
- return null;
- }
- var fileContents = cc._convertResponseBodyToText(req["responseBody"]);
- if (fileContents) {
- arrayInfo = self._str2Uint8Array(fileContents);
- }
- } else {
- if (req.overrideMimeType)
- req.overrideMimeType('text\/plain; charset=x-user-defined');
- req.send(null);
- if (req.status !== 200) {
- cc.log(errInfo);
- return null;
- }
- arrayInfo = this._str2Uint8Array(req.responseText);
- }
- return arrayInfo;
- };
- window.Uint8Array = window.Uint8Array || window.Array;
- if (cc.loader.loadBinary._IEFilter) {
- var IEBinaryToArray_ByteStr_Script =
- "<!-- IEBinaryToArray_ByteStr -->\r\n" +
- "Function IEBinaryToArray_ByteStr(Binary)\r\n" +
- " IEBinaryToArray_ByteStr = CStr(Binary)\r\n" +
- "End Function\r\n" +
- "Function IEBinaryToArray_ByteStr_Last(Binary)\r\n" +
- " Dim lastIndex\r\n" +
- " lastIndex = LenB(Binary)\r\n" +
- " if lastIndex mod 2 Then\r\n" +
- " IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )\r\n" +
- " Else\r\n" +
- " IEBinaryToArray_ByteStr_Last = " + '""' + "\r\n" +
- " End If\r\n" +
- "End Function\r\n";// +
- var myVBScript = document.createElement('script');
- myVBScript.type = "text/vbscript";
- myVBScript.textContent = IEBinaryToArray_ByteStr_Script;
- document.body.appendChild(myVBScript);
- cc._convertResponseBodyToText = function (binary) {
- var byteMapping = {};
- for (var i = 0; i < 256; i++) {
- for (var j = 0; j < 256; j++) {
- byteMapping[ String.fromCharCode(i + j * 256) ] =
- String.fromCharCode(i) + String.fromCharCode(j);
- }
- }
- var rawBytes = IEBinaryToArray_ByteStr(binary);
- var lastChr = IEBinaryToArray_ByteStr_Last(binary);
- return rawBytes.replace(/[\s\S]/g,
- function (match) {
- return byteMapping[match];
- }) + lastChr;
- };
- }
- var cc = cc || {};
- var ClassManager = {
- id : (0|(Math.random()*998)),
- instanceId : (0|(Math.random()*998)),
- getNewID : function(){
- return this.id++;
- },
- getNewInstanceId : function(){
- return this.instanceId++;
- }
- };
- (function () {
- var fnTest = /\b_super\b/;
- cc.Class = function () {
- };
- cc.Class.extend = function (props) {
- var _super = this.prototype;
- var prototype = Object.create(_super);
- var classId = ClassManager.getNewID();
- ClassManager[classId] = _super;
- var desc = { writable: true, enumerable: false, configurable: true };
- prototype.__instanceId = null;
- function Class() {
- this.__instanceId = ClassManager.getNewInstanceId();
- if (this.ctor)
- this.ctor.apply(this, arguments);
- }
- Class.id = classId;
- desc.value = classId;
- Object.defineProperty(prototype, '__pid', desc);
- Class.prototype = prototype;
- desc.value = Class;
- Object.defineProperty(Class.prototype, 'constructor', desc);
- this.__getters__ && (Class.__getters__ = cc.clone(this.__getters__));
- this.__setters__ && (Class.__setters__ = cc.clone(this.__setters__));
- for(var idx = 0, li = arguments.length; idx < li; ++idx) {
- var prop = arguments[idx];
- for (var name in prop) {
- var isFunc = (typeof prop[name] === "function");
- var override = (typeof _super[name] === "function");
- var hasSuperCall = fnTest.test(prop[name]);
- if (isFunc && override && hasSuperCall) {
- desc.value = (function (name, fn) {
- return function () {
- var tmp = this._super;
- this._super = _super[name];
- var ret = fn.apply(this, arguments);
- this._super = tmp;
- return ret;
- };
- })(name, prop[name]);
- Object.defineProperty(prototype, name, desc);
- } else if (isFunc) {
- desc.value = prop[name];
- Object.defineProperty(prototype, name, desc);
- } else {
- prototype[name] = prop[name];
- }
- if (isFunc) {
- var getter, setter, propertyName;
- if (this.__getters__ && this.__getters__[name]) {
- propertyName = this.__getters__[name];
- for (var i in this.__setters__) {
- if (this.__setters__[i] === propertyName) {
- setter = i;
- break;
- }
- }
- cc.defineGetterSetter(prototype, propertyName, prop[name], prop[setter] ? prop[setter] : prototype[setter], name, setter);
- }
- if (this.__setters__ && this.__setters__[name]) {
- propertyName = this.__setters__[name];
- for (var i in this.__getters__) {
- if (this.__getters__[i] === propertyName) {
- getter = i;
- break;
- }
- }
- cc.defineGetterSetter(prototype, propertyName, prop[getter] ? prop[getter] : prototype[getter], prop[name], getter, name);
- }
- }
- }
- }
- Class.extend = cc.Class.extend;
- Class.implement = function (prop) {
- for (var name in prop) {
- prototype[name] = prop[name];
- }
- };
- return Class;
- };
- })();
- cc.defineGetterSetter = function (proto, prop, getter, setter, getterName, setterName){
- if (proto.__defineGetter__) {
- getter && proto.__defineGetter__(prop, getter);
- setter && proto.__defineSetter__(prop, setter);
- } else if (Object.defineProperty) {
- var desc = { enumerable: false, configurable: true };
- getter && (desc.get = getter);
- setter && (desc.set = setter);
- Object.defineProperty(proto, prop, desc);
- } else {
- throw new Error("browser does not support getters");
- }
- if(!getterName && !setterName) {
- var hasGetter = (getter != null), hasSetter = (setter != undefined), props = Object.getOwnPropertyNames(proto);
- for (var i = 0; i < props.length; i++) {
- var name = props[i];
- if( (proto.__lookupGetter__ ? proto.__lookupGetter__(name)
- : Object.getOwnPropertyDescriptor(proto, name))
- || typeof proto[name] !== "function" )
- continue;
- var func = proto[name];
- if (hasGetter && func === getter) {
- getterName = name;
- if(!hasSetter || setterName) break;
- }
- if (hasSetter && func === setter) {
- setterName = name;
- if(!hasGetter || getterName) break;
- }
- }
- }
- var ctor = proto.constructor;
- if (getterName) {
- if (!ctor.__getters__) {
- ctor.__getters__ = {};
- }
- ctor.__getters__[getterName] = prop;
- }
- if (setterName) {
- if (!ctor.__setters__) {
- ctor.__setters__ = {};
- }
- ctor.__setters__[setterName] = prop;
- }
- };
- cc.clone = function (obj) {
- var newObj = (obj.constructor) ? new obj.constructor : {};
- for (var key in obj) {
- var copy = obj[key];
- if (((typeof copy) === "object") && copy &&
- !(copy instanceof cc.Node) && !(copy instanceof HTMLElement)) {
- newObj[key] = cc.clone(copy);
- } else {
- newObj[key] = copy;
- }
- }
- return newObj;
- };
- cc.inject = function(srcPrototype, destPrototype){
- for(var key in srcPrototype)
- destPrototype[key] = srcPrototype[key];
- };
- cc.Point = function (x, y) {
- this.x = x || 0;
- this.y = y || 0;
- };
- cc.p = function (x, y) {
- if (x === undefined)
- return {x: 0, y: 0};
- if (y === undefined)
- return {x: x.x, y: x.y};
- return {x: x, y: y};
- };
- cc.pointEqualToPoint = function (point1, point2) {
- return point1 && point2 && (point1.x === point2.x) && (point1.y === point2.y);
- };
- cc.Size = function (width, height) {
- this.width = width || 0;
- this.height = height || 0;
- };
- cc.size = function (w, h) {
- if (w === undefined)
- return {width: 0, height: 0};
- if (h === undefined)
- return {width: w.width, height: w.height};
- return {width: w, height: h};
- };
- cc.sizeEqualToSize = function (size1, size2) {
- return (size1 && size2 && (size1.width === size2.width) && (size1.height === size2.height));
- };
- cc.Rect = function (x, y, width, height) {
- this.x = x||0;
- this.y = y||0;
- this.width = width||0;
- this.height = height||0;
- };
- cc.rect = function (x, y, w, h) {
- if (x === undefined)
- return {x: 0, y: 0, width: 0, height: 0};
- if (y === undefined)
- return {x: x.x, y: x.y, width: x.width, height: x.height};
- return {x: x, y: y, width: w, height: h };
- };
- cc.rectEqualToRect = function (rect1, rect2) {
- return rect1 && rect2 && (rect1.x === rect2.x) && (rect1.y === rect2.y) && (rect1.width === rect2.width) && (rect1.height === rect2.height);
- };
- cc._rectEqualToZero = function(rect){
- return rect && (rect.x === 0) && (rect.y === 0) && (rect.width === 0) && (rect.height === 0);
- };
- cc.rectContainsRect = function (rect1, rect2) {
- if (!rect1 || !rect2)
- return false;
- return !((rect1.x >= rect2.x) || (rect1.y >= rect2.y) ||
- ( rect1.x + rect1.width <= rect2.x + rect2.width) ||
- ( rect1.y + rect1.height <= rect2.y + rect2.height));
- };
- cc.rectGetMaxX = function (rect) {
- return (rect.x + rect.width);
- };
- cc.rectGetMidX = function (rect) {
- return (rect.x + rect.width / 2.0);
- };
- cc.rectGetMinX = function (rect) {
- return rect.x;
- };
- cc.rectGetMaxY = function (rect) {
- return(rect.y + rect.height);
- };
- cc.rectGetMidY = function (rect) {
- return rect.y + rect.height / 2.0;
- };
- cc.rectGetMinY = function (rect) {
- return rect.y;
- };
- cc.rectContainsPoint = function (rect, point) {
- return (point.x >= cc.rectGetMinX(rect) && point.x <= cc.rectGetMaxX(rect) &&
- point.y >= cc.rectGetMinY(rect) && point.y <= cc.rectGetMaxY(rect)) ;
- };
- cc.rectIntersectsRect = function (ra, rb) {
- var maxax = ra.x + ra.width,
- maxay = ra.y + ra.height,
- maxbx = rb.x + rb.width,
- maxby = rb.y + rb.height;
- return !(maxax < rb.x || maxbx < ra.x || maxay < rb.y || maxby < ra.y);
- };
- cc.rectOverlapsRect = function (rectA, rectB) {
- return !((rectA.x + rectA.width < rectB.x) ||
- (rectB.x + rectB.width < rectA.x) ||
- (rectA.y + rectA.height < rectB.y) ||
- (rectB.y + rectB.height < rectA.y));
- };
- cc.rectUnion = function (rectA, rectB) {
- var rect = cc.rect(0, 0, 0, 0);
- rect.x = Math.min(rectA.x, rectB.x);
- rect.y = Math.min(rectA.y, rectB.y);
- rect.width = Math.max(rectA.x + rectA.width, rectB.x + rectB.width) - rect.x;
- rect.height = Math.max(rectA.y + rectA.height, rectB.y + rectB.height) - rect.y;
- return rect;
- };
- cc.rectIntersection = function (rectA, rectB) {
- var intersection = cc.rect(
- Math.max(cc.rectGetMinX(rectA), cc.rectGetMinX(rectB)),
- Math.max(cc.rectGetMinY(rectA), cc.rectGetMinY(rectB)),
- 0, 0);
- intersection.width = Math.min(cc.rectGetMaxX(rectA), cc.rectGetMaxX(rectB)) - cc.rectGetMinX(intersection);
- intersection.height = Math.min(cc.rectGetMaxY(rectA), cc.rectGetMaxY(rectB)) - cc.rectGetMinY(intersection);
- return intersection;
- };
- cc.SAXParser = cc.Class.extend({
- _parser: null,
- _isSupportDOMParser: null,
- ctor: function () {
- if (window.DOMParser) {
- this._isSupportDOMParser = true;
- this._parser = new DOMParser();
- } else {
- this._isSupportDOMParser = false;
- }
- },
- parse : function(xmlTxt){
- return this._parseXML(xmlTxt);
- },
- _parseXML: function (textxml) {
- var xmlDoc;
- if (this._isSupportDOMParser) {
- xmlDoc = this._parser.parseFromString(textxml, "text/xml");
- } else {
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async = "false";
- xmlDoc.loadXML(textxml);
- }
- return xmlDoc;
- }
- });
- cc.PlistParser = cc.SAXParser.extend({
- parse : function (xmlTxt) {
- var xmlDoc = this._parseXML(xmlTxt);
- var plist = xmlDoc.documentElement;
- if (plist.tagName !== 'plist') {
- cc.warn("Not a plist file!");
- return {};
- }
- var node = null;
- for (var i = 0, len = plist.childNodes.length; i < len; i++) {
- node = plist.childNodes[i];
- if (node.nodeType === 1)
- break;
- }
- xmlDoc = null;
- return this._parseNode(node);
- },
- _parseNode: function (node) {
- var data = null, tagName = node.tagName;
- if(tagName === "dict"){
- data = this._parseDict(node);
- }else if(tagName === "array"){
- data = this._parseArray(node);
- }else if(tagName === "string"){
- if (node.childNodes.length === 1)
- data = node.firstChild.nodeValue;
- else {
- data = "";
- for (var i = 0; i < node.childNodes.length; i++)
- data += node.childNodes[i].nodeValue;
- }
- }else if(tagName === "false"){
- data = false;
- }else if(tagName === "true"){
- data = true;
- }else if(tagName === "real"){
- data = parseFloat(node.firstChild.nodeValue);
- }else if(tagName === "integer"){
- data = parseInt(node.firstChild.nodeValue, 10);
- }
- return data;
- },
- _parseArray: function (node) {
- var data = [];
- for (var i = 0, len = node.childNodes.length; i < len; i++) {
- var child = node.childNodes[i];
- if (child.nodeType !== 1)
- continue;
- data.push(this._parseNode(child));
- }
- return data;
- },
- _parseDict: function (node) {
- var data = {};
- var key = null;
- for (var i = 0, len = node.childNodes.length; i < len; i++) {
- var child = node.childNodes[i];
- if (child.nodeType !== 1)
- continue;
- if (child.tagName === 'key')
- key = child.firstChild.nodeValue;
- else
- data[key] = this._parseNode(child);
- }
- return data;
- }
- });
- cc.saxParser = new cc.SAXParser();
- cc.plistParser = new cc.PlistParser();
- cc._txtLoader = {
- load : function(realUrl, url, res, cb){
- cc.loader.loadTxt(realUrl, cb);
- }
- };
- cc.loader.register(["txt", "xml", "vsh", "fsh", "atlas"], cc._txtLoader);
- cc._jsonLoader = {
- load : function(realUrl, url, res, cb){
- cc.loader.loadJson(realUrl, cb);
- }
- };
- cc.loader.register(["json", "ExportJson"], cc._jsonLoader);
- cc._jsLoader = {
- load : function(realUrl, url, res, cb){
- cc.loader.loadJs(realUrl, cb);
- }
- };
- cc.loader.register(["js"], cc._jsLoader);
- cc._imgLoader = {
- load : function(realUrl, url, res, cb){
- var callback;
- if (cc.loader.isLoading(realUrl)) {
- callback = cb;
- }
- else {
- callback = function(err, img){
- if(err)
- return cb(err);
- cc.loader.cache[url] = img;
- cc.textureCache.handleLoadedTexture(url);
- cb(null, img);
- };
- }
- cc.loader.loadImg(realUrl, callback);
- }
- };
- cc.loader.register(["png", "jpg", "bmp","jpeg","gif", "ico", "tiff", "webp"], cc._imgLoader);
- cc._serverImgLoader = {
- load : function(realUrl, url, res, cb){
- cc._imgLoader.load(res.src, url, res, cb);
- }
- };
- cc.loader.register(["serverImg"], cc._serverImgLoader);
- cc._plistLoader = {
- load : function(realUrl, url, res, cb){
- cc.loader.loadTxt(realUrl, function(err, txt){
- if(err)
- return cb(err);
- cb(null, cc.plistParser.parse(txt));
- });
- }
- };
- cc.loader.register(["plist"], cc._plistLoader);
- cc._fontLoader = {
- TYPE : {
- ".eot" : "embedded-opentype",
- ".ttf" : "truetype",
- ".ttc" : "truetype",
- ".woff" : "woff",
- ".svg" : "svg"
- },
- _loadFont : function(name, srcs, type){
- var doc = document, path = cc.path, TYPE = this.TYPE, fontStyle = document.createElement("style");
- fontStyle.type = "text/css";
- doc.body.appendChild(fontStyle);
- var fontStr = "";
- if(isNaN(name - 0))
- fontStr += "@font-face { font-family:" + name + "; src:";
- else
- fontStr += "@font-face { font-family:'" + name + "'; src:";
- if(srcs instanceof Array){
- for(var i = 0, li = srcs.length; i < li; i++){
- var src = srcs[i];
- type = path.extname(src).toLowerCase();
- fontStr += "url('" + srcs[i] + "') format('" + TYPE[type] + "')";
- fontStr += (i === li - 1) ? ";" : ",";
- }
- }else{
- type = type.toLowerCase();
- fontStr += "url('" + srcs + "') format('" + TYPE[type] + "');";
- }
- fontStyle.textContent += fontStr + "}";
- var preloadDiv = document.createElement("div");
- var _divStyle = preloadDiv.style;
- _divStyle.fontFamily = name;
- preloadDiv.innerHTML = ".";
- _divStyle.position = "absolute";
- _divStyle.left = "-100px";
- _divStyle.top = "-100px";
- doc.body.appendChild(preloadDiv);
- },
- load : function(realUrl, url, res, cb){
- var self = this;
- var type = res.type, name = res.name, srcs = res.srcs;
- if(cc.isString(res)){
- type = cc.path.extname(res);
- name = cc.path.basename(res, type);
- self._loadFont(name, res, type);
- }else{
- self._loadFont(name, srcs);
- }
- if(document.fonts){
- document.fonts.load("1em " + name).then(function(){
- cb(null, true);
- }, function(err){
- cb(err);
- });
- }else{
- cb(null, true);
- }
- }
- };
- cc.loader.register(["font", "eot", "ttf", "woff", "svg", "ttc"], cc._fontLoader);
- cc._binaryLoader = {
- load : function(realUrl, url, res, cb){
- cc.loader.loadBinary(realUrl, cb);
- }
- };
- cc._csbLoader = {
- load: function(realUrl, url, res, cb){
- cc.loader.loadCsb(realUrl, cb);
- }
- };
- cc.loader.register(["csb"], cc._csbLoader);
- window["CocosEngine"] = cc.ENGINE_VERSION = "Cocos2d-JS v3.13";
- cc.FIX_ARTIFACTS_BY_STRECHING_TEXEL = 0;
- cc.DIRECTOR_STATS_POSITION = cc.p(0, 0);
- cc.DIRECTOR_FPS_INTERVAL = 0.5;
- cc.COCOSNODE_RENDER_SUBPIXEL = 1;
- cc.SPRITEBATCHNODE_RENDER_SUBPIXEL = 1;
- cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA = 1;
- cc.TEXTURE_ATLAS_USE_TRIANGLE_STRIP = 0;
- cc.TEXTURE_ATLAS_USE_VAO = 0;
- cc.TEXTURE_NPOT_SUPPORT = 0;
- cc.RETINA_DISPLAY_SUPPORT = 1;
- cc.RETINA_DISPLAY_FILENAME_SUFFIX = "-hd";
- cc.USE_LA88_LABELS = 1;
- cc.SPRITE_DEBUG_DRAW = 0;
- cc.SPRITEBATCHNODE_DEBUG_DRAW = 0;
- cc.LABELBMFONT_DEBUG_DRAW = 0;
- cc.LABELATLAS_DEBUG_DRAW = 0;
- cc.IS_RETINA_DISPLAY_SUPPORTED = 1;
- cc.DEFAULT_ENGINE = cc.ENGINE_VERSION + "-canvas";
- cc.ENABLE_STACKABLE_ACTIONS = 1;
- cc.ENABLE_GL_STATE_CACHE = 1;
- cc.$ = function (x) {
- var parent = (this === cc) ? document : this;
- var el = (x instanceof HTMLElement) ? x : parent.querySelector(x);
- if (el) {
- el.find = el.find || cc.$;
- el.hasClass = el.hasClass || function (cls) {
- return this.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
- };
- el.addClass = el.addClass || function (cls) {
- if (!this.hasClass(cls)) {
- if (this.className) {
- this.className += " ";
- }
- this.className += cls;
- }
- return this;
- };
- el.removeClass = el.removeClass || function (cls) {
- if (this.hasClass(cls)) {
- this.className = this.className.replace(cls, '');
- }
- return this;
- };
- el.remove = el.remove || function () {
- if (this.parentNode)
- this.parentNode.removeChild(this);
- return this;
- };
- el.appendTo = el.appendTo || function (x) {
- x.appendChild(this);
- return this;
- };
- el.prependTo = el.prependTo || function (x) {
- ( x.childNodes[0]) ? x.insertBefore(this, x.childNodes[0]) : x.appendChild(this);
- return this;
- };
- el.transforms = el.transforms || function () {
- this.style[cc.$.trans] = cc.$.translate(this.position) + cc.$.rotate(this.rotation) + cc.$.scale(this.scale) + cc.$.skew(this.skew);
- return this;
- };
- el.position = el.position || {x: 0, y: 0};
- el.rotation = el.rotation || 0;
- el.scale = el.scale || {x: 1, y: 1};
- el.skew = el.skew || {x: 0, y: 0};
- el.translates = function (x, y) {
- this.position.x = x;
- this.position.y = y;
- this.transforms();
- return this
- };
- el.rotate = function (x) {
- this.rotation = x;
- this.transforms();
- return this
- };
- el.resize = function (x, y) {
- this.scale.x = x;
- this.scale.y = y;
- this.transforms();
- return this
- };
- el.setSkew = function (x, y) {
- this.skew.x = x;
- this.skew.y = y;
- this.transforms();
- return this
- };
- }
- return el;
- };
- switch (cc.sys.browserType) {
- case cc.sys.BROWSER_TYPE_FIREFOX:
- cc.$.pfx = "Moz";
- cc.$.hd = true;
- break;
- case cc.sys.BROWSER_TYPE_CHROME:
- case cc.sys.BROWSER_TYPE_SAFARI:
- cc.$.pfx = "webkit";
- cc.$.hd = true;
- break;
- case cc.sys.BROWSER_TYPE_OPERA:
- cc.$.pfx = "O";
- cc.$.hd = false;
- break;
- case cc.sys.BROWSER_TYPE_IE:
- cc.$.pfx = "ms";
- cc.$.hd = false;
- break;
- default:
- cc.$.pfx = "webkit";
- cc.$.hd = true;
- }
- cc.$.trans = cc.$.pfx + "Transform";
- cc.$.translate = (cc.$.hd) ? function (a) {
- return "translate3d(" + a.x + "px, " + a.y + "px, 0) "
- } : function (a) {
- return "translate(" + a.x + "px, " + a.y + "px) "
- };
- cc.$.rotate = (cc.$.hd) ? function (a) {
- return "rotateZ(" + a + "deg) ";
- } : function (a) {
- return "rotate(" + a + "deg) ";
- };
- cc.$.scale = function (a) {
- return "scale(" + a.x + ", " + a.y + ") "
- };
- cc.$.skew = function (a) {
- return "skewX(" + -a.x + "deg) skewY(" + a.y + "deg)";
- };
- cc.$new = function (x) {
- return cc.$(document.createElement(x))
- };
- cc.$.findpos = function (obj) {
- var curleft = 0;
- var curtop = 0;
- do {
- curleft += obj.offsetLeft;
- curtop += obj.offsetTop;
- } while (obj = obj.offsetParent);
- return {x: curleft, y: curtop};
- };
- cc.INVALID_INDEX = -1;
- cc.PI = Math.PI;
- cc.FLT_MAX = parseFloat('3.402823466e+38F');
- cc.FLT_MIN = parseFloat("1.175494351e-38F");
- cc.RAD = cc.PI / 180;
- cc.DEG = 180 / cc.PI;
- cc.UINT_MAX = 0xffffffff;
- cc.swap = function (x, y, ref) {
- if (cc.isObject(ref) && !cc.isUndefined(ref.x) && !cc.isUndefined(ref.y)) {
- var tmp = ref[x];
- ref[x] = ref[y];
- ref[y] = tmp;
- } else
- cc.log(cc._LogInfos.swap);
- };
- cc.lerp = function (a, b, r) {
- return a + (b - a) * r;
- };
- cc.rand = function () {
- return Math.random() * 0xffffff;
- };
- cc.randomMinus1To1 = function () {
- return (Math.random() - 0.5) * 2;
- };
- cc.random0To1 = Math.random;
- cc.degreesToRadians = function (angle) {
- return angle * cc.RAD;
- };
- cc.radiansToDegrees = function (angle) {
- return angle * cc.DEG;
- };
- cc.radiansToDegress = function (angle) {
- cc.log(cc._LogInfos.radiansToDegress);
- return angle * cc.DEG;
- };
- cc.REPEAT_FOREVER = Number.MAX_VALUE - 1;
- cc.nodeDrawSetup = function (node) {
- if (node._shaderProgram) {
- node._shaderProgram.use();
- node._shaderProgram.setUniformForModelViewAndProjectionMatrixWithMat4();
- }
- };
- cc.enableDefaultGLStates = function () {
- };
- cc.disableDefaultGLStates = function () {
- };
- cc.incrementGLDraws = function (addNumber) {
- cc.g_NumberOfDraws += addNumber;
- };
- cc.FLT_EPSILON = 0.0000001192092896;
- cc.contentScaleFactor = cc.IS_RETINA_DISPLAY_SUPPORTED ? function () {
- return cc.director.getContentScaleFactor();
- } : function () {
- return 1;
- };
- cc.pointPointsToPixels = function (points) {
- var scale = cc.contentScaleFactor();
- return cc.p(points.x * scale, points.y * scale);
- };
- cc.pointPixelsToPoints = function (pixels) {
- var scale = cc.contentScaleFactor();
- return cc.p(pixels.x / scale, pixels.y / scale);
- };
- cc._pointPixelsToPointsOut = function(pixels, outPoint){
- var scale = cc.contentScaleFactor();
- outPoint.x = pixels.x / scale;
- outPoint.y = pixels.y / scale;
- };
- cc.sizePointsToPixels = function (sizeInPoints) {
- var scale = cc.contentScaleFactor();
- return cc.size(sizeInPoints.width * scale, sizeInPoints.height * scale);
- };
- cc.sizePixelsToPoints = function (sizeInPixels) {
- var scale = cc.contentScaleFactor();
- return cc.size(sizeInPixels.width / scale, sizeInPixels.height / scale);
- };
- cc._sizePixelsToPointsOut = function (sizeInPixels, outSize) {
- var scale = cc.contentScaleFactor();
- outSize.width = sizeInPixels.width / scale;
- outSize.height = sizeInPixels.height / scale;
- };
- cc.rectPixelsToPoints = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (pixel) {
- var scale = cc.contentScaleFactor();
- return cc.rect(pixel.x / scale, pixel.y / scale,
- pixel.width / scale, pixel.height / scale);
- } : function (p) {
- return p;
- };
- cc.rectPointsToPixels = cc.IS_RETINA_DISPLAY_SUPPORTED ? function (point) {
- var scale = cc.contentScaleFactor();
- return cc.rect(point.x * scale, point.y * scale,
- point.width * scale, point.height * scale);
- } : function (p) {
- return p;
- };
- cc.ONE = 1;
- cc.ZERO = 0;
- cc.SRC_ALPHA = 0x0302;
- cc.SRC_ALPHA_SATURATE = 0x308;
- cc.SRC_COLOR = 0x300;
- cc.DST_ALPHA = 0x304;
- cc.DST_COLOR = 0x306;
- cc.ONE_MINUS_SRC_ALPHA = 0x0303;
- cc.ONE_MINUS_SRC_COLOR = 0x301;
- cc.ONE_MINUS_DST_ALPHA = 0x305;
- cc.ONE_MINUS_DST_COLOR = 0x0307;
- cc.ONE_MINUS_CONSTANT_ALPHA = 0x8004;
- cc.ONE_MINUS_CONSTANT_COLOR = 0x8002;
- cc.LINEAR = 0x2601;
- cc.REPEAT = 0x2901;
- cc.CLAMP_TO_EDGE = 0x812f;
- cc.MIRRORED_REPEAT = 0x8370;
- cc.BLEND_SRC = cc.SRC_ALPHA;
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL
- && cc.OPTIMIZE_BLEND_FUNC_FOR_PREMULTIPLIED_ALPHA) {
- cc.BLEND_SRC = cc.ONE;
- }
- });
- cc.BLEND_DST = cc.ONE_MINUS_SRC_ALPHA;
- cc.checkGLErrorDebug = function () {
- if (cc.renderMode === cc.game.RENDER_TYPE_WEBGL) {
- var _error = cc._renderContext.getError();
- if (_error) {
- cc.log(cc._LogInfos.checkGLErrorDebug, _error);
- }
- }
- };
- cc.ORIENTATION_PORTRAIT = 1;
- cc.ORIENTATION_LANDSCAPE = 2;
- cc.ORIENTATION_AUTO = 3;
- cc.VERTEX_ATTRIB_FLAG_NONE = 0;
- cc.VERTEX_ATTRIB_FLAG_POSITION = 1 << 0;
- cc.VERTEX_ATTRIB_FLAG_COLOR = 1 << 1;
- cc.VERTEX_ATTRIB_FLAG_TEX_COORDS = 1 << 2;
- cc.VERTEX_ATTRIB_FLAG_POS_COLOR_TEX = ( cc.VERTEX_ATTRIB_FLAG_POSITION | cc.VERTEX_ATTRIB_FLAG_COLOR | cc.VERTEX_ATTRIB_FLAG_TEX_COORDS );
- cc.GL_ALL = 0;
- cc.VERTEX_ATTRIB_POSITION = 0;
- cc.VERTEX_ATTRIB_COLOR = 1;
- cc.VERTEX_ATTRIB_TEX_COORDS = 2;
- cc.VERTEX_ATTRIB_MAX = 7;
- cc.UNIFORM_PMATRIX = 0;
- cc.UNIFORM_MVMATRIX = 1;
- cc.UNIFORM_MVPMATRIX = 2;
- cc.UNIFORM_TIME = 3;
- cc.UNIFORM_SINTIME = 4;
- cc.UNIFORM_COSTIME = 5;
- cc.UNIFORM_RANDOM01 = 6;
- cc.UNIFORM_SAMPLER = 7;
- cc.UNIFORM_MAX = 8;
- cc.SHADER_POSITION_TEXTURECOLOR = "ShaderPositionTextureColor";
- cc.SHADER_SPRITE_POSITION_TEXTURECOLOR = "ShaderSpritePositionTextureColor";
- cc.SHADER_POSITION_TEXTURECOLORALPHATEST = "ShaderPositionTextureColorAlphaTest";
- cc.SHADER_SPRITE_POSITION_TEXTURECOLORALPHATEST = "ShaderSpritePositionTextureColorAlphaTest";
- cc.SHADER_POSITION_COLOR = "ShaderPositionColor";
- cc.SHADER_SPRITE_POSITION_COLOR = "ShaderSpritePositionColor";
- cc.SHADER_POSITION_TEXTURE = "ShaderPositionTexture";
- cc.SHADER_POSITION_TEXTURE_UCOLOR = "ShaderPositionTexture_uColor";
- cc.SHADER_POSITION_TEXTUREA8COLOR = "ShaderPositionTextureA8Color";
- cc.SHADER_POSITION_UCOLOR = "ShaderPosition_uColor";
- cc.SHADER_POSITION_LENGTHTEXTURECOLOR = "ShaderPositionLengthTextureColor";
- cc.UNIFORM_PMATRIX_S = "CC_PMatrix";
- cc.UNIFORM_MVMATRIX_S = "CC_MVMatrix";
- cc.UNIFORM_MVPMATRIX_S = "CC_MVPMatrix";
- cc.UNIFORM_TIME_S = "CC_Time";
- cc.UNIFORM_SINTIME_S = "CC_SinTime";
- cc.UNIFORM_COSTIME_S = "CC_CosTime";
- cc.UNIFORM_RANDOM01_S = "CC_Random01";
- cc.UNIFORM_SAMPLER_S = "CC_Texture0";
- cc.UNIFORM_ALPHA_TEST_VALUE_S = "CC_alpha_value";
- cc.ATTRIBUTE_NAME_COLOR = "a_color";
- cc.ATTRIBUTE_NAME_POSITION = "a_position";
- cc.ATTRIBUTE_NAME_TEX_COORD = "a_texCoord";
- cc.ATTRIBUTE_NAME_MVMAT = "a_mvMatrix";
- cc.ITEM_SIZE = 32;
- cc.CURRENT_ITEM = 0xc0c05001;
- cc.ZOOM_ACTION_TAG = 0xc0c05002;
- cc.NORMAL_TAG = 8801;
- cc.SELECTED_TAG = 8802;
- cc.DISABLE_TAG = 8803;
- cc.arrayVerifyType = function (arr, type) {
- if (arr && arr.length > 0) {
- for (var i = 0; i < arr.length; i++) {
- if (!(arr[i] instanceof type)) {
- cc.log("element type is wrong!");
- return false;
- }
- }
- }
- return true;
- };
- cc.arrayRemoveObject = function (arr, delObj) {
- for (var i = 0, l = arr.length; i < l; i++) {
- if (arr[i] === delObj) {
- arr.splice(i, 1);
- break;
- }
- }
- };
- cc.arrayRemoveArray = function (arr, minusArr) {
- for (var i = 0, l = minusArr.length; i < l; i++) {
- cc.arrayRemoveObject(arr, minusArr[i]);
- }
- };
- cc.arrayAppendObjectsToIndex = function(arr, addObjs,index){
- arr.splice.apply(arr, [index, 0].concat(addObjs));
- return arr;
- };
- cc.copyArray = function(arr){
- var i, len = arr.length, arr_clone = new Array(len);
- for (i = 0; i < len; i += 1)
- arr_clone[i] = arr[i];
- return arr_clone;
- };
- cc._tmp.PrototypeColor = function () {
- var _p = cc.color;
- _p._getWhite = function () {
- return _p(255, 255, 255);
- };
- _p._getYellow = function () {
- return _p(255, 255, 0);
- };
- _p._getBlue = function () {
- return _p(0, 0, 255);
- };
- _p._getGreen = function () {
- return _p(0, 255, 0);
- };
- _p._getRed = function () {
- return _p(255, 0, 0);
- };
- _p._getMagenta = function () {
- return _p(255, 0, 255);
- };
- _p._getBlack = function () {
- return _p(0, 0, 0);
- };
- _p._getOrange = function () {
- return _p(255, 127, 0);
- };
- _p._getGray = function () {
- return _p(166, 166, 166);
- };
- _p.WHITE;
- cc.defineGetterSetter(_p, "WHITE", _p._getWhite);
- _p.YELLOW;
- cc.defineGetterSetter(_p, "YELLOW", _p._getYellow);
- _p.BLUE;
- cc.defineGetterSetter(_p, "BLUE", _p._getBlue);
- _p.GREEN;
- cc.defineGetterSetter(_p, "GREEN", _p._getGreen);
- _p.RED;
- cc.defineGetterSetter(_p, "RED", _p._getRed);
- _p.MAGENTA;
- cc.defineGetterSetter(_p, "MAGENTA", _p._getMagenta);
- _p.BLACK;
- cc.defineGetterSetter(_p, "BLACK", _p._getBlack);
- _p.ORANGE;
- cc.defineGetterSetter(_p, "ORANGE", _p._getOrange);
- _p.GRAY;
- cc.defineGetterSetter(_p, "GRAY", _p._getGray);
- cc.BlendFunc._disable = function(){
- return new cc.BlendFunc(cc.ONE, cc.ZERO);
- };
- cc.BlendFunc._alphaPremultiplied = function(){
- return new cc.BlendFunc(cc.ONE, cc.ONE_MINUS_SRC_ALPHA);
- };
- cc.BlendFunc._alphaNonPremultiplied = function(){
- return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE_MINUS_SRC_ALPHA);
- };
- cc.BlendFunc._additive = function(){
- return new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE);
- };
- cc.BlendFunc.DISABLE;
- cc.defineGetterSetter(cc.BlendFunc, "DISABLE", cc.BlendFunc._disable);
- cc.BlendFunc.ALPHA_PREMULTIPLIED;
- cc.defineGetterSetter(cc.BlendFunc, "ALPHA_PREMULTIPLIED", cc.BlendFunc._alphaPremultiplied);
- cc.BlendFunc.ALPHA_NON_PREMULTIPLIED;
- cc.defineGetterSetter(cc.BlendFunc, "ALPHA_NON_PREMULTIPLIED", cc.BlendFunc._alphaNonPremultiplied);
- cc.BlendFunc.ADDITIVE;
- cc.defineGetterSetter(cc.BlendFunc, "ADDITIVE", cc.BlendFunc._additive);
- };
- var cc = cc || {};
- cc._tmp = cc._tmp || {};
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if (cc._renderType !== cc.game.RENDER_TYPE_WEBGL) {
- return;
- }
- cc.color = function (r, g, b, a, arrayBuffer, offset) {
- if (r === undefined)
- return new cc.Color(0, 0, 0, 255, arrayBuffer, offset);
- if (cc.isString(r)) {
- var color = cc.hexToColor(r);
- return new cc.Color(color.r, color.g, color.b, color.a);
- }
- if (cc.isObject(r))
- return new cc.Color(r.r, r.g, r.b, r.a, r.arrayBuffer, r.offset);
- return new cc.Color(r, g, b, a, arrayBuffer, offset);
- };
- cc.Color = function (r, g, b, a, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Color.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
- this._view = new Uint8Array(locArrayBuffer, locOffset, 4);
- this._view[0] = r || 0;
- this._view[1] = g || 0;
- this._view[2] = b || 0;
- this._view[3] = (a == null) ? 255 : a;
- if (a === undefined)
- this.a_undefined = true;
- };
- cc.Color.BYTES_PER_ELEMENT = 4;
- var _p = cc.Color.prototype;
- _p._getR = function () {
- return this._view[0];
- };
- _p._setR = function (value) {
- this._view[0] = value < 0 ? 0 : value;
- };
- _p._getG = function () {
- return this._view[1];
- };
- _p._setG = function (value) {
- this._view[1] = value < 0 ? 0 : value;
- };
- _p._getB = function () {
- return this._view[2];
- };
- _p._setB = function (value) {
- this._view[2] = value < 0 ? 0 : value;
- };
- _p._getA = function () {
- return this._view[3];
- };
- _p._setA = function (value) {
- this._view[3] = value < 0 ? 0 : value;
- };
- _p.r;
- cc.defineGetterSetter(_p, "r", _p._getR, _p._setR);
- _p.g;
- cc.defineGetterSetter(_p, "g", _p._getG, _p._setG);
- _p.b;
- cc.defineGetterSetter(_p, "b", _p._getB, _p._setB);
- _p.a;
- cc.defineGetterSetter(_p, "a", _p._getA, _p._setA);
- cc.assert(cc.isFunction(cc._tmp.PrototypeColor), cc._LogInfos.MissingFile, "CCTypesPropertyDefine.js");
- cc._tmp.PrototypeColor();
- delete cc._tmp.PrototypeColor;
- });
- cc.Color = function (r, g, b, a) {
- this.r = r || 0;
- this.g = g || 0;
- this.b = b || 0;
- this.a = (a == null) ? 255 : a;
- };
- cc.color = function (r, g, b, a) {
- if (r === undefined)
- return {r: 0, g: 0, b: 0, a: 255};
- if (cc.isString(r))
- return cc.hexToColor(r);
- if (cc.isObject(r))
- return {r: r.r, g: r.g, b: r.b, a: (r.a == null) ? 255 : r.a};
- return {r: r, g: g, b: b, a: (a == null ? 255 : a)};
- };
- cc.colorEqual = function (color1, color2) {
- return color1.r === color2.r && color1.g === color2.g && color1.b === color2.b;
- };
- cc.Acceleration = function (x, y, z, timestamp) {
- this.x = x || 0;
- this.y = y || 0;
- this.z = z || 0;
- this.timestamp = timestamp || 0;
- };
- cc.Vertex2F = function (x, y, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex2F.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- this._view = new Float32Array(this._arrayBuffer, this._offset, 2);
- this._view[0] = x || 0;
- this._view[1] = y || 0;
- };
- cc.Vertex2F.BYTES_PER_ELEMENT = 8;
- _p = cc.Vertex2F.prototype;
- _p._getX = function () {
- return this._view[0];
- };
- _p._setX = function (xValue) {
- this._view[0] = xValue;
- };
- _p._getY = function () {
- return this._view[1];
- };
- _p._setY = function (yValue) {
- this._view[1] = yValue;
- };
- _p.x;
- cc.defineGetterSetter(_p, "x", _p._getX, _p._setX);
- _p.y;
- cc.defineGetterSetter(_p, "y", _p._getY, _p._setY);
- cc.Vertex3F = function (x, y, z, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Vertex3F.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
- this._view = new Float32Array(locArrayBuffer, locOffset, 3);
- this._view[0] = x || 0;
- this._view[1] = y || 0;
- this._view[2] = z || 0;
- };
- cc.Vertex3F.BYTES_PER_ELEMENT = 12;
- _p = cc.Vertex3F.prototype;
- _p._getX = function () {
- return this._view[0];
- };
- _p._setX = function (xValue) {
- this._view[0] = xValue;
- };
- _p._getY = function () {
- return this._view[1];
- };
- _p._setY = function (yValue) {
- this._view[1] = yValue;
- };
- _p._getZ = function () {
- return this._view[2];
- };
- _p._setZ = function (zValue) {
- this._view[2] = zValue;
- };
- _p.x;
- cc.defineGetterSetter(_p, "x", _p._getX, _p._setX);
- _p.y;
- cc.defineGetterSetter(_p, "y", _p._getY, _p._setY);
- _p.z;
- cc.defineGetterSetter(_p, "z", _p._getZ, _p._setZ);
- cc.Tex2F = function (u, v, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Tex2F.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- this._view = new Float32Array(this._arrayBuffer, this._offset, 2);
- this._view[0] = u || 0;
- this._view[1] = v || 0;
- };
- cc.Tex2F.BYTES_PER_ELEMENT = 8;
- _p = cc.Tex2F.prototype;
- _p._getU = function () {
- return this._view[0];
- };
- _p._setU = function (xValue) {
- this._view[0] = xValue;
- };
- _p._getV = function () {
- return this._view[1];
- };
- _p._setV = function (yValue) {
- this._view[1] = yValue;
- };
- _p.u;
- cc.defineGetterSetter(_p, "u", _p._getU, _p._setU);
- _p.v;
- cc.defineGetterSetter(_p, "v", _p._getV, _p._setV);
- cc.Quad2 = function (tl, tr, bl, br, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Quad2.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex2F.BYTES_PER_ELEMENT;
- this._tl = tl ? new cc.Vertex2F(tl.x, tl.y, locArrayBuffer, locOffset) : new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._tr = tr ? new cc.Vertex2F(tr.x, tr.y, locArrayBuffer, locOffset) : new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._bl = bl ? new cc.Vertex2F(bl.x, bl.y, locArrayBuffer, locOffset) : new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._br = br ? new cc.Vertex2F(br.x, br.y, locArrayBuffer, locOffset) : new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
- };
- cc.Quad2.BYTES_PER_ELEMENT = 32;
- _p = cc.Quad2.prototype;
- _p._getTL = function () {
- return this._tl;
- };
- _p._setTL = function (tlValue) {
- this._tl._view[0] = tlValue.x;
- this._tl._view[1] = tlValue.y;
- };
- _p._getTR = function () {
- return this._tr;
- };
- _p._setTR = function (trValue) {
- this._tr._view[0] = trValue.x;
- this._tr._view[1] = trValue.y;
- };
- _p._getBL = function() {
- return this._bl;
- };
- _p._setBL = function (blValue) {
- this._bl._view[0] = blValue.x;
- this._bl._view[1] = blValue.y;
- };
- _p._getBR = function () {
- return this._br;
- };
- _p._setBR = function (brValue) {
- this._br._view[0] = brValue.x;
- this._br._view[1] = brValue.y;
- };
- _p.tl;
- cc.defineGetterSetter(_p, "tl", _p._getTL, _p._setTL);
- _p.tr;
- cc.defineGetterSetter(_p, "tr", _p._getTR, _p._setTR);
- _p.bl;
- cc.defineGetterSetter(_p, "bl", _p._getBL, _p._setBL);
- _p.br;
- cc.defineGetterSetter(_p, "br", _p._getBR, _p._setBR);
- cc.Quad3 = function (bl, br, tl, tr, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.Quad3.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.Vertex3F.BYTES_PER_ELEMENT;
- this.bl = bl ? new cc.Vertex3F(bl.x, bl.y, bl.z, locArrayBuffer, locOffset) : new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this.br = br ? new cc.Vertex3F(br.x, br.y, br.z, locArrayBuffer, locOffset) : new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this.tl = tl ? new cc.Vertex3F(tl.x, tl.y, tl.z, locArrayBuffer, locOffset) : new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this.tr = tr ? new cc.Vertex3F(tr.x, tr.y, tr.z, locArrayBuffer, locOffset) : new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
- };
- cc.Quad3.BYTES_PER_ELEMENT = 48;
- cc.V3F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
- this._vertices = vertices ? new cc.Vertex3F(vertices.x, vertices.y, vertices.z, locArrayBuffer, locOffset) :
- new cc.Vertex3F(0, 0, 0, locArrayBuffer, locOffset);
- locOffset += cc.Vertex3F.BYTES_PER_ELEMENT;
- this._colors = colors ? new cc.Color(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset) :
- new cc.Color(0, 0, 0, 0, locArrayBuffer, locOffset);
- locOffset += cc.Color.BYTES_PER_ELEMENT;
- this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset) :
- new cc.Tex2F(0, 0, locArrayBuffer, locOffset);
- };
- cc.V3F_C4B_T2F.BYTES_PER_ELEMENT = 24;
- _p = cc.V3F_C4B_T2F.prototype;
- _p._getVertices = function () {
- return this._vertices;
- };
- _p._setVertices = function (verticesValue) {
- var locVertices = this._vertices;
- locVertices._view[0] = verticesValue.x;
- locVertices._view[1] = verticesValue.y;
- locVertices._view[2] = verticesValue.z;
- };
- _p._getColor = function () {
- return this._colors;
- };
- _p._setColor = function (colorValue) {
- var locColors = this._colors;
- locColors._view[0] = colorValue.r;
- locColors._view[1] = colorValue.g;
- locColors._view[2] = colorValue.b;
- locColors._view[3] = colorValue.a;
- };
- _p._getTexCoords = function () {
- return this._texCoords;
- };
- _p._setTexCoords = function (texValue) {
- this._texCoords._view[0] = texValue.u;
- this._texCoords._view[1] = texValue.v;
- };
- _p.vertices;
- cc.defineGetterSetter(_p, "vertices", _p._getVertices, _p._setVertices);
- _p.colors;
- cc.defineGetterSetter(_p, "colors", _p._getColor, _p._setColor);
- _p.texCoords;
- cc.defineGetterSetter(_p, "texCoords", _p._getTexCoords, _p._setTexCoords);
- cc.V3F_C4B_T2F_Quad = function (tl, bl, tr, br, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V3F_C4B_T2F.BYTES_PER_ELEMENT;
- this._tl = tl ? new cc.V3F_C4B_T2F(tl.vertices, tl.colors, tl.texCoords, locArrayBuffer, locOffset) :
- new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._bl = bl ? new cc.V3F_C4B_T2F(bl.vertices, bl.colors, bl.texCoords, locArrayBuffer, locOffset) :
- new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._tr = tr ? new cc.V3F_C4B_T2F(tr.vertices, tr.colors, tr.texCoords, locArrayBuffer, locOffset) :
- new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._br = br ? new cc.V3F_C4B_T2F(br.vertices, br.colors, br.texCoords, locArrayBuffer, locOffset) :
- new cc.V3F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- };
- cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT = 96;
- _p = cc.V3F_C4B_T2F_Quad.prototype;
- _p._getTL = function () {
- return this._tl;
- };
- _p._setTL = function (tlValue) {
- var locTl = this._tl;
- locTl.vertices = tlValue.vertices;
- locTl.colors = tlValue.colors;
- locTl.texCoords = tlValue.texCoords;
- };
- _p._getBL = function () {
- return this._bl;
- };
- _p._setBL = function (blValue) {
- var locBl = this._bl;
- locBl.vertices = blValue.vertices;
- locBl.colors = blValue.colors;
- locBl.texCoords = blValue.texCoords;
- };
- _p._getTR = function () {
- return this._tr;
- };
- _p._setTR = function (trValue) {
- var locTr = this._tr;
- locTr.vertices = trValue.vertices;
- locTr.colors = trValue.colors;
- locTr.texCoords = trValue.texCoords;
- };
- _p._getBR = function () {
- return this._br;
- };
- _p._setBR = function (brValue) {
- var locBr = this._br;
- locBr.vertices = brValue.vertices;
- locBr.colors = brValue.colors;
- locBr.texCoords = brValue.texCoords;
- };
- _p._getArrayBuffer = function () {
- return this._arrayBuffer;
- };
- _p.tl;
- cc.defineGetterSetter(_p, "tl", _p._getTL, _p._setTL);
- _p.tr;
- cc.defineGetterSetter(_p, "tr", _p._getTR, _p._setTR);
- _p.bl;
- cc.defineGetterSetter(_p, "bl", _p._getBL, _p._setBL);
- _p.br;
- cc.defineGetterSetter(_p, "br", _p._getBR, _p._setBR);
- _p.arrayBuffer;
- cc.defineGetterSetter(_p, "arrayBuffer", _p._getArrayBuffer, null);
- cc.V3F_C4B_T2F_QuadZero = function () {
- return new cc.V3F_C4B_T2F_Quad();
- };
- cc.V3F_C4B_T2F_QuadCopy = function (sourceQuad) {
- if (!sourceQuad)
- return cc.V3F_C4B_T2F_QuadZero();
- var srcTL = sourceQuad.tl, srcBL = sourceQuad.bl, srcTR = sourceQuad.tr, srcBR = sourceQuad.br;
- return {
- tl: {vertices: {x: srcTL.vertices.x, y: srcTL.vertices.y, z: srcTL.vertices.z},
- colors: {r: srcTL.colors.r, g: srcTL.colors.g, b: srcTL.colors.b, a: srcTL.colors.a},
- texCoords: {u: srcTL.texCoords.u, v: srcTL.texCoords.v}},
- bl: {vertices: {x: srcBL.vertices.x, y: srcBL.vertices.y, z: srcBL.vertices.z},
- colors: {r: srcBL.colors.r, g: srcBL.colors.g, b: srcBL.colors.b, a: srcBL.colors.a},
- texCoords: {u: srcBL.texCoords.u, v: srcBL.texCoords.v}},
- tr: {vertices: {x: srcTR.vertices.x, y: srcTR.vertices.y, z: srcTR.vertices.z},
- colors: {r: srcTR.colors.r, g: srcTR.colors.g, b: srcTR.colors.b, a: srcTR.colors.a},
- texCoords: {u: srcTR.texCoords.u, v: srcTR.texCoords.v}},
- br: {vertices: {x: srcBR.vertices.x, y: srcBR.vertices.y, z: srcBR.vertices.z},
- colors: {r: srcBR.colors.r, g: srcBR.colors.g, b: srcBR.colors.b, a: srcBR.colors.a},
- texCoords: {u: srcBR.texCoords.u, v: srcBR.texCoords.v}}
- };
- };
- cc.V3F_C4B_T2F_QuadsCopy = function (sourceQuads) {
- if (!sourceQuads)
- return [];
- var retArr = [];
- for (var i = 0; i < sourceQuads.length; i++) {
- retArr.push(cc.V3F_C4B_T2F_QuadCopy(sourceQuads[i]));
- }
- return retArr;
- };
- cc.V2F_C4B_T2F = function (vertices, colors, texCoords, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset;
- this._vertices = vertices ? new cc.Vertex2F(vertices.x, vertices.y, locArrayBuffer, locOffset) :
- new cc.Vertex2F(0, 0, locArrayBuffer, locOffset);
- locOffset += cc.Vertex2F.BYTES_PER_ELEMENT;
- this._colors = colors ? cc.color(colors.r, colors.g, colors.b, colors.a, locArrayBuffer, locOffset) :
- cc.color(0, 0, 0, 0, locArrayBuffer, locOffset);
- locOffset += cc.Color.BYTES_PER_ELEMENT;
- this._texCoords = texCoords ? new cc.Tex2F(texCoords.u, texCoords.v, locArrayBuffer, locOffset) :
- new cc.Tex2F(0, 0, locArrayBuffer, locOffset);
- };
- cc.V2F_C4B_T2F.BYTES_PER_ELEMENT = 20;
- _p = cc.V2F_C4B_T2F.prototype;
- _p._getVertices = function () {
- return this._vertices;
- };
- _p._setVertices = function (verticesValue) {
- this._vertices._view[0] = verticesValue.x;
- this._vertices._view[1] = verticesValue.y;
- };
- _p._getColor = function () {
- return this._colors;
- };
- _p._setColor = function (colorValue) {
- var locColors = this._colors;
- locColors._view[0] = colorValue.r;
- locColors._view[1] = colorValue.g;
- locColors._view[2] = colorValue.b;
- locColors._view[3] = colorValue.a;
- };
- _p._getTexCoords = function () {
- return this._texCoords;
- };
- _p._setTexCoords = function (texValue) {
- this._texCoords._view[0] = texValue.u;
- this._texCoords._view[1] = texValue.v;
- };
- _p.vertices;
- cc.defineGetterSetter(_p, "vertices", _p._getVertices, _p._setVertices);
- _p.colors;
- cc.defineGetterSetter(_p, "colors", _p._getColor, _p._setColor);
- _p.texCoords;
- cc.defineGetterSetter(_p, "texCoords", _p._getTexCoords, _p._setTexCoords);
- cc.V2F_C4B_T2F_Triangle = function (a, b, c, arrayBuffer, offset) {
- this._arrayBuffer = arrayBuffer || new ArrayBuffer(cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT);
- this._offset = offset || 0;
- var locArrayBuffer = this._arrayBuffer, locOffset = this._offset, locElementLen = cc.V2F_C4B_T2F.BYTES_PER_ELEMENT;
- this._a = a ? new cc.V2F_C4B_T2F(a.vertices, a.colors, a.texCoords, locArrayBuffer, locOffset) :
- new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._b = b ? new cc.V2F_C4B_T2F(b.vertices, b.colors, b.texCoords, locArrayBuffer, locOffset) :
- new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- locOffset += locElementLen;
- this._c = c ? new cc.V2F_C4B_T2F(c.vertices, c.colors, c.texCoords, locArrayBuffer, locOffset) :
- new cc.V2F_C4B_T2F(null, null, null, locArrayBuffer, locOffset);
- };
- cc.V2F_C4B_T2F_Triangle.BYTES_PER_ELEMENT = 60;
- _p = cc.V2F_C4B_T2F_Triangle.prototype;
- _p._getA = function () {
- return this._a;
- };
- _p._setA = function (aValue) {
- var locA = this._a;
- locA.vertices = aValue.vertices;
- locA.colors = aValue.colors;
- locA.texCoords = aValue.texCoords;
- };
- _p._getB = function () {
- return this._b;
- };
- _p._setB = function (bValue) {
- var locB = this._b;
- locB.vertices = bValue.vertices;
- locB.colors = bValue.colors;
- locB.texCoords = bValue.texCoords;
- };
- _p._getC = function () {
- return this._c;
- };
- _p._setC = function (cValue) {
- var locC = this._c;
- locC.vertices = cValue.vertices;
- locC.colors = cValue.colors;
- locC.texCoords = cValue.texCoords;
- };
- _p.a;
- cc.defineGetterSetter(_p, "a", _p._getA, _p._setA);
- _p.b;
- cc.defineGetterSetter(_p, "b", _p._getB, _p._setB);
- _p.c;
- cc.defineGetterSetter(_p, "c", _p._getC, _p._setC);
- cc.vertex2 = function (x, y) {
- return new cc.Vertex2F(x, y);
- };
- cc.vertex3 = function (x, y, z) {
- return new cc.Vertex3F(x, y, z);
- };
- cc.tex2 = function (u, v) {
- return new cc.Tex2F(u, v);
- };
- cc.BlendFunc = function (src1, dst1) {
- this.src = src1;
- this.dst = dst1;
- };
- cc.blendFuncDisable = function () {
- return new cc.BlendFunc(cc.ONE, cc.ZERO);
- };
- cc.hexToColor = function (hex) {
- hex = hex.replace(/^#?/, "0x");
- var c = parseInt(hex);
- var r = c >> 16;
- var g = (c >> 8) % 256;
- var b = c % 256;
- return cc.color(r, g, b);
- };
- cc.colorToHex = function (color) {
- var hR = color.r.toString(16), hG = color.g.toString(16), hB = color.b.toString(16);
- return "#" + (color.r < 16 ? ("0" + hR) : hR) + (color.g < 16 ? ("0" + hG) : hG) + (color.b < 16 ? ("0" + hB) : hB);
- };
- cc.TEXT_ALIGNMENT_LEFT = 0;
- cc.TEXT_ALIGNMENT_CENTER = 1;
- cc.TEXT_ALIGNMENT_RIGHT = 2;
- cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0;
- cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1;
- cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2;
- cc._Dictionary = cc.Class.extend({
- _keyMapTb: null,
- _valueMapTb: null,
- __currId: 0,
- ctor: function () {
- this._keyMapTb = {};
- this._valueMapTb = {};
- this.__currId = 2 << (0 | (Math.random() * 10));
- },
- __getKey: function () {
- this.__currId++;
- return "key_" + this.__currId;
- },
- setObject: function (value, key) {
- if (key == null)
- return;
- var keyId = this.__getKey();
- this._keyMapTb[keyId] = key;
- this._valueMapTb[keyId] = value;
- },
- objectForKey: function (key) {
- if (key == null)
- return null;
- var locKeyMapTb = this._keyMapTb;
- for (var keyId in locKeyMapTb) {
- if (locKeyMapTb[keyId] === key)
- return this._valueMapTb[keyId];
- }
- return null;
- },
- valueForKey: function (key) {
- return this.objectForKey(key);
- },
- removeObjectForKey: function (key) {
- if (key == null)
- return;
- var locKeyMapTb = this._keyMapTb;
- for (var keyId in locKeyMapTb) {
- if (locKeyMapTb[keyId] === key) {
- delete this._valueMapTb[keyId];
- delete locKeyMapTb[keyId];
- return;
- }
- }
- },
- removeObjectsForKeys: function (keys) {
- if (keys == null)
- return;
- for (var i = 0; i < keys.length; i++)
- this.removeObjectForKey(keys[i]);
- },
- allKeys: function () {
- var keyArr = [], locKeyMapTb = this._keyMapTb;
- for (var key in locKeyMapTb)
- keyArr.push(locKeyMapTb[key]);
- return keyArr;
- },
- removeAllObjects: function () {
- this._keyMapTb = {};
- this._valueMapTb = {};
- },
- count: function () {
- return this.allKeys().length;
- }
- });
- cc.FontDefinition = function (properties) {
- var _t = this;
- _t.fontName = "Arial";
- _t.fontSize = 12;
- _t.textAlign = cc.TEXT_ALIGNMENT_CENTER;
- _t.verticalAlign = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
- _t.fillStyle = cc.color(255, 255, 255, 255);
- _t.boundingWidth = 0;
- _t.boundingHeight = 0;
- _t.strokeEnabled = false;
- _t.strokeStyle = cc.color(255, 255, 255, 255);
- _t.lineWidth = 1;
- _t.lineHeight = "normal";
- _t.fontStyle = "normal";
- _t.fontWeight = "normal";
- _t.shadowEnabled = false;
- _t.shadowOffsetX = 0;
- _t.shadowOffsetY = 0;
- _t.shadowBlur = 0;
- _t.shadowOpacity = 1.0;
- if(properties && properties instanceof Object){
- for(var key in properties){
- _t[key] = properties[key];
- }
- }
- };
- cc.FontDefinition.prototype._getCanvasFontStr = function(){
- var lineHeight = !this.lineHeight.charAt ? this.lineHeight+"px" : this.lineHeight;
- return this.fontStyle + " " + this.fontWeight + " " + this.fontSize + "px/"+lineHeight+" '" + this.fontName + "'";
- };
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- cc.assert(cc.isFunction(cc._tmp.PrototypeColor), cc._LogInfos.MissingFile, "CCTypesPropertyDefine.js");
- cc._tmp.PrototypeColor();
- delete cc._tmp.PrototypeColor;
- }
- });
- cc.Touches = [];
- cc.TouchesIntergerDict = {};
- cc.DENSITYDPI_DEVICE = "device-dpi";
- cc.DENSITYDPI_HIGH = "high-dpi";
- cc.DENSITYDPI_MEDIUM = "medium-dpi";
- cc.DENSITYDPI_LOW = "low-dpi";
- var __BrowserGetter = {
- init: function(){
- this.html = document.getElementsByTagName("html")[0];
- },
- availWidth: function(frame){
- if(!frame || frame === this.html)
- return window.innerWidth;
- else
- return frame.clientWidth;
- },
- availHeight: function(frame){
- if(!frame || frame === this.html)
- return window.innerHeight;
- else
- return frame.clientHeight;
- },
- meta: {
- "width": "device-width"
- },
- adaptationType: cc.sys.browserType
- };
- if(window.navigator.userAgent.indexOf("OS 8_1_") > -1)
- __BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_MIUI;
- if(cc.sys.os === cc.sys.OS_IOS)
- __BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_SAFARI;
- switch(__BrowserGetter.adaptationType){
- case cc.sys.BROWSER_TYPE_SAFARI:
- __BrowserGetter.meta["minimal-ui"] = "true";
- __BrowserGetter.availWidth = function(frame){
- return frame.clientWidth;
- };
- __BrowserGetter.availHeight = function(frame){
- return frame.clientHeight;
- };
- break;
- case cc.sys.BROWSER_TYPE_CHROME:
- __BrowserGetter.__defineGetter__("target-densitydpi", function(){
- return cc.view._targetDensityDPI;
- });
- case cc.sys.BROWSER_TYPE_SOUGOU:
- case cc.sys.BROWSER_TYPE_UC:
- __BrowserGetter.availWidth = function(frame){
- return frame.clientWidth;
- };
- __BrowserGetter.availHeight = function(frame){
- return frame.clientHeight;
- };
- break;
- case cc.sys.BROWSER_TYPE_MIUI:
- __BrowserGetter.init = function(view){
- if(view.__resizeWithBrowserSize) return;
- var resize = function(){
- view.setDesignResolutionSize(
- view._designResolutionSize.width,
- view._designResolutionSize.height,
- view._resolutionPolicy
- );
- window.removeEventListener("resize", resize, false);
- };
- window.addEventListener("resize", resize, false);
- };
- break;
- }
- var _scissorRect = cc.rect();
- cc.EGLView = cc.Class.extend({
- _delegate: null,
- _frameSize: null,
- _designResolutionSize: null,
- _originalDesignResolutionSize: null,
- _viewPortRect: null,
- _visibleRect: null,
- _retinaEnabled: false,
- _autoFullScreen: false,
- _devicePixelRatio: 1,
- _viewName: "",
- _resizeCallback: null,
- _scaleX: 1,
- _originalScaleX: 1,
- _scaleY: 1,
- _originalScaleY: 1,
- _isRotated: false,
- _orientation: 3,
- _resolutionPolicy: null,
- _rpExactFit: null,
- _rpShowAll: null,
- _rpNoBorder: null,
- _rpFixedHeight: null,
- _rpFixedWidth: null,
- _initialized: false,
- _contentTranslateLeftTop: null,
- _frame: null,
- _frameZoomFactor: 1.0,
- __resizeWithBrowserSize: false,
- _isAdjustViewPort: true,
- _targetDensityDPI: null,
- ctor: function () {
- var _t = this, d = document, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy;
- __BrowserGetter.init(this);
- _t._frame = (cc.container.parentNode === d.body) ? d.documentElement : cc.container.parentNode;
- _t._frameSize = cc.size(0, 0);
- _t._initFrameSize();
- var w = cc._canvas.width, h = cc._canvas.height;
- _t._designResolutionSize = cc.size(w, h);
- _t._originalDesignResolutionSize = cc.size(w, h);
- _t._viewPortRect = cc.rect(0, 0, w, h);
- _t._visibleRect = cc.rect(0, 0, w, h);
- _t._contentTranslateLeftTop = {left: 0, top: 0};
- _t._viewName = "Cocos2dHTML5";
- var sys = cc.sys;
- _t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX);
- _t.enableAutoFullScreen(sys.isMobile && sys.browserType !== sys.BROWSER_TYPE_BAIDU);
- cc.visibleRect && cc.visibleRect.init(_t._visibleRect);
- _t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT);
- _t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL);
- _t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER);
- _t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT);
- _t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH);
- _t._targetDensityDPI = cc.DENSITYDPI_HIGH;
- },
- _resizeEvent: function () {
- var view;
- if (this.setDesignResolutionSize) {
- view = this;
- } else {
- view = cc.view;
- }
- var prevFrameW = view._frameSize.width, prevFrameH = view._frameSize.height, prevRotated = view._isRotated;
- view._initFrameSize();
- if (view._isRotated === prevRotated && view._frameSize.width === prevFrameW && view._frameSize.height === prevFrameH)
- return;
- if (view._resizeCallback) {
- view._resizeCallback.call();
- }
- var width = view._originalDesignResolutionSize.width;
- var height = view._originalDesignResolutionSize.height;
- if (width > 0) {
- view.setDesignResolutionSize(width, height, view._resolutionPolicy);
- }
- },
- setTargetDensityDPI: function(densityDPI){
- this._targetDensityDPI = densityDPI;
- this._adjustViewportMeta();
- },
- getTargetDensityDPI: function(){
- return this._targetDensityDPI;
- },
- resizeWithBrowserSize: function (enabled) {
- if (enabled) {
- if (!this.__resizeWithBrowserSize) {
- this.__resizeWithBrowserSize = true;
- window.addEventListener('resize', this._resizeEvent);
- window.addEventListener('orientationchange', this._resizeEvent);
- }
- } else {
- if (this.__resizeWithBrowserSize) {
- this.__resizeWithBrowserSize = false;
- window.removeEventListener('resize', this._resizeEvent);
- window.removeEventListener('orientationchange', this._resizeEvent);
- }
- }
- },
- setResizeCallback: function (callback) {
- if (cc.isFunction(callback) || callback == null) {
- this._resizeCallback = callback;
- }
- },
- setOrientation: function (orientation) {
- orientation = orientation & cc.ORIENTATION_AUTO;
- if (orientation) {
- this._orientation = orientation;
- }
- },
- _initFrameSize: function () {
- var locFrameSize = this._frameSize;
- var w = __BrowserGetter.availWidth(this._frame);
- var h = __BrowserGetter.availHeight(this._frame);
- var isLandscape = w >= h;
- if (!cc.sys.isMobile ||
- (isLandscape && this._orientation & cc.ORIENTATION_LANDSCAPE) ||
- (!isLandscape && this._orientation & cc.ORIENTATION_PORTRAIT)) {
- locFrameSize.width = w;
- locFrameSize.height = h;
- cc.container.style['-webkit-transform'] = 'rotate(0deg)';
- cc.container.style.transform = 'rotate(0deg)';
- this._isRotated = false;
- }
- else {
- locFrameSize.width = h;
- locFrameSize.height = w;
- cc.container.style['-webkit-transform'] = 'rotate(90deg)';
- cc.container.style.transform = 'rotate(90deg)';
- cc.container.style['-webkit-transform-origin'] = '0px 0px 0px';
- cc.container.style.transformOrigin = '0px 0px 0px';
- this._isRotated = true;
- }
- },
- _adjustSizeKeepCanvasSize: function () {
- var designWidth = this._originalDesignResolutionSize.width;
- var designHeight = this._originalDesignResolutionSize.height;
- if (designWidth > 0)
- this.setDesignResolutionSize(designWidth, designHeight, this._resolutionPolicy);
- },
- _setViewportMeta: function (metas, overwrite) {
- var vp = document.getElementById("cocosMetaElement");
- if(vp && overwrite){
- document.head.removeChild(vp);
- }
- var elems = document.getElementsByName("viewport"),
- currentVP = elems ? elems[0] : null,
- content, key, pattern;
- content = currentVP ? currentVP.content : "";
- vp = vp || document.createElement("meta");
- vp.id = "cocosMetaElement";
- vp.name = "viewport";
- vp.content = "";
- for (key in metas) {
- if (content.indexOf(key) == -1) {
- content += "," + key + "=" + metas[key];
- }
- else if (overwrite) {
- pattern = new RegExp(key+"\s*=\s*[^,]+");
- content.replace(pattern, key + "=" + metas[key]);
- }
- }
- if(/^,/.test(content))
- content = content.substr(1);
- vp.content = content;
- if (currentVP)
- currentVP.content = content;
- document.head.appendChild(vp);
- },
- _adjustViewportMeta: function () {
- if (this._isAdjustViewPort) {
- this._setViewportMeta(__BrowserGetter.meta, false);
- this._isAdjustViewPort = false;
- }
- },
- _setScaleXYForRenderTexture: function () {
- var scaleFactor = cc.contentScaleFactor();
- this._scaleX = scaleFactor;
- this._scaleY = scaleFactor;
- },
- _resetScale: function () {
- this._scaleX = this._originalScaleX;
- this._scaleY = this._originalScaleY;
- },
- _adjustSizeToBrowser: function () {
- },
- initialize: function () {
- this._initialized = true;
- },
- adjustViewPort: function (enabled) {
- this._isAdjustViewPort = enabled;
- },
- enableRetina: function(enabled) {
- this._retinaEnabled = enabled ? true : false;
- },
- isRetinaEnabled: function() {
- return this._retinaEnabled;
- },
- enableAutoFullScreen: function(enabled) {
- if (enabled && enabled !== this._autoFullScreen && cc.sys.isMobile && this._frame === document.documentElement) {
- this._autoFullScreen = true;
- cc.screen.autoFullScreen(this._frame);
- }
- else {
- this._autoFullScreen = false;
- }
- },
- isAutoFullScreenEnabled: function() {
- return this._autoFullScreen;
- },
- end: function () {
- },
- isOpenGLReady: function () {
- return (cc.game.canvas && cc._renderContext);
- },
- setFrameZoomFactor: function (zoomFactor) {
- this._frameZoomFactor = zoomFactor;
- this.centerWindow();
- cc.director.setProjection(cc.director.getProjection());
- },
- swapBuffers: function () {
- },
- setIMEKeyboardState: function (isOpen) {
- },
- setContentTranslateLeftTop: function (offsetLeft, offsetTop) {
- this._contentTranslateLeftTop = {left: offsetLeft, top: offsetTop};
- },
- getContentTranslateLeftTop: function () {
- return this._contentTranslateLeftTop;
- },
- getCanvasSize: function () {
- return cc.size(cc._canvas.width, cc._canvas.height);
- },
- getFrameSize: function () {
- return cc.size(this._frameSize.width, this._frameSize.height);
- },
- setFrameSize: function (width, height) {
- this._frameSize.width = width;
- this._frameSize.height = height;
- this._frame.style.width = width + "px";
- this._frame.style.height = height + "px";
- this._resizeEvent();
- cc.director.setProjection(cc.director.getProjection());
- },
- centerWindow: function () {
- },
- getVisibleSize: function () {
- return cc.size(this._visibleRect.width,this._visibleRect.height);
- },
- getVisibleSizeInPixel: function () {
- return cc.size( this._visibleRect.width * this._scaleX,
- this._visibleRect.height * this._scaleY );
- },
- getVisibleOrigin: function () {
- return cc.p(this._visibleRect.x,this._visibleRect.y);
- },
- getVisibleOriginInPixel: function () {
- return cc.p(this._visibleRect.x * this._scaleX,
- this._visibleRect.y * this._scaleY);
- },
- canSetContentScaleFactor: function () {
- return true;
- },
- getResolutionPolicy: function () {
- return this._resolutionPolicy;
- },
- setResolutionPolicy: function (resolutionPolicy) {
- var _t = this;
- if (resolutionPolicy instanceof cc.ResolutionPolicy) {
- _t._resolutionPolicy = resolutionPolicy;
- }
- else {
- var _locPolicy = cc.ResolutionPolicy;
- if(resolutionPolicy === _locPolicy.EXACT_FIT)
- _t._resolutionPolicy = _t._rpExactFit;
- if(resolutionPolicy === _locPolicy.SHOW_ALL)
- _t._resolutionPolicy = _t._rpShowAll;
- if(resolutionPolicy === _locPolicy.NO_BORDER)
- _t._resolutionPolicy = _t._rpNoBorder;
- if(resolutionPolicy === _locPolicy.FIXED_HEIGHT)
- _t._resolutionPolicy = _t._rpFixedHeight;
- if(resolutionPolicy === _locPolicy.FIXED_WIDTH)
- _t._resolutionPolicy = _t._rpFixedWidth;
- }
- },
- setDesignResolutionSize: function (width, height, resolutionPolicy) {
- if( !(width > 0 || height > 0) ){
- cc.log(cc._LogInfos.EGLView_setDesignResolutionSize);
- return;
- }
- this.setResolutionPolicy(resolutionPolicy);
- var policy = this._resolutionPolicy;
- if (!policy){
- cc.log(cc._LogInfos.EGLView_setDesignResolutionSize_2);
- return;
- }
- policy.preApply(this);
- if(cc.sys.isMobile)
- this._adjustViewportMeta();
- this._initFrameSize();
- this._originalDesignResolutionSize.width = this._designResolutionSize.width = width;
- this._originalDesignResolutionSize.height = this._designResolutionSize.height = height;
- var result = policy.apply(this, this._designResolutionSize);
- if(result.scale && result.scale.length === 2){
- this._scaleX = result.scale[0];
- this._scaleY = result.scale[1];
- }
- if(result.viewport){
- var vp = this._viewPortRect,
- vb = this._visibleRect,
- rv = result.viewport;
- vp.x = rv.x;
- vp.y = rv.y;
- vp.width = rv.width;
- vp.height = rv.height;
- vb.x = -vp.x / this._scaleX;
- vb.y = -vp.y / this._scaleY;
- vb.width = cc._canvas.width / this._scaleX;
- vb.height = cc._canvas.height / this._scaleY;
- cc._renderContext.setOffset && cc._renderContext.setOffset(vp.x, -vp.y);
- }
- var director = cc.director;
- director._winSizeInPoints.width = this._designResolutionSize.width;
- director._winSizeInPoints.height = this._designResolutionSize.height;
- policy.postApply(this);
- cc.winSize.width = director._winSizeInPoints.width;
- cc.winSize.height = director._winSizeInPoints.height;
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
- director.setGLDefaultValues();
- }
- this._originalScaleX = this._scaleX;
- this._originalScaleY = this._scaleY;
- if (cc.DOM)
- cc.DOM._resetEGLViewDiv();
- cc.visibleRect && cc.visibleRect.init(this._visibleRect);
- },
- getDesignResolutionSize: function () {
- return cc.size(this._designResolutionSize.width, this._designResolutionSize.height);
- },
- setRealPixelResolution: function (width, height, resolutionPolicy) {
- this._setViewportMeta({"width": width, "target-densitydpi": cc.DENSITYDPI_DEVICE}, true);
- document.body.style.width = width + "px";
- document.body.style.left = "0px";
- document.body.style.top = "0px";
- this.setDesignResolutionSize(width, height, resolutionPolicy);
- },
- setViewPortInPoints: function (x, y, w, h) {
- var locFrameZoomFactor = this._frameZoomFactor, locScaleX = this._scaleX, locScaleY = this._scaleY;
- cc._renderContext.viewport((x * locScaleX * locFrameZoomFactor + this._viewPortRect.x * locFrameZoomFactor),
- (y * locScaleY * locFrameZoomFactor + this._viewPortRect.y * locFrameZoomFactor),
- (w * locScaleX * locFrameZoomFactor),
- (h * locScaleY * locFrameZoomFactor));
- },
- setScissorInPoints: function (x, y, w, h) {
- var zoomFactor = this._frameZoomFactor, scaleX = this._scaleX, scaleY = this._scaleY;
- _scissorRect.x = x;
- _scissorRect.y = y;
- _scissorRect.width = w;
- _scissorRect.height = h;
- cc._renderContext.scissor(x * scaleX * zoomFactor + this._viewPortRect.x * zoomFactor,
- y * scaleY * zoomFactor + this._viewPortRect.y * zoomFactor,
- w * scaleX * zoomFactor,
- h * scaleY * zoomFactor);
- },
- isScissorEnabled: function () {
- return cc._renderContext.isEnabled(gl.SCISSOR_TEST);
- },
- getScissorRect: function () {
- return cc.rect(_scissorRect);
- },
- setViewName: function (viewName) {
- if (viewName != null && viewName.length > 0) {
- this._viewName = viewName;
- }
- },
- getViewName: function () {
- return this._viewName;
- },
- getViewPortRect: function () {
- return this._viewPortRect;
- },
- getScaleX: function () {
- return this._scaleX;
- },
- getScaleY: function () {
- return this._scaleY;
- },
- getDevicePixelRatio: function() {
- return this._devicePixelRatio;
- },
- convertToLocationInView: function (tx, ty, relatedPos) {
- var x = this._devicePixelRatio * (tx - relatedPos.left);
- var y = this._devicePixelRatio * (relatedPos.top + relatedPos.height - ty);
- return this._isRotated ? {x: this._viewPortRect.width - y, y: x} : {x: x, y: y};
- },
- _convertMouseToLocationInView: function(point, relatedPos) {
- var locViewPortRect = this._viewPortRect, _t = this;
- point.x = ((_t._devicePixelRatio * (point.x - relatedPos.left)) - locViewPortRect.x) / _t._scaleX;
- point.y = (_t._devicePixelRatio * (relatedPos.top + relatedPos.height - point.y) - locViewPortRect.y) / _t._scaleY;
- },
- _convertPointWithScale: function (point) {
- var viewport = this._viewPortRect;
- point.x = (point.x - viewport.x) / this._scaleX;
- point.y = (point.y - viewport.y) / this._scaleY;
- },
- _convertTouchesWithScale: function (touches) {
- var viewport = this._viewPortRect, scaleX = this._scaleX, scaleY = this._scaleY,
- selTouch, selPoint, selPrePoint;
- for( var i = 0; i < touches.length; i++){
- selTouch = touches[i];
- selPoint = selTouch._point;
- selPrePoint = selTouch._prevPoint;
- selPoint.x = (selPoint.x - viewport.x) / scaleX;
- selPoint.y = (selPoint.y - viewport.y) / scaleY;
- selPrePoint.x = (selPrePoint.x - viewport.x) / scaleX;
- selPrePoint.y = (selPrePoint.y - viewport.y) / scaleY;
- }
- }
- });
- cc.EGLView._getInstance = function () {
- if (!this._instance) {
- this._instance = this._instance || new cc.EGLView();
- this._instance.initialize();
- }
- return this._instance;
- };
- cc.ContainerStrategy = cc.Class.extend({
- preApply: function (view) {
- },
- apply: function (view, designedResolution) {
- },
- postApply: function (view) {
- },
- _setupContainer: function (view, w, h) {
- var locCanvas = cc.game.canvas, locContainer = cc.game.container;
- locContainer.style.width = locCanvas.style.width = w + 'px';
- locContainer.style.height = locCanvas.style.height = h + 'px';
- var devicePixelRatio = view._devicePixelRatio = 1;
- if (view.isRetinaEnabled())
- devicePixelRatio = view._devicePixelRatio = Math.min(2, window.devicePixelRatio || 1);
- locCanvas.width = w * devicePixelRatio;
- locCanvas.height = h * devicePixelRatio;
- cc._renderContext.resetCache && cc._renderContext.resetCache();
- },
- _fixContainer: function () {
- document.body.insertBefore(cc.container, document.body.firstChild);
- var bs = document.body.style;
- bs.width = window.innerWidth + "px";
- bs.height = window.innerHeight + "px";
- bs.overflow = "hidden";
- var contStyle = cc.container.style;
- contStyle.position = "fixed";
- contStyle.left = contStyle.top = "0px";
- document.body.scrollTop = 0;
- }
- });
- cc.ContentStrategy = cc.Class.extend({
- _result: {
- scale: [1, 1],
- viewport: null
- },
- _buildResult: function (containerW, containerH, contentW, contentH, scaleX, scaleY) {
- Math.abs(containerW - contentW) < 2 && (contentW = containerW);
- Math.abs(containerH - contentH) < 2 && (contentH = containerH);
- var viewport = cc.rect(Math.round((containerW - contentW) / 2),
- Math.round((containerH - contentH) / 2),
- contentW, contentH);
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS){
- }
- this._result.scale = [scaleX, scaleY];
- this._result.viewport = viewport;
- return this._result;
- },
- preApply: function (view) {
- },
- apply: function (view, designedResolution) {
- return {"scale": [1, 1]};
- },
- postApply: function (view) {
- }
- });
- (function () {
- var EqualToFrame = cc.ContainerStrategy.extend({
- apply: function (view) {
- var frameH = view._frameSize.height, containerStyle = cc.container.style;
- this._setupContainer(view, view._frameSize.width, view._frameSize.height);
- if (view._isRotated) {
- containerStyle.marginLeft = frameH + 'px';
- }
- else {
- containerStyle.margin = '0px';
- }
- }
- });
- var ProportionalToFrame = cc.ContainerStrategy.extend({
- apply: function (view, designedResolution) {
- var frameW = view._frameSize.width, frameH = view._frameSize.height, containerStyle = cc.container.style,
- designW = designedResolution.width, designH = designedResolution.height,
- scaleX = frameW / designW, scaleY = frameH / designH,
- containerW, containerH;
- scaleX < scaleY ? (containerW = frameW, containerH = designH * scaleX) : (containerW = designW * scaleY, containerH = frameH);
- var offx = Math.round((frameW - containerW) / 2);
- var offy = Math.round((frameH - containerH) / 2);
- containerW = frameW - 2 * offx;
- containerH = frameH - 2 * offy;
- this._setupContainer(view, containerW, containerH);
- if (view._isRotated) {
- containerStyle.marginLeft = frameH + 'px';
- }
- else {
- containerStyle.margin = '0px';
- }
- containerStyle.paddingLeft = offx + "px";
- containerStyle.paddingRight = offx + "px";
- containerStyle.paddingTop = offy + "px";
- containerStyle.paddingBottom = offy + "px";
- }
- });
- var EqualToWindow = EqualToFrame.extend({
- preApply: function (view) {
- this._super(view);
- view._frame = document.documentElement;
- },
- apply: function (view) {
- this._super(view);
- this._fixContainer();
- }
- });
- var ProportionalToWindow = ProportionalToFrame.extend({
- preApply: function (view) {
- this._super(view);
- view._frame = document.documentElement;
- },
- apply: function (view, designedResolution) {
- this._super(view, designedResolution);
- this._fixContainer();
- }
- });
- var OriginalContainer = cc.ContainerStrategy.extend({
- apply: function (view) {
- this._setupContainer(view, cc._canvas.width, cc._canvas.height);
- }
- });
- cc.ContainerStrategy.EQUAL_TO_FRAME = new EqualToFrame();
- cc.ContainerStrategy.PROPORTION_TO_FRAME = new ProportionalToFrame();
- cc.ContainerStrategy.ORIGINAL_CONTAINER = new OriginalContainer();
- var ExactFit = cc.ContentStrategy.extend({
- apply: function (view, designedResolution) {
- var containerW = cc._canvas.width, containerH = cc._canvas.height,
- scaleX = containerW / designedResolution.width, scaleY = containerH / designedResolution.height;
- return this._buildResult(containerW, containerH, containerW, containerH, scaleX, scaleY);
- }
- });
- var ShowAll = cc.ContentStrategy.extend({
- apply: function (view, designedResolution) {
- var containerW = cc._canvas.width, containerH = cc._canvas.height,
- designW = designedResolution.width, designH = designedResolution.height,
- scaleX = containerW / designW, scaleY = containerH / designH, scale = 0,
- contentW, contentH;
- scaleX < scaleY ? (scale = scaleX, contentW = containerW, contentH = designH * scale)
- : (scale = scaleY, contentW = designW * scale, contentH = containerH);
- return this._buildResult(containerW, containerH, contentW, contentH, scale, scale);
- }
- });
- var NoBorder = cc.ContentStrategy.extend({
- apply: function (view, designedResolution) {
- var containerW = cc._canvas.width, containerH = cc._canvas.height,
- designW = designedResolution.width, designH = designedResolution.height,
- scaleX = containerW / designW, scaleY = containerH / designH, scale,
- contentW, contentH;
- scaleX < scaleY ? (scale = scaleY, contentW = designW * scale, contentH = containerH)
- : (scale = scaleX, contentW = containerW, contentH = designH * scale);
- return this._buildResult(containerW, containerH, contentW, contentH, scale, scale);
- }
- });
- var FixedHeight = cc.ContentStrategy.extend({
- apply: function (view, designedResolution) {
- var containerW = cc._canvas.width, containerH = cc._canvas.height,
- designH = designedResolution.height, scale = containerH / designH,
- contentW = containerW, contentH = containerH;
- return this._buildResult(containerW, containerH, contentW, contentH, scale, scale);
- },
- postApply: function (view) {
- cc.director._winSizeInPoints = view.getVisibleSize();
- }
- });
- var FixedWidth = cc.ContentStrategy.extend({
- apply: function (view, designedResolution) {
- var containerW = cc._canvas.width, containerH = cc._canvas.height,
- designW = designedResolution.width, scale = containerW / designW,
- contentW = containerW, contentH = containerH;
- return this._buildResult(containerW, containerH, contentW, contentH, scale, scale);
- },
- postApply: function (view) {
- cc.director._winSizeInPoints = view.getVisibleSize();
- }
- });
- cc.ContentStrategy.EXACT_FIT = new ExactFit();
- cc.ContentStrategy.SHOW_ALL = new ShowAll();
- cc.ContentStrategy.NO_BORDER = new NoBorder();
- cc.ContentStrategy.FIXED_HEIGHT = new FixedHeight();
- cc.ContentStrategy.FIXED_WIDTH = new FixedWidth();
- })();
- cc.ResolutionPolicy = cc.Class.extend({
- _containerStrategy: null,
- _contentStrategy: null,
- ctor: function (containerStg, contentStg) {
- this.setContainerStrategy(containerStg);
- this.setContentStrategy(contentStg);
- },
- preApply: function (view) {
- this._containerStrategy.preApply(view);
- this._contentStrategy.preApply(view);
- },
- apply: function (view, designedResolution) {
- this._containerStrategy.apply(view, designedResolution);
- return this._contentStrategy.apply(view, designedResolution);
- },
- postApply: function (view) {
- this._containerStrategy.postApply(view);
- this._contentStrategy.postApply(view);
- },
- setContainerStrategy: function (containerStg) {
- if (containerStg instanceof cc.ContainerStrategy)
- this._containerStrategy = containerStg;
- },
- setContentStrategy: function (contentStg) {
- if (contentStg instanceof cc.ContentStrategy)
- this._contentStrategy = contentStg;
- }
- });
- cc.ResolutionPolicy.EXACT_FIT = 0;
- cc.ResolutionPolicy.NO_BORDER = 1;
- cc.ResolutionPolicy.SHOW_ALL = 2;
- cc.ResolutionPolicy.FIXED_HEIGHT = 3;
- cc.ResolutionPolicy.FIXED_WIDTH = 4;
- cc.ResolutionPolicy.UNKNOWN = 5;
- cc.screen = {
- _supportsFullScreen: false,
- _preOnFullScreenChange: null,
- _touchEvent: "",
- _fn: null,
- _fnMap: [
- [
- 'requestFullscreen',
- 'exitFullscreen',
- 'fullscreenchange',
- 'fullscreenEnabled',
- 'fullscreenElement'
- ],
- [
- 'requestFullScreen',
- 'exitFullScreen',
- 'fullScreenchange',
- 'fullScreenEnabled',
- 'fullScreenElement'
- ],
- [
- 'webkitRequestFullScreen',
- 'webkitCancelFullScreen',
- 'webkitfullscreenchange',
- 'webkitIsFullScreen',
- 'webkitCurrentFullScreenElement'
- ],
- [
- 'mozRequestFullScreen',
- 'mozCancelFullScreen',
- 'mozfullscreenchange',
- 'mozFullScreen',
- 'mozFullScreenElement'
- ],
- [
- 'msRequestFullscreen',
- 'msExitFullscreen',
- 'MSFullscreenChange',
- 'msFullscreenEnabled',
- 'msFullscreenElement'
- ]
- ],
- init: function () {
- this._fn = {};
- var i, val, map = this._fnMap, valL;
- for (i = 0, l = map.length; i < l; i++) {
- val = map[i];
- if (val && val[1] in document) {
- for (i = 0, valL = val.length; i < valL; i++) {
- this._fn[map[0][i]] = val[i];
- }
- break;
- }
- }
- this._supportsFullScreen = (typeof this._fn.requestFullscreen !== 'undefined');
- this._touchEvent = ('ontouchstart' in window) ? 'touchstart' : 'mousedown';
- },
- fullScreen: function () {
- if(!this._supportsFullScreen) return false;
- else if( document[this._fn.fullscreenElement] === undefined || document[this._fn.fullscreenElement] === null )
- return false;
- else
- return true;
- },
- requestFullScreen: function (element, onFullScreenChange) {
- if (!this._supportsFullScreen) {
- return;
- }
- element = element || document.documentElement;
- if (onFullScreenChange) {
- var eventName = this._fn.fullscreenchange;
- if (this._preOnFullScreenChange) {
- document.removeEventListener(eventName, this._preOnFullScreenChange);
- }
- this._preOnFullScreenChange = onFullScreenChange;
- document.addEventListener(eventName, onFullScreenChange, false);
- }
- return element[this._fn.requestFullscreen]();
- },
- exitFullScreen: function () {
- return this._supportsFullScreen ? document[this._fn.exitFullscreen]() : true;
- },
- autoFullScreen: function (element, onFullScreenChange) {
- element = element || document.body;
- var touchTarget = cc.game.canvas || element;
- var theScreen = this;
- function callback() {
- touchTarget.removeEventListener(theScreen._touchEvent, callback);
- theScreen.requestFullScreen(element, onFullScreenChange);
- }
- this.requestFullScreen(element, onFullScreenChange);
- touchTarget.addEventListener(this._touchEvent, callback);
- }
- };
- cc.screen.init();
- cc.visibleRect = {
- topLeft:cc.p(0,0),
- topRight:cc.p(0,0),
- top:cc.p(0,0),
- bottomLeft:cc.p(0,0),
- bottomRight:cc.p(0,0),
- bottom:cc.p(0,0),
- center:cc.p(0,0),
- left:cc.p(0,0),
- right:cc.p(0,0),
- width:0,
- height:0,
- init:function(visibleRect){
- var w = this.width = visibleRect.width;
- var h = this.height = visibleRect.height;
- var l = visibleRect.x,
- b = visibleRect.y,
- t = b + h,
- r = l + w;
- this.topLeft.x = l;
- this.topLeft.y = t;
- this.topRight.x = r;
- this.topRight.y = t;
- this.top.x = l + w/2;
- this.top.y = t;
- this.bottomLeft.x = l;
- this.bottomLeft.y = b;
- this.bottomRight.x = r;
- this.bottomRight.y = b;
- this.bottom.x = l + w/2;
- this.bottom.y = b;
- this.center.x = l + w/2;
- this.center.y = b + h/2;
- this.left.x = l;
- this.left.y = b + h/2;
- this.right.x = r;
- this.right.y = b + h/2;
- }
- };
- cc.UIInterfaceOrientationLandscapeLeft = -90;
- cc.UIInterfaceOrientationLandscapeRight = 90;
- cc.UIInterfaceOrientationPortraitUpsideDown = 180;
- cc.UIInterfaceOrientationPortrait = 0;
- cc.inputManager = {
- _mousePressed: false,
- _isRegisterEvent: false,
- _preTouchPoint: cc.p(0,0),
- _prevMousePoint: cc.p(0,0),
- _preTouchPool: [],
- _preTouchPoolPointer: 0,
- _touches: [],
- _touchesIntegerDict:{},
- _indexBitsUsed: 0,
- _maxTouches: 5,
- _accelEnabled: false,
- _accelInterval: 1/30,
- _accelMinus: 1,
- _accelCurTime: 0,
- _acceleration: null,
- _accelDeviceEvent: null,
- _getUnUsedIndex: function () {
- var temp = this._indexBitsUsed;
- for (var i = 0; i < this._maxTouches; i++) {
- if (!(temp & 0x00000001)) {
- this._indexBitsUsed |= (1 << i);
- return i;
- }
- temp >>= 1;
- }
- return -1;
- },
- _removeUsedIndexBit: function (index) {
- if (index < 0 || index >= this._maxTouches)
- return;
- var temp = 1 << index;
- temp = ~temp;
- this._indexBitsUsed &= temp;
- },
- _glView: null,
- handleTouchesBegin: function (touches) {
- var selTouch, index, curTouch, touchID, handleTouches = [], locTouchIntDict = this._touchesIntegerDict;
- for(var i = 0, len = touches.length; i< len; i ++){
- selTouch = touches[i];
- touchID = selTouch.getID();
- index = locTouchIntDict[touchID];
- if(index == null){
- var unusedIndex = this._getUnUsedIndex();
- if (unusedIndex === -1) {
- cc.log(cc._LogInfos.inputManager_handleTouchesBegin, unusedIndex);
- continue;
- }
- curTouch = this._touches[unusedIndex] = new cc.Touch(selTouch._point.x, selTouch._point.y, selTouch.getID());
- curTouch._setPrevPoint(selTouch._prevPoint);
- locTouchIntDict[touchID] = unusedIndex;
- handleTouches.push(curTouch);
- }
- }
- if(handleTouches.length > 0){
- this._glView._convertTouchesWithScale(handleTouches);
- var touchEvent = new cc.EventTouch(handleTouches);
- touchEvent._eventCode = cc.EventTouch.EventCode.BEGAN;
- cc.eventManager.dispatchEvent(touchEvent);
- }
- },
- handleTouchesMove: function(touches){
- var selTouch, index, touchID, handleTouches = [], locTouches = this._touches;
- for(var i = 0, len = touches.length; i< len; i ++){
- selTouch = touches[i];
- touchID = selTouch.getID();
- index = this._touchesIntegerDict[touchID];
- if(index == null){
- continue;
- }
- if(locTouches[index]){
- locTouches[index]._setPoint(selTouch._point);
- locTouches[index]._setPrevPoint(selTouch._prevPoint);
- handleTouches.push(locTouches[index]);
- }
- }
- if(handleTouches.length > 0){
- this._glView._convertTouchesWithScale(handleTouches);
- var touchEvent = new cc.EventTouch(handleTouches);
- touchEvent._eventCode = cc.EventTouch.EventCode.MOVED;
- cc.eventManager.dispatchEvent(touchEvent);
- }
- },
- handleTouchesEnd: function(touches){
- var handleTouches = this.getSetOfTouchesEndOrCancel(touches);
- if(handleTouches.length > 0) {
- this._glView._convertTouchesWithScale(handleTouches);
- var touchEvent = new cc.EventTouch(handleTouches);
- touchEvent._eventCode = cc.EventTouch.EventCode.ENDED;
- cc.eventManager.dispatchEvent(touchEvent);
- }
- },
- handleTouchesCancel: function(touches){
- var handleTouches = this.getSetOfTouchesEndOrCancel(touches);
- if(handleTouches.length > 0) {
- this._glView._convertTouchesWithScale(handleTouches);
- var touchEvent = new cc.EventTouch(handleTouches);
- touchEvent._eventCode = cc.EventTouch.EventCode.CANCELLED;
- cc.eventManager.dispatchEvent(touchEvent);
- }
- },
- getSetOfTouchesEndOrCancel: function(touches) {
- var selTouch, index, touchID, handleTouches = [], locTouches = this._touches, locTouchesIntDict = this._touchesIntegerDict;
- for(var i = 0, len = touches.length; i< len; i ++){
- selTouch = touches[i];
- touchID = selTouch.getID();
- index = locTouchesIntDict[touchID];
- if(index == null){
- continue;
- }
- if(locTouches[index]){
- locTouches[index]._setPoint(selTouch._point);
- locTouches[index]._setPrevPoint(selTouch._prevPoint);
- handleTouches.push(locTouches[index]);
- this._removeUsedIndexBit(index);
- delete locTouchesIntDict[touchID];
- }
- }
- return handleTouches;
- },
- getHTMLElementPosition: function (element) {
- var docElem = document.documentElement;
- var win = window;
- var box = null;
- if (cc.isFunction(element.getBoundingClientRect)) {
- box = element.getBoundingClientRect();
- } else {
- box = {
- left: 0,
- top: 0,
- width: parseInt(element.style.width),
- height: parseInt(element.style.height)
- };
- }
- return {
- left: box.left + win.pageXOffset - docElem.clientLeft,
- top: box.top + win.pageYOffset - docElem.clientTop,
- width: box.width,
- height: box.height
- };
- },
- getPreTouch: function(touch){
- var preTouch = null;
- var locPreTouchPool = this._preTouchPool;
- var id = touch.getID();
- for (var i = locPreTouchPool.length - 1; i >= 0; i--) {
- if (locPreTouchPool[i].getID() === id) {
- preTouch = locPreTouchPool[i];
- break;
- }
- }
- if (!preTouch)
- preTouch = touch;
- return preTouch;
- },
- setPreTouch: function(touch){
- var find = false;
- var locPreTouchPool = this._preTouchPool;
- var id = touch.getID();
- for (var i = locPreTouchPool.length - 1; i >= 0; i--) {
- if (locPreTouchPool[i].getID() === id) {
- locPreTouchPool[i] = touch;
- find = true;
- break;
- }
- }
- if (!find) {
- if (locPreTouchPool.length <= 50) {
- locPreTouchPool.push(touch);
- } else {
- locPreTouchPool[this._preTouchPoolPointer] = touch;
- this._preTouchPoolPointer = (this._preTouchPoolPointer + 1) % 50;
- }
- }
- },
- getTouchByXY: function(tx, ty, pos){
- var locPreTouch = this._preTouchPoint;
- var location = this._glView.convertToLocationInView(tx, ty, pos);
- var touch = new cc.Touch(location.x, location.y);
- touch._setPrevPoint(locPreTouch.x, locPreTouch.y);
- locPreTouch.x = location.x;
- locPreTouch.y = location.y;
- return touch;
- },
- getMouseEvent: function(location, pos, eventType){
- var locPreMouse = this._prevMousePoint;
- this._glView._convertMouseToLocationInView(location, pos);
- var mouseEvent = new cc.EventMouse(eventType);
- mouseEvent.setLocation(location.x, location.y);
- mouseEvent._setPrevCursor(locPreMouse.x, locPreMouse.y);
- locPreMouse.x = location.x;
- locPreMouse.y = location.y;
- return mouseEvent;
- },
- getPointByEvent: function(event, pos){
- if (event.pageX != null)
- return {x: event.pageX, y: event.pageY};
- pos.left -= document.body.scrollLeft;
- pos.top -= document.body.scrollTop;
- return {x: event.clientX, y: event.clientY};
- },
- getTouchesByEvent: function(event, pos){
- var touchArr = [], locView = this._glView;
- var touch_event, touch, preLocation;
- var locPreTouch = this._preTouchPoint;
- var length = event.changedTouches.length;
- for (var i = 0; i < length; i++) {
- touch_event = event.changedTouches[i];
- if (touch_event) {
- var location;
- if (cc.sys.BROWSER_TYPE_FIREFOX === cc.sys.browserType)
- location = locView.convertToLocationInView(touch_event.pageX, touch_event.pageY, pos);
- else
- location = locView.convertToLocationInView(touch_event.clientX, touch_event.clientY, pos);
- if (touch_event.identifier != null) {
- touch = new cc.Touch(location.x, location.y, touch_event.identifier);
- preLocation = this.getPreTouch(touch).getLocation();
- touch._setPrevPoint(preLocation.x, preLocation.y);
- this.setPreTouch(touch);
- } else {
- touch = new cc.Touch(location.x, location.y);
- touch._setPrevPoint(locPreTouch.x, locPreTouch.y);
- }
- locPreTouch.x = location.x;
- locPreTouch.y = location.y;
- touchArr.push(touch);
- }
- }
- return touchArr;
- },
- registerSystemEvent: function(element){
- if(this._isRegisterEvent) return;
- var locView = this._glView = cc.view;
- var selfPointer = this;
- var supportMouse = ('mouse' in cc.sys.capabilities), supportTouches = ('touches' in cc.sys.capabilities);
- var prohibition = false;
- if( cc.sys.isMobile)
- prohibition = true;
- if (supportMouse) {
- window.addEventListener('mousedown', function () {
- selfPointer._mousePressed = true;
- }, false);
- window.addEventListener('mouseup', function (event) {
- if(prohibition) return;
- var savePressed = selfPointer._mousePressed;
- selfPointer._mousePressed = false;
- if(!savePressed)
- return;
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- if (!cc.rectContainsPoint(new cc.Rect(pos.left, pos.top, pos.width, pos.height), location)){
- selfPointer.handleTouchesEnd([selfPointer.getTouchByXY(location.x, location.y, pos)]);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.UP);
- mouseEvent.setButton(event.button);
- cc.eventManager.dispatchEvent(mouseEvent);
- }
- }, false);
- element.addEventListener("mousedown", function (event) {
- if(prohibition) return;
- selfPointer._mousePressed = true;
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- selfPointer.handleTouchesBegin([selfPointer.getTouchByXY(location.x, location.y, pos)]);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.DOWN);
- mouseEvent.setButton(event.button);
- cc.eventManager.dispatchEvent(mouseEvent);
- event.stopPropagation();
- event.preventDefault();
- element.focus();
- }, false);
- element.addEventListener("mouseup", function (event) {
- if(prohibition) return;
- selfPointer._mousePressed = false;
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- selfPointer.handleTouchesEnd([selfPointer.getTouchByXY(location.x, location.y, pos)]);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.UP);
- mouseEvent.setButton(event.button);
- cc.eventManager.dispatchEvent(mouseEvent);
- event.stopPropagation();
- event.preventDefault();
- }, false);
- element.addEventListener("mousemove", function (event) {
- if(prohibition) return;
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- selfPointer.handleTouchesMove([selfPointer.getTouchByXY(location.x, location.y, pos)]);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.MOVE);
- if(selfPointer._mousePressed)
- mouseEvent.setButton(event.button);
- else
- mouseEvent.setButton(null);
- cc.eventManager.dispatchEvent(mouseEvent);
- event.stopPropagation();
- event.preventDefault();
- }, false);
- element.addEventListener("mousewheel", function (event) {
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.SCROLL);
- mouseEvent.setButton(event.button);
- mouseEvent.setScrollData(0, event.wheelDelta);
- cc.eventManager.dispatchEvent(mouseEvent);
- event.stopPropagation();
- event.preventDefault();
- }, false);
- element.addEventListener("DOMMouseScroll", function(event) {
- var pos = selfPointer.getHTMLElementPosition(element);
- var location = selfPointer.getPointByEvent(event, pos);
- var mouseEvent = selfPointer.getMouseEvent(location,pos,cc.EventMouse.SCROLL);
- mouseEvent.setButton(event.button);
- mouseEvent.setScrollData(0, event.detail * -120);
- cc.eventManager.dispatchEvent(mouseEvent);
- event.stopPropagation();
- event.preventDefault();
- }, false);
- }
- if(window.navigator.msPointerEnabled){
- var _pointerEventsMap = {
- "MSPointerDown" : selfPointer.handleTouchesBegin,
- "MSPointerMove" : selfPointer.handleTouchesMove,
- "MSPointerUp" : selfPointer.handleTouchesEnd,
- "MSPointerCancel" : selfPointer.handleTouchesCancel
- };
- for(var eventName in _pointerEventsMap){
- (function(_pointerEvent, _touchEvent){
- element.addEventListener(_pointerEvent, function (event){
- var pos = selfPointer.getHTMLElementPosition(element);
- pos.left -= document.documentElement.scrollLeft;
- pos.top -= document.documentElement.scrollTop;
- _touchEvent.call(selfPointer, [selfPointer.getTouchByXY(event.clientX, event.clientY, pos)]);
- event.stopPropagation();
- }, false);
- })(eventName, _pointerEventsMap[eventName]);
- }
- }
- if(supportTouches) {
- element.addEventListener("touchstart", function (event) {
- if (!event.changedTouches) return;
- var pos = selfPointer.getHTMLElementPosition(element);
- pos.left -= document.body.scrollLeft;
- pos.top -= document.body.scrollTop;
- selfPointer.handleTouchesBegin(selfPointer.getTouchesByEvent(event, pos));
- event.stopPropagation();
- event.preventDefault();
- element.focus();
- }, false);
- element.addEventListener("touchmove", function (event) {
- if (!event.changedTouches) return;
- var pos = selfPointer.getHTMLElementPosition(element);
- pos.left -= document.body.scrollLeft;
- pos.top -= document.body.scrollTop;
- selfPointer.handleTouchesMove(selfPointer.getTouchesByEvent(event, pos));
- event.stopPropagation();
- event.preventDefault();
- }, false);
- element.addEventListener("touchend", function (event) {
- if (!event.changedTouches) return;
- var pos = selfPointer.getHTMLElementPosition(element);
- pos.left -= document.body.scrollLeft;
- pos.top -= document.body.scrollTop;
- selfPointer.handleTouchesEnd(selfPointer.getTouchesByEvent(event, pos));
- event.stopPropagation();
- event.preventDefault();
- }, false);
- element.addEventListener("touchcancel", function (event) {
- if (!event.changedTouches) return;
- var pos = selfPointer.getHTMLElementPosition(element);
- pos.left -= document.body.scrollLeft;
- pos.top -= document.body.scrollTop;
- selfPointer.handleTouchesCancel(selfPointer.getTouchesByEvent(event, pos));
- event.stopPropagation();
- event.preventDefault();
- }, false);
- }
- this._registerKeyboardEvent();
- this._registerAccelerometerEvent();
- this._isRegisterEvent = true;
- },
- _registerKeyboardEvent: function(){},
- _registerAccelerometerEvent: function(){},
- update:function(dt){
- if(this._accelCurTime > this._accelInterval){
- this._accelCurTime -= this._accelInterval;
- cc.eventManager.dispatchEvent(new cc.EventAcceleration(this._acceleration));
- }
- this._accelCurTime += dt;
- }
- };
- cc.AffineTransform = function (a, b, c, d, tx, ty) {
- this.a = a;
- this.b = b;
- this.c = c;
- this.d = d;
- this.tx = tx;
- this.ty = ty;
- };
- cc.affineTransformMake = function (a, b, c, d, tx, ty) {
- return {a: a, b: b, c: c, d: d, tx: tx, ty: ty};
- };
- cc.pointApplyAffineTransform = function (point, transOrY, t) {
- var x, y;
- if (t === undefined) {
- t = transOrY;
- x = point.x;
- y = point.y;
- } else {
- x = point;
- y = transOrY;
- }
- return {x: t.a * x + t.c * y + t.tx, y: t.b * x + t.d * y + t.ty};
- };
- cc._pointApplyAffineTransform = function (x, y, t) {
- return cc.pointApplyAffineTransform(x, y, t);
- };
- cc.sizeApplyAffineTransform = function (size, t) {
- return {width: t.a * size.width + t.c * size.height, height: t.b * size.width + t.d * size.height};
- };
- cc.affineTransformMakeIdentity = function () {
- return {a: 1.0, b: 0.0, c: 0.0, d: 1.0, tx: 0.0, ty: 0.0};
- };
- cc.affineTransformIdentity = function () {
- return {a: 1.0, b: 0.0, c: 0.0, d: 1.0, tx: 0.0, ty: 0.0};
- };
- cc.rectApplyAffineTransform = function (rect, anAffineTransform) {
- var top = cc.rectGetMinY(rect);
- var left = cc.rectGetMinX(rect);
- var right = cc.rectGetMaxX(rect);
- var bottom = cc.rectGetMaxY(rect);
- var topLeft = cc.pointApplyAffineTransform(left, top, anAffineTransform);
- var topRight = cc.pointApplyAffineTransform(right, top, anAffineTransform);
- var bottomLeft = cc.pointApplyAffineTransform(left, bottom, anAffineTransform);
- var bottomRight = cc.pointApplyAffineTransform(right, bottom, anAffineTransform);
- var minX = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
- var maxX = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
- var minY = Math.min(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y);
- var maxY = Math.max(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y);
- return cc.rect(minX, minY, (maxX - minX), (maxY - minY));
- };
- cc._rectApplyAffineTransformIn = function(rect, anAffineTransform){
- var top = cc.rectGetMinY(rect);
- var left = cc.rectGetMinX(rect);
- var right = cc.rectGetMaxX(rect);
- var bottom = cc.rectGetMaxY(rect);
- var topLeft = cc.pointApplyAffineTransform(left, top, anAffineTransform);
- var topRight = cc.pointApplyAffineTransform(right, top, anAffineTransform);
- var bottomLeft = cc.pointApplyAffineTransform(left, bottom, anAffineTransform);
- var bottomRight = cc.pointApplyAffineTransform(right, bottom, anAffineTransform);
- var minX = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
- var maxX = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
- var minY = Math.min(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y);
- var maxY = Math.max(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y);
- rect.x = minX;
- rect.y = minY;
- rect.width = maxX - minX;
- rect.height = maxY - minY;
- return rect;
- };
- cc.affineTransformTranslate = function (t, tx, ty) {
- return {
- a: t.a,
- b: t.b,
- c: t.c,
- d: t.d,
- tx: t.tx + t.a * tx + t.c * ty,
- ty: t.ty + t.b * tx + t.d * ty
- };
- };
- cc.affineTransformScale = function (t, sx, sy) {
- return {a: t.a * sx, b: t.b * sx, c: t.c * sy, d: t.d * sy, tx: t.tx, ty: t.ty};
- };
- cc.affineTransformRotate = function (aTransform, anAngle) {
- var fSin = Math.sin(anAngle);
- var fCos = Math.cos(anAngle);
- return {a: aTransform.a * fCos + aTransform.c * fSin,
- b: aTransform.b * fCos + aTransform.d * fSin,
- c: aTransform.c * fCos - aTransform.a * fSin,
- d: aTransform.d * fCos - aTransform.b * fSin,
- tx: aTransform.tx,
- ty: aTransform.ty};
- };
- cc.affineTransformConcat = function (t1, t2) {
- return {a: t1.a * t2.a + t1.b * t2.c,
- b: t1.a * t2.b + t1.b * t2.d,
- c: t1.c * t2.a + t1.d * t2.c,
- d: t1.c * t2.b + t1.d * t2.d,
- tx: t1.tx * t2.a + t1.ty * t2.c + t2.tx,
- ty: t1.tx * t2.b + t1.ty * t2.d + t2.ty};
- };
- cc.affineTransformConcatIn = function (t1, t2) {
- var a = t1.a, b = t1.b, c = t1.c, d = t1.d, tx = t1.tx, ty = t1.ty;
- t1.a = a * t2.a + b * t2.c;
- t1.b = a * t2.b + b * t2.d;
- t1.c = c * t2.a + d * t2.c;
- t1.d = c * t2.b + d * t2.d;
- t1.tx = tx * t2.a + ty * t2.c + t2.tx;
- t1.ty = tx * t2.b + ty * t2.d + t2.ty;
- return t1;
- };
- cc.affineTransformEqualToTransform = function (t1, t2) {
- return ((t1.a === t2.a) && (t1.b === t2.b) && (t1.c === t2.c) && (t1.d === t2.d) && (t1.tx === t2.tx) && (t1.ty === t2.ty));
- };
- cc.affineTransformInvert = function (t) {
- var determinant = 1 / (t.a * t.d - t.b * t.c);
- return {a: determinant * t.d, b: -determinant * t.b, c: -determinant * t.c, d: determinant * t.a,
- tx: determinant * (t.c * t.ty - t.d * t.tx), ty: determinant * (t.b * t.tx - t.a * t.ty)};
- };
- cc.POINT_EPSILON = parseFloat('1.192092896e-07F');
- cc.pNeg = function (point) {
- return cc.p(-point.x, -point.y);
- };
- cc.pAdd = function (v1, v2) {
- return cc.p(v1.x + v2.x, v1.y + v2.y);
- };
- cc.pSub = function (v1, v2) {
- return cc.p(v1.x - v2.x, v1.y - v2.y);
- };
- cc.pMult = function (point, floatVar) {
- return cc.p(point.x * floatVar, point.y * floatVar);
- };
- cc.pMidpoint = function (v1, v2) {
- return cc.pMult(cc.pAdd(v1, v2), 0.5);
- };
- cc.pDot = function (v1, v2) {
- return v1.x * v2.x + v1.y * v2.y;
- };
- cc.pCross = function (v1, v2) {
- return v1.x * v2.y - v1.y * v2.x;
- };
- cc.pPerp = function (point) {
- return cc.p(-point.y, point.x);
- };
- cc.pRPerp = function (point) {
- return cc.p(point.y, -point.x);
- };
- cc.pProject = function (v1, v2) {
- return cc.pMult(v2, cc.pDot(v1, v2) / cc.pDot(v2, v2));
- };
- cc.pRotate = function (v1, v2) {
- return cc.p(v1.x * v2.x - v1.y * v2.y, v1.x * v2.y + v1.y * v2.x);
- };
- cc.pUnrotate = function (v1, v2) {
- return cc.p(v1.x * v2.x + v1.y * v2.y, v1.y * v2.x - v1.x * v2.y);
- };
- cc.pLengthSQ = function (v) {
- return cc.pDot(v, v);
- };
- cc.pDistanceSQ = function(point1, point2){
- return cc.pLengthSQ(cc.pSub(point1,point2));
- };
- cc.pLength = function (v) {
- return Math.sqrt(cc.pLengthSQ(v));
- };
- cc.pDistance = function (v1, v2) {
- return cc.pLength(cc.pSub(v1, v2));
- };
- cc.pNormalize = function (v) {
- var n = cc.pLength(v);
- return n === 0 ? cc.p(v) : cc.pMult(v, 1.0 / n);
- };
- cc.pForAngle = function (a) {
- return cc.p(Math.cos(a), Math.sin(a));
- };
- cc.pToAngle = function (v) {
- return Math.atan2(v.y, v.x);
- };
- cc.clampf = function (value, min_inclusive, max_inclusive) {
- if (min_inclusive > max_inclusive) {
- var temp = min_inclusive;
- min_inclusive = max_inclusive;
- max_inclusive = temp;
- }
- return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive;
- };
- cc.pClamp = function (p, min_inclusive, max_inclusive) {
- return cc.p(cc.clampf(p.x, min_inclusive.x, max_inclusive.x), cc.clampf(p.y, min_inclusive.y, max_inclusive.y));
- };
- cc.pFromSize = function (s) {
- return cc.p(s.width, s.height);
- };
- cc.pCompOp = function (p, opFunc) {
- return cc.p(opFunc(p.x), opFunc(p.y));
- };
- cc.pLerp = function (a, b, alpha) {
- return cc.pAdd(cc.pMult(a, 1 - alpha), cc.pMult(b, alpha));
- };
- cc.pFuzzyEqual = function (a, b, variance) {
- if (a.x - variance <= b.x && b.x <= a.x + variance) {
- if (a.y - variance <= b.y && b.y <= a.y + variance)
- return true;
- }
- return false;
- };
- cc.pCompMult = function (a, b) {
- return cc.p(a.x * b.x, a.y * b.y);
- };
- cc.pAngleSigned = function (a, b) {
- var a2 = cc.pNormalize(a);
- var b2 = cc.pNormalize(b);
- var angle = Math.atan2(a2.x * b2.y - a2.y * b2.x, cc.pDot(a2, b2));
- if (Math.abs(angle) < cc.POINT_EPSILON)
- return 0.0;
- return angle;
- };
- cc.pAngle = function (a, b) {
- var angle = Math.acos(cc.pDot(cc.pNormalize(a), cc.pNormalize(b)));
- if (Math.abs(angle) < cc.POINT_EPSILON) return 0.0;
- return angle;
- };
- cc.pRotateByAngle = function (v, pivot, angle) {
- var r = cc.pSub(v, pivot);
- var cosa = Math.cos(angle), sina = Math.sin(angle);
- var t = r.x;
- r.x = t * cosa - r.y * sina + pivot.x;
- r.y = t * sina + r.y * cosa + pivot.y;
- return r;
- };
- cc.pLineIntersect = function (A, B, C, D, retP) {
- if ((A.x === B.x && A.y === B.y) || (C.x === D.x && C.y === D.y)) {
- return false;
- }
- var BAx = B.x - A.x;
- var BAy = B.y - A.y;
- var DCx = D.x - C.x;
- var DCy = D.y - C.y;
- var ACx = A.x - C.x;
- var ACy = A.y - C.y;
- var denom = DCy * BAx - DCx * BAy;
- retP.x = DCx * ACy - DCy * ACx;
- retP.y = BAx * ACy - BAy * ACx;
- if (denom === 0) {
- if (retP.x === 0 || retP.y === 0) {
- return true;
- }
- return false;
- }
- retP.x = retP.x / denom;
- retP.y = retP.y / denom;
- return true;
- };
- cc.pSegmentIntersect = function (A, B, C, D) {
- var retP = cc.p(0, 0);
- if (cc.pLineIntersect(A, B, C, D, retP))
- if (retP.x >= 0.0 && retP.x <= 1.0 && retP.y >= 0.0 && retP.y <= 1.0)
- return true;
- return false;
- };
- cc.pIntersectPoint = function (A, B, C, D) {
- var retP = cc.p(0, 0);
- if (cc.pLineIntersect(A, B, C, D, retP)) {
- var P = cc.p(0, 0);
- P.x = A.x + retP.x * (B.x - A.x);
- P.y = A.y + retP.x * (B.y - A.y);
- return P;
- }
- return cc.p(0,0);
- };
- cc.pSameAs = function (A, B) {
- if ((A != null) && (B != null)) {
- return (A.x === B.x && A.y === B.y);
- }
- return false;
- };
- cc.pZeroIn = function(v) {
- v.x = 0;
- v.y = 0;
- };
- cc.pIn = function(v1, v2) {
- v1.x = v2.x;
- v1.y = v2.y;
- };
- cc.pMultIn = function(point, floatVar) {
- point.x *= floatVar;
- point.y *= floatVar;
- };
- cc.pSubIn = function(v1, v2) {
- v1.x -= v2.x;
- v1.y -= v2.y;
- };
- cc.pAddIn = function(v1, v2) {
- v1.x += v2.x;
- v1.y += v2.y;
- };
- cc.pNormalizeIn = function(v) {
- cc.pMultIn(v, 1.0 / Math.sqrt(v.x * v.x + v.y * v.y));
- };
- cc.Touch = cc.Class.extend({
- _point:null,
- _prevPoint:null,
- _id:0,
- _startPointCaptured: false,
- _startPoint:null,
- ctor:function (x, y, id) {
- this.setTouchInfo(id, x, y);
- },
- getLocation:function () {
- return {x: this._point.x, y: this._point.y};
- },
- getLocationX: function () {
- return this._point.x;
- },
- getLocationY: function () {
- return this._point.y;
- },
- getPreviousLocation:function () {
- return {x: this._prevPoint.x, y: this._prevPoint.y};
- },
- getStartLocation: function() {
- return {x: this._startPoint.x, y: this._startPoint.y};
- },
- getDelta:function () {
- return cc.pSub(this._point, this._prevPoint);
- },
- getLocationInView: function() {
- return {x: this._point.x, y: this._point.y};
- },
- getPreviousLocationInView: function(){
- return {x: this._prevPoint.x, y: this._prevPoint.y};
- },
- getStartLocationInView: function(){
- return {x: this._startPoint.x, y: this._startPoint.y};
- },
- getID:function () {
- return this._id;
- },
- getId:function () {
- cc.log("getId is deprecated. Please use getID instead.");
- return this._id;
- },
- setTouchInfo:function (id, x, y) {
- this._prevPoint = this._point;
- this._point = cc.p(x || 0, y || 0);
- this._id = id;
- if (!this._startPointCaptured) {
- this._startPoint = cc.p(this._point);
- cc.view._convertPointWithScale(this._startPoint);
- this._startPointCaptured = true;
- }
- },
- _setPoint: function(x, y){
- if(y === undefined){
- this._point.x = x.x;
- this._point.y = x.y;
- }else{
- this._point.x = x;
- this._point.y = y;
- }
- },
- _setPrevPoint:function (x, y) {
- if(y === undefined)
- this._prevPoint = cc.p(x.x, x.y);
- else
- this._prevPoint = cc.p(x || 0, y || 0);
- }
- });
- cc.Event = cc.Class.extend({
- _type: 0,
- _isStopped: false,
- _currentTarget: null,
- _setCurrentTarget: function (target) {
- this._currentTarget = target;
- },
- ctor: function (type) {
- this._type = type;
- },
- getType: function () {
- return this._type;
- },
- stopPropagation: function () {
- this._isStopped = true;
- },
- isStopped: function () {
- return this._isStopped;
- },
- getCurrentTarget: function () {
- return this._currentTarget;
- }
- });
- cc.Event.TOUCH = 0;
- cc.Event.KEYBOARD = 1;
- cc.Event.ACCELERATION = 2;
- cc.Event.MOUSE = 3;
- cc.Event.FOCUS = 4;
- cc.Event.CUSTOM = 6;
- cc.EventCustom = cc.Event.extend({
- _eventName: null,
- _userData: null,
- ctor: function (eventName) {
- cc.Event.prototype.ctor.call(this, cc.Event.CUSTOM);
- this._eventName = eventName;
- },
- setUserData: function (data) {
- this._userData = data;
- },
- getUserData: function () {
- return this._userData;
- },
- getEventName: function () {
- return this._eventName;
- }
- });
- cc.EventMouse = cc.Event.extend({
- _eventType: 0,
- _button: 0,
- _x: 0,
- _y: 0,
- _prevX: 0,
- _prevY: 0,
- _scrollX: 0,
- _scrollY: 0,
- ctor: function (eventType) {
- cc.Event.prototype.ctor.call(this, cc.Event.MOUSE);
- this._eventType = eventType;
- },
- setScrollData: function (scrollX, scrollY) {
- this._scrollX = scrollX;
- this._scrollY = scrollY;
- },
- getScrollX: function () {
- return this._scrollX;
- },
- getScrollY: function () {
- return this._scrollY;
- },
- setLocation: function (x, y) {
- this._x = x;
- this._y = y;
- },
- getLocation: function () {
- return {x: this._x, y: this._y};
- },
- getLocationInView: function() {
- return {x: this._x, y: cc.view._designResolutionSize.height - this._y};
- },
- _setPrevCursor: function (x, y) {
- this._prevX = x;
- this._prevY = y;
- },
- getDelta: function () {
- return {x: this._x - this._prevX, y: this._y - this._prevY};
- },
- getDeltaX: function () {
- return this._x - this._prevX;
- },
- getDeltaY: function () {
- return this._y - this._prevY;
- },
- setButton: function (button) {
- this._button = button;
- },
- getButton: function () {
- return this._button;
- },
- getLocationX: function () {
- return this._x;
- },
- getLocationY: function () {
- return this._y;
- }
- });
- cc.EventMouse.NONE = 0;
- cc.EventMouse.DOWN = 1;
- cc.EventMouse.UP = 2;
- cc.EventMouse.MOVE = 3;
- cc.EventMouse.SCROLL = 4;
- cc.EventMouse.BUTTON_LEFT = 0;
- cc.EventMouse.BUTTON_RIGHT = 2;
- cc.EventMouse.BUTTON_MIDDLE = 1;
- cc.EventMouse.BUTTON_4 = 3;
- cc.EventMouse.BUTTON_5 = 4;
- cc.EventMouse.BUTTON_6 = 5;
- cc.EventMouse.BUTTON_7 = 6;
- cc.EventMouse.BUTTON_8 = 7;
- cc.EventTouch = cc.Event.extend({
- _eventCode: 0,
- _touches: null,
- ctor: function (arr) {
- cc.Event.prototype.ctor.call(this, cc.Event.TOUCH);
- this._touches = arr || [];
- },
- getEventCode: function () {
- return this._eventCode;
- },
- getTouches: function () {
- return this._touches;
- },
- _setEventCode: function (eventCode) {
- this._eventCode = eventCode;
- },
- _setTouches: function (touches) {
- this._touches = touches;
- }
- });
- cc.EventTouch.MAX_TOUCHES = 5;
- cc.EventTouch.EventCode = {BEGAN: 0, MOVED: 1, ENDED: 2, CANCELLED: 3};
- cc.EventFocus = cc.Event.extend({
- _widgetGetFocus: null,
- _widgetLoseFocus: null,
- ctor: function(widgetLoseFocus, widgetGetFocus){
- cc.Event.prototype.ctor.call(this, cc.Event.FOCUS);
- this._widgetGetFocus = widgetGetFocus;
- this._widgetLoseFocus = widgetLoseFocus;
- }
- });
- cc.EventListener = cc.Class.extend({
- _onEvent: null,
- _type: 0,
- _listenerID: null,
- _registered: false,
- _fixedPriority: 0,
- _node: null,
- _paused: true,
- _isEnabled: true,
- ctor: function (type, listenerID, callback) {
- this._onEvent = callback;
- this._type = type || 0;
- this._listenerID = listenerID || "";
- },
- _setPaused: function (paused) {
- this._paused = paused;
- },
- _isPaused: function () {
- return this._paused;
- },
- _setRegistered: function (registered) {
- this._registered = registered;
- },
- _isRegistered: function () {
- return this._registered;
- },
- _getType: function () {
- return this._type;
- },
- _getListenerID: function () {
- return this._listenerID;
- },
- _setFixedPriority: function (fixedPriority) {
- this._fixedPriority = fixedPriority;
- },
- _getFixedPriority: function () {
- return this._fixedPriority;
- },
- _setSceneGraphPriority: function (node) {
- this._node = node;
- },
- _getSceneGraphPriority: function () {
- return this._node;
- },
- checkAvailable: function () {
- return this._onEvent !== null;
- },
- clone: function () {
- return null;
- },
- setEnabled: function(enabled){
- this._isEnabled = enabled;
- },
- isEnabled: function(){
- return this._isEnabled;
- },
- retain:function () {
- },
- release:function () {
- }
- });
- cc.EventListener.UNKNOWN = 0;
- cc.EventListener.TOUCH_ONE_BY_ONE = 1;
- cc.EventListener.TOUCH_ALL_AT_ONCE = 2;
- cc.EventListener.KEYBOARD = 3;
- cc.EventListener.MOUSE = 4;
- cc.EventListener.ACCELERATION = 6;
- cc.EventListener.FOCUS = 7;
- cc.EventListener.CUSTOM = 8;
- cc._EventListenerCustom = cc.EventListener.extend({
- _onCustomEvent: null,
- ctor: function (listenerId, callback) {
- this._onCustomEvent = callback;
- var selfPointer = this;
- var listener = function (event) {
- if (selfPointer._onCustomEvent !== null)
- selfPointer._onCustomEvent(event);
- };
- cc.EventListener.prototype.ctor.call(this, cc.EventListener.CUSTOM, listenerId, listener);
- },
- checkAvailable: function () {
- return (cc.EventListener.prototype.checkAvailable.call(this) && this._onCustomEvent !== null);
- },
- clone: function () {
- return new cc._EventListenerCustom(this._listenerID, this._onCustomEvent);
- }
- });
- cc._EventListenerCustom.create = function (eventName, callback) {
- return new cc._EventListenerCustom(eventName, callback);
- };
- cc._EventListenerMouse = cc.EventListener.extend({
- onMouseDown: null,
- onMouseUp: null,
- onMouseMove: null,
- onMouseScroll: null,
- ctor: function () {
- var selfPointer = this;
- var listener = function (event) {
- var eventType = cc.EventMouse;
- switch (event._eventType) {
- case eventType.DOWN:
- if (selfPointer.onMouseDown)
- selfPointer.onMouseDown(event);
- break;
- case eventType.UP:
- if (selfPointer.onMouseUp)
- selfPointer.onMouseUp(event);
- break;
- case eventType.MOVE:
- if (selfPointer.onMouseMove)
- selfPointer.onMouseMove(event);
- break;
- case eventType.SCROLL:
- if (selfPointer.onMouseScroll)
- selfPointer.onMouseScroll(event);
- break;
- default:
- break;
- }
- };
- cc.EventListener.prototype.ctor.call(this, cc.EventListener.MOUSE, cc._EventListenerMouse.LISTENER_ID, listener);
- },
- clone: function () {
- var eventListener = new cc._EventListenerMouse();
- eventListener.onMouseDown = this.onMouseDown;
- eventListener.onMouseUp = this.onMouseUp;
- eventListener.onMouseMove = this.onMouseMove;
- eventListener.onMouseScroll = this.onMouseScroll;
- return eventListener;
- },
- checkAvailable: function () {
- return true;
- }
- });
- cc._EventListenerMouse.LISTENER_ID = "__cc_mouse";
- cc._EventListenerMouse.create = function () {
- return new cc._EventListenerMouse();
- };
- cc._EventListenerTouchOneByOne = cc.EventListener.extend({
- _claimedTouches: null,
- swallowTouches: false,
- onTouchBegan: null,
- onTouchMoved: null,
- onTouchEnded: null,
- onTouchCancelled: null,
- ctor: function () {
- cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ONE_BY_ONE, cc._EventListenerTouchOneByOne.LISTENER_ID, null);
- this._claimedTouches = [];
- },
- setSwallowTouches: function (needSwallow) {
- this.swallowTouches = needSwallow;
- },
- isSwallowTouches: function(){
- return this.swallowTouches;
- },
- clone: function () {
- var eventListener = new cc._EventListenerTouchOneByOne();
- eventListener.onTouchBegan = this.onTouchBegan;
- eventListener.onTouchMoved = this.onTouchMoved;
- eventListener.onTouchEnded = this.onTouchEnded;
- eventListener.onTouchCancelled = this.onTouchCancelled;
- eventListener.swallowTouches = this.swallowTouches;
- return eventListener;
- },
- checkAvailable: function () {
- if(!this.onTouchBegan){
- cc.log(cc._LogInfos._EventListenerTouchOneByOne_checkAvailable);
- return false;
- }
- return true;
- }
- });
- cc._EventListenerTouchOneByOne.LISTENER_ID = "__cc_touch_one_by_one";
- cc._EventListenerTouchOneByOne.create = function () {
- return new cc._EventListenerTouchOneByOne();
- };
- cc._EventListenerTouchAllAtOnce = cc.EventListener.extend({
- onTouchesBegan: null,
- onTouchesMoved: null,
- onTouchesEnded: null,
- onTouchesCancelled: null,
- ctor: function(){
- cc.EventListener.prototype.ctor.call(this, cc.EventListener.TOUCH_ALL_AT_ONCE, cc._EventListenerTouchAllAtOnce.LISTENER_ID, null);
- },
- clone: function(){
- var eventListener = new cc._EventListenerTouchAllAtOnce();
- eventListener.onTouchesBegan = this.onTouchesBegan;
- eventListener.onTouchesMoved = this.onTouchesMoved;
- eventListener.onTouchesEnded = this.onTouchesEnded;
- eventListener.onTouchesCancelled = this.onTouchesCancelled;
- return eventListener;
- },
- checkAvailable: function(){
- if (this.onTouchesBegan === null && this.onTouchesMoved === null
- && this.onTouchesEnded === null && this.onTouchesCancelled === null) {
- cc.log(cc._LogInfos._EventListenerTouchAllAtOnce_checkAvailable);
- return false;
- }
- return true;
- }
- });
- cc._EventListenerTouchAllAtOnce.LISTENER_ID = "__cc_touch_all_at_once";
- cc._EventListenerTouchAllAtOnce.create = function(){
- return new cc._EventListenerTouchAllAtOnce();
- };
- cc.EventListener.create = function(argObj){
- cc.assert(argObj&&argObj.event, cc._LogInfos.EventListener_create);
- var listenerType = argObj.event;
- delete argObj.event;
- var listener = null;
- if(listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
- listener = new cc._EventListenerTouchOneByOne();
- else if(listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
- listener = new cc._EventListenerTouchAllAtOnce();
- else if(listenerType === cc.EventListener.MOUSE)
- listener = new cc._EventListenerMouse();
- else if(listenerType === cc.EventListener.CUSTOM){
- listener = new cc._EventListenerCustom(argObj.eventName, argObj.callback);
- delete argObj.eventName;
- delete argObj.callback;
- } else if(listenerType === cc.EventListener.KEYBOARD)
- listener = new cc._EventListenerKeyboard();
- else if(listenerType === cc.EventListener.ACCELERATION){
- listener = new cc._EventListenerAcceleration(argObj.callback);
- delete argObj.callback;
- } else if(listenerType === cc.EventListener.FOCUS)
- listener = new cc._EventListenerFocus();
- for(var key in argObj) {
- listener[key] = argObj[key];
- }
- return listener;
- };
- cc._EventListenerFocus = cc.EventListener.extend({
- clone: function(){
- var listener = new cc._EventListenerFocus();
- listener.onFocusChanged = this.onFocusChanged;
- return listener;
- },
- checkAvailable: function(){
- if(!this.onFocusChanged){
- cc.log("Invalid EventListenerFocus!");
- return false;
- }
- return true;
- },
- onFocusChanged: null,
- ctor: function(){
- var listener = function(event){
- if(this.onFocusChanged)
- this.onFocusChanged(event._widgetLoseFocus, event._widgetGetFocus);
- };
- cc.EventListener.prototype.ctor.call(this, cc.EventListener.FOCUS, cc._EventListenerFocus.LISTENER_ID, listener);
- }
- });
- cc._EventListenerFocus.LISTENER_ID = "__cc_focus_event";
- cc._EventListenerVector = cc.Class.extend({
- _fixedListeners: null,
- _sceneGraphListeners: null,
- gt0Index: 0,
- ctor: function () {
- this._fixedListeners = [];
- this._sceneGraphListeners = [];
- },
- size: function () {
- return this._fixedListeners.length + this._sceneGraphListeners.length;
- },
- empty: function () {
- return (this._fixedListeners.length === 0) && (this._sceneGraphListeners.length === 0);
- },
- push: function (listener) {
- if (listener._getFixedPriority() === 0)
- this._sceneGraphListeners.push(listener);
- else
- this._fixedListeners.push(listener);
- },
- clearSceneGraphListeners: function () {
- this._sceneGraphListeners.length = 0;
- },
- clearFixedListeners: function () {
- this._fixedListeners.length = 0;
- },
- clear: function () {
- this._sceneGraphListeners.length = 0;
- this._fixedListeners.length = 0;
- },
- getFixedPriorityListeners: function () {
- return this._fixedListeners;
- },
- getSceneGraphPriorityListeners: function () {
- return this._sceneGraphListeners;
- }
- });
- cc.__getListenerID = function (event) {
- var eventType = cc.Event, getType = event.getType();
- if(getType === eventType.ACCELERATION)
- return cc._EventListenerAcceleration.LISTENER_ID;
- if(getType === eventType.CUSTOM)
- return event.getEventName();
- if(getType === eventType.KEYBOARD)
- return cc._EventListenerKeyboard.LISTENER_ID;
- if(getType === eventType.MOUSE)
- return cc._EventListenerMouse.LISTENER_ID;
- if(getType === eventType.FOCUS)
- return cc._EventListenerFocus.LISTENER_ID;
- if(getType === eventType.TOUCH){
- cc.log(cc._LogInfos.__getListenerID);
- }
- return "";
- };
- cc.eventManager = {
- DIRTY_NONE:0,
- DIRTY_FIXED_PRIORITY:1 <<0,
- DIRTY_SCENE_GRAPH_PRIORITY : 1<< 1,
- DIRTY_ALL: 3,
- _listenersMap: {},
- _priorityDirtyFlagMap: {},
- _nodeListenersMap: {},
- _nodePriorityMap: {},
- _globalZOrderNodeMap: {},
- _toAddedListeners: [],
- _toRemovedListeners: [],
- _dirtyNodes: [],
- _inDispatch: 0,
- _isEnabled: false,
- _nodePriorityIndex: 0,
- _internalCustomListenerIDs:[cc.game.EVENT_HIDE, cc.game.EVENT_SHOW],
- _setDirtyForNode: function (node) {
- if (this._nodeListenersMap[node.__instanceId] != null)
- this._dirtyNodes.push(node);
- var _children = node.getChildren();
- for(var i = 0, len = _children.length; i < len; i++)
- this._setDirtyForNode(_children[i]);
- },
- pauseTarget: function (node, recursive) {
- var listeners = this._nodeListenersMap[node.__instanceId], i, len;
- if (listeners) {
- for ( i = 0, len = listeners.length; i < len; i++)
- listeners[i]._setPaused(true);
- }
- if (recursive === true) {
- var locChildren = node.getChildren();
- for ( i = 0, len = locChildren.length; i< len; i++)
- this.pauseTarget(locChildren[i], true);
- }
- },
- resumeTarget: function (node, recursive) {
- var listeners = this._nodeListenersMap[node.__instanceId], i, len;
- if (listeners){
- for ( i = 0, len = listeners.length; i < len; i++)
- listeners[i]._setPaused(false);
- }
- this._setDirtyForNode(node);
- if (recursive === true) {
- var locChildren = node.getChildren();
- for ( i = 0, len = locChildren.length; i< len; i++)
- this.resumeTarget(locChildren[i], true);
- }
- },
- _addListener: function (listener) {
- if (this._inDispatch === 0)
- this._forceAddEventListener(listener);
- else
- this._toAddedListeners.push(listener);
- },
- _forceAddEventListener: function (listener) {
- var listenerID = listener._getListenerID();
- var listeners = this._listenersMap[listenerID];
- if (!listeners) {
- listeners = new cc._EventListenerVector();
- this._listenersMap[listenerID] = listeners;
- }
- listeners.push(listener);
- if (listener._getFixedPriority() === 0) {
- this._setDirty(listenerID, this.DIRTY_SCENE_GRAPH_PRIORITY);
- var node = listener._getSceneGraphPriority();
- if (node === null)
- cc.log(cc._LogInfos.eventManager__forceAddEventListener);
- this._associateNodeAndEventListener(node, listener);
- if (node.isRunning())
- this.resumeTarget(node);
- } else
- this._setDirty(listenerID, this.DIRTY_FIXED_PRIORITY);
- },
- _getListeners: function (listenerID) {
- return this._listenersMap[listenerID];
- },
- _updateDirtyFlagForSceneGraph: function () {
- if (this._dirtyNodes.length === 0)
- return;
- var locDirtyNodes = this._dirtyNodes, selListeners, selListener, locNodeListenersMap = this._nodeListenersMap;
- for (var i = 0, len = locDirtyNodes.length; i < len; i++) {
- selListeners = locNodeListenersMap[locDirtyNodes[i].__instanceId];
- if (selListeners) {
- for (var j = 0, listenersLen = selListeners.length; j < listenersLen; j++) {
- selListener = selListeners[j];
- if (selListener)
- this._setDirty(selListener._getListenerID(), this.DIRTY_SCENE_GRAPH_PRIORITY);
- }
- }
- }
- this._dirtyNodes.length = 0;
- },
- _removeAllListenersInVector: function (listenerVector) {
- if (!listenerVector)
- return;
- var selListener;
- for (var i = 0; i < listenerVector.length;) {
- selListener = listenerVector[i];
- selListener._setRegistered(false);
- if (selListener._getSceneGraphPriority() != null){
- this._dissociateNodeAndEventListener(selListener._getSceneGraphPriority(), selListener);
- selListener._setSceneGraphPriority(null);
- }
- if (this._inDispatch === 0)
- cc.arrayRemoveObject(listenerVector, selListener);
- else
- ++i;
- }
- },
- _removeListenersForListenerID: function (listenerID) {
- var listeners = this._listenersMap[listenerID], i;
- if (listeners) {
- var fixedPriorityListeners = listeners.getFixedPriorityListeners();
- var sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
- this._removeAllListenersInVector(sceneGraphPriorityListeners);
- this._removeAllListenersInVector(fixedPriorityListeners);
- delete this._priorityDirtyFlagMap[listenerID];
- if (!this._inDispatch) {
- listeners.clear();
- delete this._listenersMap[listenerID];
- }
- }
- var locToAddedListeners = this._toAddedListeners, listener;
- for (i = 0; i < locToAddedListeners.length;) {
- listener = locToAddedListeners[i];
- if (listener && listener._getListenerID() === listenerID)
- cc.arrayRemoveObject(locToAddedListeners, listener);
- else
- ++i;
- }
- },
- _sortEventListeners: function (listenerID) {
- var dirtyFlag = this.DIRTY_NONE, locFlagMap = this._priorityDirtyFlagMap;
- if (locFlagMap[listenerID])
- dirtyFlag = locFlagMap[listenerID];
- if (dirtyFlag !== this.DIRTY_NONE) {
- locFlagMap[listenerID] = this.DIRTY_NONE;
- if (dirtyFlag & this.DIRTY_FIXED_PRIORITY)
- this._sortListenersOfFixedPriority(listenerID);
- if (dirtyFlag & this.DIRTY_SCENE_GRAPH_PRIORITY){
- var rootNode = cc.director.getRunningScene();
- if(rootNode)
- this._sortListenersOfSceneGraphPriority(listenerID, rootNode);
- else
- locFlagMap[listenerID] = this.DIRTY_SCENE_GRAPH_PRIORITY;
- }
- }
- },
- _sortListenersOfSceneGraphPriority: function (listenerID, rootNode) {
- var listeners = this._getListeners(listenerID);
- if (!listeners)
- return;
- var sceneGraphListener = listeners.getSceneGraphPriorityListeners();
- if(!sceneGraphListener || sceneGraphListener.length === 0)
- return;
- this._nodePriorityIndex = 0;
- this._nodePriorityMap = {};
- this._visitTarget(rootNode, true);
- listeners.getSceneGraphPriorityListeners().sort(this._sortEventListenersOfSceneGraphPriorityDes);
- },
- _sortEventListenersOfSceneGraphPriorityDes : function(l1, l2){
- var locNodePriorityMap = cc.eventManager._nodePriorityMap, node1 = l1._getSceneGraphPriority(),
- node2 = l2._getSceneGraphPriority();
- if( !l2 || !node2 || !locNodePriorityMap[node2.__instanceId] )
- return -1;
- else if( !l1 || !node1 || !locNodePriorityMap[node1.__instanceId] )
- return 1;
- return locNodePriorityMap[l2._getSceneGraphPriority().__instanceId] - locNodePriorityMap[l1._getSceneGraphPriority().__instanceId];
- },
- _sortListenersOfFixedPriority: function (listenerID) {
- var listeners = this._listenersMap[listenerID];
- if (!listeners)
- return;
- var fixedListeners = listeners.getFixedPriorityListeners();
- if(!fixedListeners || fixedListeners.length === 0)
- return;
- fixedListeners.sort(this._sortListenersOfFixedPriorityAsc);
- var index = 0;
- for (var len = fixedListeners.length; index < len;) {
- if (fixedListeners[index]._getFixedPriority() >= 0)
- break;
- ++index;
- }
- listeners.gt0Index = index;
- },
- _sortListenersOfFixedPriorityAsc: function (l1, l2) {
- return l1._getFixedPriority() - l2._getFixedPriority();
- },
- _onUpdateListeners: function (listenerID) {
- var listeners = this._listenersMap[listenerID];
- if (!listeners)
- return;
- var fixedPriorityListeners = listeners.getFixedPriorityListeners();
- var sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
- var i, selListener, idx, toRemovedListeners = this._toRemovedListeners;
- if (sceneGraphPriorityListeners) {
- for (i = 0; i < sceneGraphPriorityListeners.length;) {
- selListener = sceneGraphPriorityListeners[i];
- if (!selListener._isRegistered()) {
- cc.arrayRemoveObject(sceneGraphPriorityListeners, selListener);
- idx = toRemovedListeners.indexOf(selListener);
- if(idx !== -1)
- toRemovedListeners.splice(idx, 1);
- } else
- ++i;
- }
- }
- if (fixedPriorityListeners) {
- for (i = 0; i < fixedPriorityListeners.length;) {
- selListener = fixedPriorityListeners[i];
- if (!selListener._isRegistered()) {
- cc.arrayRemoveObject(fixedPriorityListeners, selListener);
- idx = toRemovedListeners.indexOf(selListener);
- if(idx !== -1)
- toRemovedListeners.splice(idx, 1);
- } else
- ++i;
- }
- }
- if (sceneGraphPriorityListeners && sceneGraphPriorityListeners.length === 0)
- listeners.clearSceneGraphListeners();
- if (fixedPriorityListeners && fixedPriorityListeners.length === 0)
- listeners.clearFixedListeners();
- },
- _updateListeners: function (event) {
- var locInDispatch = this._inDispatch;
- cc.assert(locInDispatch > 0, cc._LogInfos.EventManager__updateListeners);
- if(locInDispatch > 1)
- return;
- if (event.getType() === cc.Event.TOUCH) {
- this._onUpdateListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
- this._onUpdateListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
- } else
- this._onUpdateListeners(cc.__getListenerID(event));
- cc.assert(locInDispatch === 1, cc._LogInfos.EventManager__updateListeners_2);
- var locListenersMap = this._listenersMap, locPriorityDirtyFlagMap = this._priorityDirtyFlagMap;
- for (var selKey in locListenersMap) {
- if (locListenersMap[selKey].empty()) {
- delete locPriorityDirtyFlagMap[selKey];
- delete locListenersMap[selKey];
- }
- }
- var locToAddedListeners = this._toAddedListeners;
- if (locToAddedListeners.length !== 0) {
- for (var i = 0, len = locToAddedListeners.length; i < len; i++)
- this._forceAddEventListener(locToAddedListeners[i]);
- this._toAddedListeners.length = 0;
- }
- if(this._toRemovedListeners.length !== 0)
- this._cleanToRemovedListeners();
- },
- _cleanToRemovedListeners: function(){
- var toRemovedListeners = this._toRemovedListeners;
- for(var i = 0; i< toRemovedListeners.length; i++){
- var selListener = toRemovedListeners[i];
- var listeners = this._listenersMap[selListener._getListenerID()];
- if(!listeners)
- continue;
- var idx, fixedPriorityListeners = listeners.getFixedPriorityListeners(),
- sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
- if(sceneGraphPriorityListeners){
- idx = sceneGraphPriorityListeners.indexOf(selListener);
- if (idx !== -1) {
- sceneGraphPriorityListeners.splice(idx, 1);
- }
- }
- if(fixedPriorityListeners){
- idx = fixedPriorityListeners.indexOf(selListener);
- if (idx !== -1) {
- fixedPriorityListeners.splice(idx, 1);
- }
- }
- }
- toRemovedListeners.length = 0;
- },
- _onTouchEventCallback: function(listener, argsObj){
- if (!listener._isRegistered)
- return false;
- var event = argsObj.event, selTouch = argsObj.selTouch;
- event._setCurrentTarget(listener._node);
- var isClaimed = false, removedIdx;
- var getCode = event.getEventCode(), eventCode = cc.EventTouch.EventCode;
- if (getCode === eventCode.BEGAN) {
- if (listener.onTouchBegan) {
- isClaimed = listener.onTouchBegan(selTouch, event);
- if (isClaimed && listener._registered)
- listener._claimedTouches.push(selTouch);
- }
- } else if (listener._claimedTouches.length > 0
- && ((removedIdx = listener._claimedTouches.indexOf(selTouch)) !== -1)) {
- isClaimed = true;
- if(getCode === eventCode.MOVED && listener.onTouchMoved){
- listener.onTouchMoved(selTouch, event);
- } else if(getCode === eventCode.ENDED){
- if (listener.onTouchEnded)
- listener.onTouchEnded(selTouch, event);
- if (listener._registered)
- listener._claimedTouches.splice(removedIdx, 1);
- } else if(getCode === eventCode.CANCELLED){
- if (listener.onTouchCancelled)
- listener.onTouchCancelled(selTouch, event);
- if (listener._registered)
- listener._claimedTouches.splice(removedIdx, 1);
- }
- }
- if (event.isStopped()) {
- cc.eventManager._updateListeners(event);
- return true;
- }
- if (isClaimed && listener._registered && listener.swallowTouches) {
- if (argsObj.needsMutableSet)
- argsObj.touches.splice(selTouch, 1);
- return true;
- }
- return false;
- },
- _dispatchTouchEvent: function (event) {
- this._sortEventListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
- this._sortEventListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
- var oneByOneListeners = this._getListeners(cc._EventListenerTouchOneByOne.LISTENER_ID);
- var allAtOnceListeners = this._getListeners(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
- if (null === oneByOneListeners && null === allAtOnceListeners)
- return;
- var originalTouches = event.getTouches(), mutableTouches = cc.copyArray(originalTouches);
- var oneByOneArgsObj = {event: event, needsMutableSet: (oneByOneListeners && allAtOnceListeners), touches: mutableTouches, selTouch: null};
- if (oneByOneListeners) {
- for (var i = 0; i < originalTouches.length; i++) {
- oneByOneArgsObj.selTouch = originalTouches[i];
- this._dispatchEventToListeners(oneByOneListeners, this._onTouchEventCallback, oneByOneArgsObj);
- if (event.isStopped())
- return;
- }
- }
- if (allAtOnceListeners && mutableTouches.length > 0) {
- this._dispatchEventToListeners(allAtOnceListeners, this._onTouchesEventCallback, {event: event, touches: mutableTouches});
- if (event.isStopped())
- return;
- }
- this._updateListeners(event);
- },
- _onTouchesEventCallback: function (listener, callbackParams) {
- if (!listener._registered)
- return false;
- var eventCode = cc.EventTouch.EventCode, event = callbackParams.event, touches = callbackParams.touches, getCode = event.getEventCode();
- event._setCurrentTarget(listener._node);
- if(getCode === eventCode.BEGAN && listener.onTouchesBegan)
- listener.onTouchesBegan(touches, event);
- else if(getCode === eventCode.MOVED && listener.onTouchesMoved)
- listener.onTouchesMoved(touches, event);
- else if(getCode === eventCode.ENDED && listener.onTouchesEnded)
- listener.onTouchesEnded(touches, event);
- else if(getCode === eventCode.CANCELLED && listener.onTouchesCancelled)
- listener.onTouchesCancelled(touches, event);
- if (event.isStopped()) {
- cc.eventManager._updateListeners(event);
- return true;
- }
- return false;
- },
- _associateNodeAndEventListener: function (node, listener) {
- var listeners = this._nodeListenersMap[node.__instanceId];
- if (!listeners) {
- listeners = [];
- this._nodeListenersMap[node.__instanceId] = listeners;
- }
- listeners.push(listener);
- },
- _dissociateNodeAndEventListener: function (node, listener) {
- var listeners = this._nodeListenersMap[node.__instanceId];
- if (listeners) {
- cc.arrayRemoveObject(listeners, listener);
- if (listeners.length === 0)
- delete this._nodeListenersMap[node.__instanceId];
- }
- },
- _dispatchEventToListeners: function (listeners, onEvent, eventOrArgs) {
- var shouldStopPropagation = false;
- var fixedPriorityListeners = listeners.getFixedPriorityListeners();
- var sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
- var i = 0, j, selListener;
- if (fixedPriorityListeners) {
- if (fixedPriorityListeners.length !== 0) {
- for (; i < listeners.gt0Index; ++i) {
- selListener = fixedPriorityListeners[i];
- if (selListener.isEnabled() && !selListener._isPaused() && selListener._isRegistered() && onEvent(selListener, eventOrArgs)) {
- shouldStopPropagation = true;
- break;
- }
- }
- }
- }
- if (sceneGraphPriorityListeners && !shouldStopPropagation) {
- for (j = 0; j < sceneGraphPriorityListeners.length; j++) {
- selListener = sceneGraphPriorityListeners[j];
- if (selListener.isEnabled() && !selListener._isPaused() && selListener._isRegistered() && onEvent(selListener, eventOrArgs)) {
- shouldStopPropagation = true;
- break;
- }
- }
- }
- if (fixedPriorityListeners && !shouldStopPropagation) {
- for (; i < fixedPriorityListeners.length; ++i) {
- selListener = fixedPriorityListeners[i];
- if (selListener.isEnabled() && !selListener._isPaused() && selListener._isRegistered() && onEvent(selListener, eventOrArgs)) {
- shouldStopPropagation = true;
- break;
- }
- }
- }
- },
- _setDirty: function (listenerID, flag) {
- var locDirtyFlagMap = this._priorityDirtyFlagMap;
- if (locDirtyFlagMap[listenerID] == null)
- locDirtyFlagMap[listenerID] = flag;
- else
- locDirtyFlagMap[listenerID] = flag | locDirtyFlagMap[listenerID];
- },
- _visitTarget: function (node, isRootNode) {
- var children = node.getChildren(), i = 0;
- var childrenCount = children.length, locGlobalZOrderNodeMap = this._globalZOrderNodeMap, locNodeListenersMap = this._nodeListenersMap;
- if (childrenCount > 0) {
- var child;
- for (; i < childrenCount; i++) {
- child = children[i];
- if (child && child.getLocalZOrder() < 0)
- this._visitTarget(child, false);
- else
- break;
- }
- if (locNodeListenersMap[node.__instanceId] != null) {
- if (!locGlobalZOrderNodeMap[node.getGlobalZOrder()])
- locGlobalZOrderNodeMap[node.getGlobalZOrder()] = [];
- locGlobalZOrderNodeMap[node.getGlobalZOrder()].push(node.__instanceId);
- }
- for (; i < childrenCount; i++) {
- child = children[i];
- if (child)
- this._visitTarget(child, false);
- }
- } else {
- if (locNodeListenersMap[node.__instanceId] != null) {
- if (!locGlobalZOrderNodeMap[node.getGlobalZOrder()])
- locGlobalZOrderNodeMap[node.getGlobalZOrder()] = [];
- locGlobalZOrderNodeMap[node.getGlobalZOrder()].push(node.__instanceId);
- }
- }
- if (isRootNode) {
- var globalZOrders = [];
- for (var selKey in locGlobalZOrderNodeMap)
- globalZOrders.push(selKey);
- globalZOrders.sort(this._sortNumberAsc);
- var zOrdersLen = globalZOrders.length, selZOrders, j, locNodePriorityMap = this._nodePriorityMap;
- for (i = 0; i < zOrdersLen; i++) {
- selZOrders = locGlobalZOrderNodeMap[globalZOrders[i]];
- for (j = 0; j < selZOrders.length; j++)
- locNodePriorityMap[selZOrders[j]] = ++this._nodePriorityIndex;
- }
- this._globalZOrderNodeMap = {};
- }
- },
- _sortNumberAsc : function (a, b) {
- return a - b;
- },
- addListener: function (listener, nodeOrPriority) {
- cc.assert(listener && nodeOrPriority, cc._LogInfos.eventManager_addListener_2);
- if(!(listener instanceof cc.EventListener)){
- cc.assert(!cc.isNumber(nodeOrPriority), cc._LogInfos.eventManager_addListener_3);
- listener = cc.EventListener.create(listener);
- } else {
- if(listener._isRegistered()){
- cc.log(cc._LogInfos.eventManager_addListener_4);
- return;
- }
- }
- if (!listener.checkAvailable())
- return;
- if (cc.isNumber(nodeOrPriority)) {
- if (nodeOrPriority === 0) {
- cc.log(cc._LogInfos.eventManager_addListener);
- return;
- }
- listener._setSceneGraphPriority(null);
- listener._setFixedPriority(nodeOrPriority);
- listener._setRegistered(true);
- listener._setPaused(false);
- this._addListener(listener);
- } else {
- listener._setSceneGraphPriority(nodeOrPriority);
- listener._setFixedPriority(0);
- listener._setRegistered(true);
- this._addListener(listener);
- }
- return listener;
- },
- addCustomListener: function (eventName, callback) {
- var listener = new cc._EventListenerCustom(eventName, callback);
- this.addListener(listener, 1);
- return listener;
- },
- removeListener: function (listener) {
- if (listener == null)
- return;
- var isFound, locListener = this._listenersMap;
- for (var selKey in locListener) {
- var listeners = locListener[selKey];
- var fixedPriorityListeners = listeners.getFixedPriorityListeners(), sceneGraphPriorityListeners = listeners.getSceneGraphPriorityListeners();
- isFound = this._removeListenerInVector(sceneGraphPriorityListeners, listener);
- if (isFound){
- this._setDirty(listener._getListenerID(), this.DIRTY_SCENE_GRAPH_PRIORITY);
- }else{
- isFound = this._removeListenerInVector(fixedPriorityListeners, listener);
- if (isFound)
- this._setDirty(listener._getListenerID(), this.DIRTY_FIXED_PRIORITY);
- }
- if (listeners.empty()) {
- delete this._priorityDirtyFlagMap[listener._getListenerID()];
- delete locListener[selKey];
- }
- if (isFound)
- break;
- }
- if (!isFound) {
- var locToAddedListeners = this._toAddedListeners;
- for (var i = 0, len = locToAddedListeners.length; i < len; i++) {
- var selListener = locToAddedListeners[i];
- if (selListener === listener) {
- cc.arrayRemoveObject(locToAddedListeners, selListener);
- selListener._setRegistered(false);
- break;
- }
- }
- }
- },
- _removeListenerInCallback: function(listeners, callback){
- if (listeners == null)
- return false;
- for (var i = 0, len = listeners.length; i < len; i++) {
- var selListener = listeners[i];
- if (selListener._onCustomEvent === callback || selListener._onEvent === callback) {
- selListener._setRegistered(false);
- if (selListener._getSceneGraphPriority() != null){
- this._dissociateNodeAndEventListener(selListener._getSceneGraphPriority(), selListener);
- selListener._setSceneGraphPriority(null);
- }
- if (this._inDispatch === 0)
- cc.arrayRemoveObject(listeners, selListener);
- return true;
- }
- }
- return false;
- },
- _removeListenerInVector : function(listeners, listener){
- if (listeners == null)
- return false;
- for (var i = 0, len = listeners.length; i < len; i++) {
- var selListener = listeners[i];
- if (selListener === listener) {
- selListener._setRegistered(false);
- if (selListener._getSceneGraphPriority() != null){
- this._dissociateNodeAndEventListener(selListener._getSceneGraphPriority(), selListener);
- selListener._setSceneGraphPriority(null);
- }
- if (this._inDispatch === 0)
- cc.arrayRemoveObject(listeners, selListener);
- else
- this._toRemovedListeners.push(selListener);
- return true;
- }
- }
- return false;
- },
- removeListeners: function (listenerType, recursive) {
- var _t = this;
- if (listenerType instanceof cc.Node) {
- delete _t._nodePriorityMap[listenerType.__instanceId];
- cc.arrayRemoveObject(_t._dirtyNodes, listenerType);
- var listeners = _t._nodeListenersMap[listenerType.__instanceId], i;
- if (listeners) {
- var listenersCopy = cc.copyArray(listeners);
- for (i = 0; i < listenersCopy.length; i++)
- _t.removeListener(listenersCopy[i]);
- listenersCopy.length = 0;
- }
- var locToAddedListeners = _t._toAddedListeners;
- for (i = 0; i < locToAddedListeners.length; ) {
- var listener = locToAddedListeners[i];
- if (listener._getSceneGraphPriority() === listenerType) {
- listener._setSceneGraphPriority(null);
- listener._setRegistered(false);
- locToAddedListeners.splice(i, 1);
- } else
- ++i;
- }
- if (recursive === true) {
- var locChildren = listenerType.getChildren(), len;
- for (i = 0, len = locChildren.length; i< len; i++)
- _t.removeListeners(locChildren[i], true);
- }
- } else {
- if (listenerType === cc.EventListener.TOUCH_ONE_BY_ONE)
- _t._removeListenersForListenerID(cc._EventListenerTouchOneByOne.LISTENER_ID);
- else if (listenerType === cc.EventListener.TOUCH_ALL_AT_ONCE)
- _t._removeListenersForListenerID(cc._EventListenerTouchAllAtOnce.LISTENER_ID);
- else if (listenerType === cc.EventListener.MOUSE)
- _t._removeListenersForListenerID(cc._EventListenerMouse.LISTENER_ID);
- else if (listenerType === cc.EventListener.ACCELERATION)
- _t._removeListenersForListenerID(cc._EventListenerAcceleration.LISTENER_ID);
- else if (listenerType === cc.EventListener.KEYBOARD)
- _t._removeListenersForListenerID(cc._EventListenerKeyboard.LISTENER_ID);
- else
- cc.log(cc._LogInfos.eventManager_removeListeners);
- }
- },
- removeCustomListeners: function (customEventName) {
- this._removeListenersForListenerID(customEventName);
- },
- removeAllListeners: function () {
- var locListeners = this._listenersMap, locInternalCustomEventIDs = this._internalCustomListenerIDs;
- for (var selKey in locListeners){
- if(locInternalCustomEventIDs.indexOf(selKey) === -1)
- this._removeListenersForListenerID(selKey);
- }
- },
- setPriority: function (listener, fixedPriority) {
- if (listener == null)
- return;
- var locListeners = this._listenersMap;
- for (var selKey in locListeners) {
- var selListeners = locListeners[selKey];
- var fixedPriorityListeners = selListeners.getFixedPriorityListeners();
- if (fixedPriorityListeners) {
- var found = fixedPriorityListeners.indexOf(listener);
- if (found !== -1) {
- if(listener._getSceneGraphPriority() != null)
- cc.log(cc._LogInfos.eventManager_setPriority);
- if (listener._getFixedPriority() !== fixedPriority) {
- listener._setFixedPriority(fixedPriority);
- this._setDirty(listener._getListenerID(), this.DIRTY_FIXED_PRIORITY);
- }
- return;
- }
- }
- }
- },
- setEnabled: function (enabled) {
- this._isEnabled = enabled;
- },
- isEnabled: function () {
- return this._isEnabled;
- },
- dispatchEvent: function (event) {
- if (!this._isEnabled)
- return;
- this._updateDirtyFlagForSceneGraph();
- this._inDispatch++;
- if(!event || !event.getType)
- throw new Error("event is undefined");
- if (event.getType() === cc.Event.TOUCH) {
- this._dispatchTouchEvent(event);
- this._inDispatch--;
- return;
- }
- var listenerID = cc.__getListenerID(event);
- this._sortEventListeners(listenerID);
- var selListeners = this._listenersMap[listenerID];
- if (selListeners != null)
- this._dispatchEventToListeners(selListeners, this._onListenerCallback, event);
- this._updateListeners(event);
- this._inDispatch--;
- },
- _onListenerCallback: function(listener, event){
- event._setCurrentTarget(listener._getSceneGraphPriority());
- listener._onEvent(event);
- return event.isStopped();
- },
- dispatchCustomEvent: function (eventName, optionalUserData) {
- var ev = new cc.EventCustom(eventName);
- ev.setUserData(optionalUserData);
- this.dispatchEvent(ev);
- }
- };
- cc._tmp.PrototypeCCNode = function () {
- var _p = cc.Node.prototype;
- cc.defineGetterSetter(_p, "x", _p.getPositionX, _p.setPositionX);
- cc.defineGetterSetter(_p, "y", _p.getPositionY, _p.setPositionY);
- _p.width;
- cc.defineGetterSetter(_p, "width", _p._getWidth, _p._setWidth);
- _p.height;
- cc.defineGetterSetter(_p, "height", _p._getHeight, _p._setHeight);
- _p.anchorX;
- cc.defineGetterSetter(_p, "anchorX", _p._getAnchorX, _p._setAnchorX);
- _p.anchorY;
- cc.defineGetterSetter(_p, "anchorY", _p._getAnchorY, _p._setAnchorY);
- _p.skewX;
- cc.defineGetterSetter(_p, "skewX", _p.getSkewX, _p.setSkewX);
- _p.skewY;
- cc.defineGetterSetter(_p, "skewY", _p.getSkewY, _p.setSkewY);
- _p.zIndex;
- cc.defineGetterSetter(_p, "zIndex", _p.getLocalZOrder, _p.setLocalZOrder);
- _p.vertexZ;
- cc.defineGetterSetter(_p, "vertexZ", _p.getVertexZ, _p.setVertexZ);
- _p.rotation;
- cc.defineGetterSetter(_p, "rotation", _p.getRotation, _p.setRotation);
- _p.rotationX;
- cc.defineGetterSetter(_p, "rotationX", _p.getRotationX, _p.setRotationX);
- _p.rotationY;
- cc.defineGetterSetter(_p, "rotationY", _p.getRotationY, _p.setRotationY);
- _p.scale;
- cc.defineGetterSetter(_p, "scale", _p.getScale, _p.setScale);
- _p.scaleX;
- cc.defineGetterSetter(_p, "scaleX", _p.getScaleX, _p.setScaleX);
- _p.scaleY;
- cc.defineGetterSetter(_p, "scaleY", _p.getScaleY, _p.setScaleY);
- _p.children;
- cc.defineGetterSetter(_p, "children", _p.getChildren);
- _p.childrenCount;
- cc.defineGetterSetter(_p, "childrenCount", _p.getChildrenCount);
- _p.parent;
- cc.defineGetterSetter(_p, "parent", _p.getParent, _p.setParent);
- _p.visible;
- cc.defineGetterSetter(_p, "visible", _p.isVisible, _p.setVisible);
- _p.running;
- cc.defineGetterSetter(_p, "running", _p.isRunning);
- _p.ignoreAnchor;
- cc.defineGetterSetter(_p, "ignoreAnchor", _p.isIgnoreAnchorPointForPosition, _p.ignoreAnchorPointForPosition);
- _p.tag;
- _p.userData;
- _p.userObject;
- _p.arrivalOrder;
- _p.actionManager;
- cc.defineGetterSetter(_p, "actionManager", _p.getActionManager, _p.setActionManager);
- _p.scheduler;
- cc.defineGetterSetter(_p, "scheduler", _p.getScheduler, _p.setScheduler);
- _p.shaderProgram;
- cc.defineGetterSetter(_p, "shaderProgram", _p.getShaderProgram, _p.setShaderProgram);
- _p.opacity;
- cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
- _p.opacityModifyRGB;
- cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB);
- _p.cascadeOpacity;
- cc.defineGetterSetter(_p, "cascadeOpacity", _p.isCascadeOpacityEnabled, _p.setCascadeOpacityEnabled);
- _p.color;
- cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
- _p.cascadeColor;
- cc.defineGetterSetter(_p, "cascadeColor", _p.isCascadeColorEnabled, _p.setCascadeColorEnabled);
- };
- cc.NODE_TAG_INVALID = -1;
- cc.s_globalOrderOfArrival = 1;
- cc.Node = cc.Class.extend({
- _localZOrder: 0,
- _globalZOrder: 0,
- _vertexZ: 0.0,
- _customZ: NaN,
- _rotationX: 0,
- _rotationY: 0.0,
- _scaleX: 1.0,
- _scaleY: 1.0,
- _position: null,
- _normalizedPosition:null,
- _usingNormalizedPosition: false,
- _normalizedPositionDirty: false,
- _skewX: 0.0,
- _skewY: 0.0,
- _children: null,
- _visible: true,
- _anchorPoint: null,
- _contentSize: null,
- _running: false,
- _parent: null,
- _ignoreAnchorPointForPosition: false,
- tag: cc.NODE_TAG_INVALID,
- userData: null,
- userObject: null,
- _reorderChildDirty: false,
- _shaderProgram: null,
- arrivalOrder: 0,
- _actionManager: null,
- _scheduler: null,
- _eventDispatcher: null,
- _additionalTransformDirty: false,
- _additionalTransform: null,
- _componentContainer: null,
- _isTransitionFinished: false,
- _className: "Node",
- _showNode: false,
- _name: "",
- _realOpacity: 255,
- _realColor: null,
- _cascadeColorEnabled: false,
- _cascadeOpacityEnabled: false,
- _renderCmd:null,
- ctor: function(){
- this._initNode();
- this._initRendererCmd();
- },
- _initNode: function () {
- var _t = this;
- _t._anchorPoint = cc.p(0, 0);
- _t._contentSize = cc.size(0, 0);
- _t._position = cc.p(0, 0);
- _t._normalizedPosition = cc.p(0,0);
- _t._children = [];
- var director = cc.director;
- _t._actionManager = director.getActionManager();
- _t._scheduler = director.getScheduler();
- _t._additionalTransform = cc.affineTransformMakeIdentity();
- if (cc.ComponentContainer) {
- _t._componentContainer = new cc.ComponentContainer(_t);
- }
- this._realOpacity = 255;
- this._realColor = cc.color(255, 255, 255, 255);
- this._cascadeColorEnabled = false;
- this._cascadeOpacityEnabled = false;
- },
- init: function () {
- return true;
- },
- _arrayMakeObjectsPerformSelector: function (array, callbackType) {
- if (!array || array.length === 0)
- return;
- var i, len = array.length, node;
- var nodeCallbackType = cc.Node._stateCallbackType;
- switch (callbackType) {
- case nodeCallbackType.onEnter:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.onEnter();
- }
- break;
- case nodeCallbackType.onExit:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.onExit();
- }
- break;
- case nodeCallbackType.onEnterTransitionDidFinish:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.onEnterTransitionDidFinish();
- }
- break;
- case nodeCallbackType.cleanup:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.cleanup();
- }
- break;
- case nodeCallbackType.updateTransform:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.updateTransform();
- }
- break;
- case nodeCallbackType.onExitTransitionDidStart:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.onExitTransitionDidStart();
- }
- break;
- case nodeCallbackType.sortAllChildren:
- for (i = 0; i < len; i++) {
- node = array[i];
- if (node)
- node.sortAllChildren();
- }
- break;
- default :
- cc.assert(0, cc._LogInfos.Node__arrayMakeObjectsPerformSelector);
- break;
- }
- },
- attr: function (attrs) {
- for (var key in attrs) {
- this[key] = attrs[key];
- }
- },
- getSkewX: function () {
- return this._skewX;
- },
- setSkewX: function (newSkewX) {
- this._skewX = newSkewX;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getSkewY: function () {
- return this._skewY;
- },
- setSkewY: function (newSkewY) {
- this._skewY = newSkewY;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- setLocalZOrder: function (localZOrder) {
- this._localZOrder = localZOrder;
- if (this._parent)
- this._parent.reorderChild(this, localZOrder);
- cc.eventManager._setDirtyForNode(this);
- },
- _setLocalZOrder: function (localZOrder) {
- this._localZOrder = localZOrder;
- },
- getLocalZOrder: function () {
- return this._localZOrder;
- },
- getZOrder: function () {
- cc.log(cc._LogInfos.Node_getZOrder);
- return this.getLocalZOrder();
- },
- setZOrder: function (z) {
- cc.log(cc._LogInfos.Node_setZOrder);
- this.setLocalZOrder(z);
- },
- setGlobalZOrder: function (globalZOrder) {
- if (this._globalZOrder !== globalZOrder) {
- this._globalZOrder = globalZOrder;
- cc.eventManager._setDirtyForNode(this);
- }
- },
- getGlobalZOrder: function () {
- return this._globalZOrder;
- },
- getVertexZ: function () {
- return this._vertexZ;
- },
- setVertexZ: function (Var) {
- this._customZ = this._vertexZ = Var;
- },
- getRotation: function () {
- if (this._rotationX !== this._rotationY)
- cc.log(cc._LogInfos.Node_getRotation);
- return this._rotationX;
- },
- setRotation: function (newRotation) {
- this._rotationX = this._rotationY = newRotation;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getRotationX: function () {
- return this._rotationX;
- },
- setRotationX: function (rotationX) {
- this._rotationX = rotationX;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getRotationY: function () {
- return this._rotationY;
- },
- setRotationY: function (rotationY) {
- this._rotationY = rotationY;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getScale: function () {
- if (this._scaleX !== this._scaleY)
- cc.log(cc._LogInfos.Node_getScale);
- return this._scaleX;
- },
- setScale: function (scale, scaleY) {
- this._scaleX = scale;
- this._scaleY = (scaleY || scaleY === 0) ? scaleY : scale;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getScaleX: function () {
- return this._scaleX;
- },
- setScaleX: function (newScaleX) {
- this._scaleX = newScaleX;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getScaleY: function () {
- return this._scaleY;
- },
- setScaleY: function (newScaleY) {
- this._scaleY = newScaleY;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- setPosition: function (newPosOrxValue, yValue) {
- var locPosition = this._position;
- if (yValue === undefined) {
- if(locPosition.x === newPosOrxValue.x && locPosition.y === newPosOrxValue.y)
- return;
- locPosition.x = newPosOrxValue.x;
- locPosition.y = newPosOrxValue.y;
- } else {
- if(locPosition.x === newPosOrxValue && locPosition.y === yValue)
- return;
- locPosition.x = newPosOrxValue;
- locPosition.y = yValue;
- }
- this._usingNormalizedPosition = false;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- setNormalizedPosition: function(posOrX, y){
- var locPosition = this._normalizedPosition;
- if (y === undefined) {
- locPosition.x = posOrX.x;
- locPosition.y = posOrX.y;
- } else {
- locPosition.x = posOrX;
- locPosition.y = y;
- }
- this._normalizedPositionDirty = this._usingNormalizedPosition = true;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getPosition: function () {
- return cc.p(this._position);
- },
- getNormalizedPosition: function(){
- return cc.p(this._normalizedPosition);
- },
- getPositionX: function () {
- return this._position.x;
- },
- setPositionX: function (x) {
- this._position.x = x;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getPositionY: function () {
- return this._position.y;
- },
- setPositionY: function (y) {
- this._position.y = y;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getChildrenCount: function () {
- return this._children.length;
- },
- getChildren: function () {
- return this._children;
- },
- isVisible: function () {
- return this._visible;
- },
- setVisible: function (visible) {
- if(this._visible !== visible){
- this._visible = visible;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- cc.renderer.childrenOrderDirty = true;
- }
- },
- getAnchorPoint: function () {
- return cc.p(this._anchorPoint);
- },
- setAnchorPoint: function (point, y) {
- var locAnchorPoint = this._anchorPoint;
- if (y === undefined) {
- if ((point.x === locAnchorPoint.x) && (point.y === locAnchorPoint.y))
- return;
- locAnchorPoint.x = point.x;
- locAnchorPoint.y = point.y;
- } else {
- if ((point === locAnchorPoint.x) && (y === locAnchorPoint.y))
- return;
- locAnchorPoint.x = point;
- locAnchorPoint.y = y;
- }
- this._renderCmd._updateAnchorPointInPoint();
- },
- _getAnchorX: function () {
- return this._anchorPoint.x;
- },
- _setAnchorX: function (x) {
- if (this._anchorPoint.x === x) return;
- this._anchorPoint.x = x;
- this._renderCmd._updateAnchorPointInPoint();
- },
- _getAnchorY: function () {
- return this._anchorPoint.y;
- },
- _setAnchorY: function (y) {
- if (this._anchorPoint.y === y) return;
- this._anchorPoint.y = y;
- this._renderCmd._updateAnchorPointInPoint();
- },
- getAnchorPointInPoints: function () {
- return this._renderCmd.getAnchorPointInPoints();
- },
- _getWidth: function () {
- return this._contentSize.width;
- },
- _setWidth: function (width) {
- this._contentSize.width = width;
- this._renderCmd._updateAnchorPointInPoint();
- },
- _getHeight: function () {
- return this._contentSize.height;
- },
- _setHeight: function (height) {
- this._contentSize.height = height;
- this._renderCmd._updateAnchorPointInPoint();
- },
- getContentSize: function () {
- return cc.size(this._contentSize);
- },
- setContentSize: function (size, height) {
- var locContentSize = this._contentSize;
- if (height === undefined) {
- if ((size.width === locContentSize.width) && (size.height === locContentSize.height))
- return;
- locContentSize.width = size.width;
- locContentSize.height = size.height;
- } else {
- if ((size === locContentSize.width) && (height === locContentSize.height))
- return;
- locContentSize.width = size;
- locContentSize.height = height;
- }
- this._renderCmd._updateAnchorPointInPoint();
- },
- isRunning: function () {
- return this._running;
- },
- getParent: function () {
- return this._parent;
- },
- setParent: function (parent) {
- this._parent = parent;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- isIgnoreAnchorPointForPosition: function () {
- return this._ignoreAnchorPointForPosition;
- },
- ignoreAnchorPointForPosition: function (newValue) {
- if (newValue !== this._ignoreAnchorPointForPosition) {
- this._ignoreAnchorPointForPosition = newValue;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- }
- },
- getTag: function () {
- return this.tag;
- },
- setTag: function (tag) {
- this.tag = tag;
- },
- setName: function(name){
- this._name = name;
- },
- getName: function(){
- return this._name;
- },
- getUserData: function () {
- return this.userData;
- },
- setUserData: function (Var) {
- this.userData = Var;
- },
- getUserObject: function () {
- return this.userObject;
- },
- setUserObject: function (newValue) {
- if (this.userObject !== newValue)
- this.userObject = newValue;
- },
- getOrderOfArrival: function () {
- return this.arrivalOrder;
- },
- setOrderOfArrival: function (Var) {
- this.arrivalOrder = Var;
- },
- getActionManager: function () {
- if (!this._actionManager)
- this._actionManager = cc.director.getActionManager();
- return this._actionManager;
- },
- setActionManager: function (actionManager) {
- if (this._actionManager !== actionManager) {
- this.stopAllActions();
- this._actionManager = actionManager;
- }
- },
- getScheduler: function () {
- if (!this._scheduler)
- this._scheduler = cc.director.getScheduler();
- return this._scheduler;
- },
- setScheduler: function (scheduler) {
- if (this._scheduler !== scheduler) {
- this.unscheduleAllCallbacks();
- this._scheduler = scheduler;
- }
- },
- boundingBox: function(){
- cc.log(cc._LogInfos.Node_boundingBox);
- return this.getBoundingBox();
- },
- getBoundingBox: function () {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- return cc._rectApplyAffineTransformIn(rect, this.getNodeToParentTransform());
- },
- cleanup: function () {
- this.stopAllActions();
- this.unscheduleAllCallbacks();
- cc.eventManager.removeListeners(this);
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.cleanup);
- },
- getChildByTag: function (aTag) {
- var __children = this._children;
- if (__children !== null) {
- for (var i = 0; i < __children.length; i++) {
- var node = __children[i];
- if (node && node.tag === aTag)
- return node;
- }
- }
- return null;
- },
- getChildByName: function(name){
- if(!name){
- cc.log("Invalid name");
- return null;
- }
- var locChildren = this._children;
- for(var i = 0, len = locChildren.length; i < len; i++){
- if(locChildren[i]._name === name)
- return locChildren[i];
- }
- return null;
- },
- addChild: function (child, localZOrder, tag) {
- localZOrder = localZOrder === undefined ? child._localZOrder : localZOrder;
- var name, setTag = false;
- if(cc.isUndefined(tag)){
- tag = undefined;
- name = child._name;
- } else if(cc.isString(tag)){
- name = tag;
- tag = undefined;
- } else if(cc.isNumber(tag)){
- setTag = true;
- name = "";
- }
- cc.assert(child, cc._LogInfos.Node_addChild_3);
- cc.assert(child._parent === null, "child already added. It can't be added again");
- this._addChildHelper(child, localZOrder, tag, name, setTag);
- },
- _addChildHelper: function(child, localZOrder, tag, name, setTag){
- if(!this._children)
- this._children = [];
- this._insertChild(child, localZOrder);
- if(setTag)
- child.setTag(tag);
- else
- child.setName(name);
- child.setParent(this);
- child.setOrderOfArrival(cc.s_globalOrderOfArrival++);
- if( this._running ){
- child.onEnter();
- if (this._isTransitionFinished)
- child.onEnterTransitionDidFinish();
- }
- child._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- if (this._cascadeColorEnabled)
- child._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty);
- if (this._cascadeOpacityEnabled)
- child._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.opacityDirty);
- },
- removeFromParent: function (cleanup) {
- if (this._parent) {
- if (cleanup === undefined)
- cleanup = true;
- this._parent.removeChild(this, cleanup);
- }
- },
- removeFromParentAndCleanup: function (cleanup) {
- cc.log(cc._LogInfos.Node_removeFromParentAndCleanup);
- this.removeFromParent(cleanup);
- },
- removeChild: function (child, cleanup) {
- if (this._children.length === 0)
- return;
- if (cleanup === undefined)
- cleanup = true;
- if (this._children.indexOf(child) > -1)
- this._detachChild(child, cleanup);
- cc.renderer.childrenOrderDirty = true;
- },
- removeChildByTag: function (tag, cleanup) {
- if (tag === cc.NODE_TAG_INVALID)
- cc.log(cc._LogInfos.Node_removeChildByTag);
- var child = this.getChildByTag(tag);
- if (!child)
- cc.log(cc._LogInfos.Node_removeChildByTag_2, tag);
- else
- this.removeChild(child, cleanup);
- },
- removeAllChildrenWithCleanup: function (cleanup) {
- this.removeAllChildren(cleanup);
- },
- removeAllChildren: function (cleanup) {
- var __children = this._children;
- if (__children !== null) {
- if (cleanup === undefined)
- cleanup = true;
- for (var i = 0; i < __children.length; i++) {
- var node = __children[i];
- if (node) {
- if (this._running) {
- node.onExitTransitionDidStart();
- node.onExit();
- }
- if (cleanup)
- node.cleanup();
- node.parent = null;
- node._renderCmd.detachFromParent();
- }
- }
- this._children.length = 0;
- cc.renderer.childrenOrderDirty = true;
- }
- },
- _detachChild: function (child, doCleanup) {
- if (this._running) {
- child.onExitTransitionDidStart();
- child.onExit();
- }
- if (doCleanup)
- child.cleanup();
- child.parent = null;
- child._renderCmd.detachFromParent();
- cc.arrayRemoveObject(this._children, child);
- },
- _insertChild: function (child, z) {
- cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
- this._children.push(child);
- child._setLocalZOrder(z);
- },
- setNodeDirty: function(){
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- reorderChild: function (child, zOrder) {
- cc.assert(child, cc._LogInfos.Node_reorderChild);
- cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
- child.arrivalOrder = cc.s_globalOrderOfArrival;
- cc.s_globalOrderOfArrival++;
- child._setLocalZOrder(zOrder);
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.orderDirty);
- },
- sortAllChildren: function () {
- if (this._reorderChildDirty) {
- var _children = this._children;
- var len = _children.length, i, j, tmp;
- for(i=1; i<len; i++){
- tmp = _children[i];
- j = i - 1;
- while(j >= 0){
- if(tmp._localZOrder < _children[j]._localZOrder){
- _children[j+1] = _children[j];
- }else if(tmp._localZOrder === _children[j]._localZOrder && tmp.arrivalOrder < _children[j].arrivalOrder){
- _children[j+1] = _children[j];
- }else{
- break;
- }
- j--;
- }
- _children[j+1] = tmp;
- }
- this._reorderChildDirty = false;
- }
- },
- draw: function (ctx) {
- },
- transformAncestors: function () {
- if (this._parent !== null) {
- this._parent.transformAncestors();
- this._parent.transform();
- }
- },
- onEnter: function () {
- this._isTransitionFinished = false;
- this._running = true;//should be running before resumeSchedule
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onEnter);
- this.resume();
- },
- onEnterTransitionDidFinish: function () {
- this._isTransitionFinished = true;
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onEnterTransitionDidFinish);
- },
- onExitTransitionDidStart: function () {
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onExitTransitionDidStart);
- },
- onExit: function () {
- this._running = false;
- this.pause();
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.onExit);
- this.removeAllComponents();
- },
- runAction: function (action) {
- cc.assert(action, cc._LogInfos.Node_runAction);
- this.actionManager.addAction(action, this, !this._running);
- return action;
- },
- stopAllActions: function () {
- this.actionManager && this.actionManager.removeAllActionsFromTarget(this);
- },
- stopAction: function (action) {
- this.actionManager.removeAction(action);
- },
- stopActionByTag: function (tag) {
- if (tag === cc.ACTION_TAG_INVALID) {
- cc.log(cc._LogInfos.Node_stopActionByTag);
- return;
- }
- this.actionManager.removeActionByTag(tag, this);
- },
- getActionByTag: function (tag) {
- if (tag === cc.ACTION_TAG_INVALID) {
- cc.log(cc._LogInfos.Node_getActionByTag);
- return null;
- }
- return this.actionManager.getActionByTag(tag, this);
- },
- getNumberOfRunningActions: function () {
- return this.actionManager.numberOfRunningActionsInTarget(this);
- },
- scheduleUpdate: function () {
- this.scheduleUpdateWithPriority(0);
- },
- scheduleUpdateWithPriority: function (priority) {
- this.scheduler.scheduleUpdate(this, priority, !this._running);
- },
- unscheduleUpdate: function () {
- this.scheduler.unscheduleUpdate(this);
- },
- schedule: function (callback, interval, repeat, delay, key) {
- var len = arguments.length;
- if(typeof callback === "function"){
- if(len === 1){
- interval = 0;
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- key = this.__instanceId;
- }else if(len === 2){
- if(typeof interval === "number"){
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- key = this.__instanceId;
- }else{
- key = interval;
- interval = 0;
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- }
- }else if(len === 3){
- if(typeof repeat === "string"){
- key = repeat;
- repeat = cc.REPEAT_FOREVER;
- }else{
- key = this.__instanceId;
- }
- delay = 0;
- }else if(len === 4){
- key = this.__instanceId;
- }
- }else{
- if(len === 1){
- interval = 0;
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- }else if(len === 2){
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- }
- }
- cc.assert(callback, cc._LogInfos.Node_schedule);
- cc.assert(interval >= 0, cc._LogInfos.Node_schedule_2);
- interval = interval || 0;
- repeat = (repeat == null) ? cc.REPEAT_FOREVER : repeat;
- delay = delay || 0;
- this.scheduler.schedule(callback, this, interval, repeat, delay, !this._running, key);
- },
- scheduleOnce: function (callback, delay, key) {
- if(key === undefined)
- key = this.__instanceId;
- this.schedule(callback, 0, 0, delay, key);
- },
- unschedule: function (callback_fn) {
- if (!callback_fn)
- return;
- this.scheduler.unschedule(callback_fn, this);
- },
- unscheduleAllCallbacks: function () {
- this.scheduler.unscheduleAllForTarget(this);
- },
- resumeSchedulerAndActions: function () {
- cc.log(cc._LogInfos.Node_resumeSchedulerAndActions);
- this.resume();
- },
- resume: function () {
- this.scheduler.resumeTarget(this);
- this.actionManager && this.actionManager.resumeTarget(this);
- cc.eventManager.resumeTarget(this);
- },
- pauseSchedulerAndActions: function () {
- cc.log(cc._LogInfos.Node_pauseSchedulerAndActions);
- this.pause();
- },
- pause: function () {
- this.scheduler.pauseTarget(this);
- this.actionManager && this.actionManager.pauseTarget(this);
- cc.eventManager.pauseTarget(this);
- },
- setAdditionalTransform: function (additionalTransform) {
- if(additionalTransform === undefined)
- return this._additionalTransformDirty = false;
- this._additionalTransform = additionalTransform;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- this._additionalTransformDirty = true;
- },
- getParentToNodeTransform: function () {
- return this._renderCmd.getParentToNodeTransform();
- },
- parentToNodeTransform: function () {
- return this.getParentToNodeTransform();
- },
- getNodeToWorldTransform: function () {
- var t = this.getNodeToParentTransform();
- for (var p = this._parent; p !== null; p = p.parent)
- t = cc.affineTransformConcat(t, p.getNodeToParentTransform());
- return t;
- },
- nodeToWorldTransform: function(){
- return this.getNodeToWorldTransform();
- },
- getWorldToNodeTransform: function () {
- return cc.affineTransformInvert(this.getNodeToWorldTransform());
- },
- worldToNodeTransform: function () {
- return this.getWorldToNodeTransform();
- },
- convertToNodeSpace: function (worldPoint) {
- return cc.pointApplyAffineTransform(worldPoint, this.getWorldToNodeTransform());
- },
- convertToWorldSpace: function (nodePoint) {
- nodePoint = nodePoint || cc.p(0,0);
- return cc.pointApplyAffineTransform(nodePoint, this.getNodeToWorldTransform());
- },
- convertToNodeSpaceAR: function (worldPoint) {
- return cc.pSub(this.convertToNodeSpace(worldPoint), this._renderCmd.getAnchorPointInPoints());
- },
- convertToWorldSpaceAR: function (nodePoint) {
- nodePoint = nodePoint || cc.p(0,0);
- var pt = cc.pAdd(nodePoint, this._renderCmd.getAnchorPointInPoints());
- return this.convertToWorldSpace(pt);
- },
- _convertToWindowSpace: function (nodePoint) {
- var worldPoint = this.convertToWorldSpace(nodePoint);
- return cc.director.convertToUI(worldPoint);
- },
- convertTouchToNodeSpace: function (touch) {
- var point = touch.getLocation();
- return this.convertToNodeSpace(point);
- },
- convertTouchToNodeSpaceAR: function (touch) {
- var point = cc.director.convertToGL(touch.getLocation());
- return this.convertToNodeSpaceAR(point);
- },
- update: function (dt) {
- if (this._componentContainer && !this._componentContainer.isEmpty())
- this._componentContainer.visit(dt);
- },
- updateTransform: function () {
- this._arrayMakeObjectsPerformSelector(this._children, cc.Node._stateCallbackType.updateTransform);
- },
- retain: function () {
- },
- release: function () {
- },
- getComponent: function (name) {
- if(this._componentContainer)
- return this._componentContainer.getComponent(name);
- return null;
- },
- addComponent: function (component) {
- if(this._componentContainer)
- this._componentContainer.add(component);
- },
- removeComponent: function (component) {
- if(this._componentContainer)
- return this._componentContainer.remove(component);
- return false;
- },
- removeAllComponents: function () {
- if(this._componentContainer)
- this._componentContainer.removeAll();
- },
- grid: null,
- visit: function(parentCmd){
- this._renderCmd.visit(parentCmd);
- },
- transform: function(parentCmd, recursive){
- this._renderCmd.transform(parentCmd, recursive);
- },
- nodeToParentTransform: function(){
- return this.getNodeToParentTransform();
- },
- getNodeToParentTransform: function(ancestor){
- var t = this._renderCmd.getNodeToParentTransform();
- if(ancestor){
- var T = {a: t.a, b: t.b, c: t.c, d: t.d, tx: t.tx, ty: t.ty};
- for(var p = this._parent; p != null && p != ancestor ; p = p.getParent()){
- cc.affineTransformConcatIn(T, p.getNodeToParentTransform());
- }
- return T;
- }else{
- return t;
- }
- },
- getNodeToParentAffineTransform: function(ancestor){
- return this.getNodeToParentTransform(ancestor);
- },
- getCamera: function () {
- return null;
- },
- getGrid: function () {
- return this.grid;
- },
- setGrid: function (grid) {
- this.grid = grid;
- },
- getShaderProgram: function () {
- return this._renderCmd.getShaderProgram();
- },
- setShaderProgram: function (newShaderProgram) {
- this._renderCmd.setShaderProgram(newShaderProgram);
- },
- getGLServerState: function () {
- return 0;
- },
- setGLServerState: function (state) {
- },
- getBoundingBoxToWorld: function () {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- var trans = this.getNodeToWorldTransform();
- rect = cc.rectApplyAffineTransform(rect, trans);
- if (!this._children)
- return rect;
- var locChildren = this._children;
- for (var i = 0; i < locChildren.length; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- if (childRect)
- rect = cc.rectUnion(rect, childRect);
- }
- }
- return rect;
- },
- _getBoundingBoxToCurrentNode: function (parentTransform) {
- var rect = cc.rect(0, 0, this._contentSize.width, this._contentSize.height);
- var trans = (parentTransform === undefined) ? this.getNodeToParentTransform() : cc.affineTransformConcat(this.getNodeToParentTransform(), parentTransform);
- rect = cc.rectApplyAffineTransform(rect, trans);
- if (!this._children)
- return rect;
- var locChildren = this._children;
- for (var i = 0; i < locChildren.length; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- if (childRect)
- rect = cc.rectUnion(rect, childRect);
- }
- }
- return rect;
- },
- getOpacity: function () {
- return this._realOpacity;
- },
- getDisplayedOpacity: function () {
- return this._renderCmd.getDisplayedOpacity();
- },
- setOpacity: function (opacity) {
- this._realOpacity = opacity;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.opacityDirty);
- },
- updateDisplayedOpacity: function (parentOpacity) {
- this._renderCmd._updateDisplayOpacity(parentOpacity);
- },
- isCascadeOpacityEnabled: function () {
- return this._cascadeOpacityEnabled;
- },
- setCascadeOpacityEnabled: function (cascadeOpacityEnabled) {
- if (this._cascadeOpacityEnabled === cascadeOpacityEnabled)
- return;
- this._cascadeOpacityEnabled = cascadeOpacityEnabled;
- this._renderCmd.setCascadeOpacityEnabledDirty();
- },
- getColor: function () {
- var locRealColor = this._realColor;
- return cc.color(locRealColor.r, locRealColor.g, locRealColor.b, locRealColor.a);
- },
- getDisplayedColor: function () {
- return this._renderCmd.getDisplayedColor();
- },
- setColor: function (color) {
- var locRealColor = this._realColor;
- locRealColor.r = color.r;
- locRealColor.g = color.g;
- locRealColor.b = color.b;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty);
- },
- updateDisplayedColor: function (parentColor) {
- this._renderCmd._updateDisplayColor(parentColor);
- },
- isCascadeColorEnabled: function () {
- return this._cascadeColorEnabled;
- },
- setCascadeColorEnabled: function (cascadeColorEnabled) {
- if (this._cascadeColorEnabled === cascadeColorEnabled)
- return;
- this._cascadeColorEnabled = cascadeColorEnabled;
- this._renderCmd.setCascadeColorEnabledDirty();
- },
- setOpacityModifyRGB: function (opacityValue) {
- },
- isOpacityModifyRGB: function () {
- return false;
- },
- _initRendererCmd: function(){
- this._renderCmd = cc.renderer.getRenderCmd(this);
- },
- _createRenderCmd: function(){
- if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.Node.CanvasRenderCmd(this);
- else
- return new cc.Node.WebGLRenderCmd(this);
- },
- enumerateChildren: function(name, callback){
- cc.assert(name && name.length != 0, "Invalid name");
- cc.assert(callback != null, "Invalid callback function");
- var length = name.length;
- var subStrStartPos = 0;
- var subStrlength = length;
- var searchRecursively = false;
- if(length > 2 && name[0] === "/" && name[1] === "/"){
- searchRecursively = true;
- subStrStartPos = 2;
- subStrlength -= 2;
- }
- var searchFromParent = false;
- if(length > 3 && name[length-3] === "/" && name[length-2] === "." && name[length-1] === "."){
- searchFromParent = true;
- subStrlength -= 3;
- }
- var newName = name.substr(subStrStartPos, subStrlength);
- if(searchFromParent)
- newName = "[[:alnum:]]+/" + newName;
- if(searchRecursively)
- this.doEnumerateRecursive(this, newName, callback);
- else
- this.doEnumerate(newName, callback);
- },
- doEnumerateRecursive: function(node, name, callback){
- var ret = false;
- if(node.doEnumerate(name,callback)){
- ret = true;
- }else{
- var child,
- children = node.getChildren(),
- length = children.length;
- for (var i=0; i<length; i++) {
- child = children[i];
- if (this.doEnumerateRecursive(child, name, callback)) {
- ret = true;
- break;
- }
- }
- }
- },
- doEnumerate: function(name, callback){
- var pos = name.indexOf('/');
- var searchName = name;
- var needRecursive = false;
- if (pos !== -1){
- searchName = name.substr(0, pos);
- needRecursive = true;
- }
- var ret = false;
- var child,
- children = this._children,
- length = children.length;
- for (var i=0; i<length; i++){
- child = children[i];
- if (child._name.indexOf(searchName) !== -1){
- if (!needRecursive){
- if (callback(child)){
- ret = true;
- break;
- }
- }else{
- ret = child.doEnumerate(name, callback);
- if (ret)
- break;
- }
- }
- }
- return ret;
- }
- });
- cc.Node.create = function () {
- return new cc.Node();
- };
- cc.Node._stateCallbackType = {onEnter: 1, onExit: 2, cleanup: 3, onEnterTransitionDidFinish: 4, updateTransform: 5, onExitTransitionDidStart: 6, sortAllChildren: 7};
- cc.assert(cc.isFunction(cc._tmp.PrototypeCCNode), cc._LogInfos.MissingFile, "BaseNodesPropertyDefine.js");
- cc._tmp.PrototypeCCNode();
- delete cc._tmp.PrototypeCCNode;
- cc.CustomRenderCmd = function (target, func) {
- this._needDraw = true;
- this._target = target;
- this._callback = func;
- this.rendering = function (ctx, scaleX, scaleY) {
- if (!this._callback)
- return;
- this._callback.call(this._target, ctx, scaleX, scaleY);
- };
- this.needDraw = function () {
- return this._needDraw;
- };
- };
- cc.Node._dirtyFlags = {
- transformDirty: 1 << 0, visibleDirty: 1 << 1, colorDirty: 1 << 2, opacityDirty: 1 << 3, cacheDirty: 1 << 4,
- orderDirty: 1 << 5, textDirty: 1 << 6, gradientDirty: 1 << 7, textureDirty: 1 << 8,
- contentDirty: 1 << 9,
- COUNT: 10,
- all: (1 << 10) - 1
- };
- cc.Node.RenderCmd = function (renderable) {
- this._dirtyFlag = 1;
- this._savedDirtyFlag = true;
- this._node = renderable;
- this._needDraw = false;
- this._anchorPointInPoints = new cc.Point(0, 0);
- this._transform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._worldTransform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._inverse = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
- this._displayedOpacity = 255;
- this._displayedColor = cc.color(255, 255, 255, 255);
- this._cascadeColorEnabledDirty = false;
- this._cascadeOpacityEnabledDirty = false;
- this._curLevel = -1;
- };
- cc.Node.RenderCmd.prototype = {
- constructor: cc.Node.RenderCmd,
- needDraw: function () {
- return this._needDraw;
- },
- getAnchorPointInPoints: function () {
- return cc.p(this._anchorPointInPoints);
- },
- getDisplayedColor: function () {
- var tmpColor = this._displayedColor;
- return cc.color(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a);
- },
- getDisplayedOpacity: function () {
- return this._displayedOpacity;
- },
- setCascadeColorEnabledDirty: function () {
- this._cascadeColorEnabledDirty = true;
- this.setDirtyFlag(cc.Node._dirtyFlags.colorDirty);
- },
- setCascadeOpacityEnabledDirty: function () {
- this._cascadeOpacityEnabledDirty = true;
- this.setDirtyFlag(cc.Node._dirtyFlags.opacityDirty);
- },
- getParentToNodeTransform: function () {
- if (this._dirtyFlag & cc.Node._dirtyFlags.transformDirty)
- this._inverse = cc.affineTransformInvert(this.getNodeToParentTransform());
- return this._inverse;
- },
- detachFromParent: function () {
- },
- _updateAnchorPointInPoint: function () {
- var locAPP = this._anchorPointInPoints, locSize = this._node._contentSize, locAnchorPoint = this._node._anchorPoint;
- locAPP.x = locSize.width * locAnchorPoint.x;
- locAPP.y = locSize.height * locAnchorPoint.y;
- this.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- setDirtyFlag: function (dirtyFlag) {
- if (this._dirtyFlag === 0 && dirtyFlag !== 0)
- cc.renderer.pushDirtyNode(this);
- this._dirtyFlag |= dirtyFlag;
- },
- getParentRenderCmd: function () {
- if (this._node && this._node._parent && this._node._parent._renderCmd)
- return this._node._parent._renderCmd;
- return null;
- },
- transform: function (parentCmd, recursive) {
- var node = this._node,
- pt = parentCmd ? parentCmd._worldTransform : null,
- t = this._transform,
- wt = this._worldTransform;
- if (node._usingNormalizedPosition && node._parent) {
- var conSize = node._parent._contentSize;
- node._position.x = node._normalizedPosition.x * conSize.width;
- node._position.y = node._normalizedPosition.y * conSize.height;
- node._normalizedPositionDirty = false;
- }
- var hasRotation = node._rotationX || node._rotationY;
- var hasSkew = node._skewX || node._skewY;
- var sx = node._scaleX, sy = node._scaleY;
- var appX = this._anchorPointInPoints.x, appY = this._anchorPointInPoints.y;
- var a = 1, b = 0, c = 0, d = 1;
- if (hasRotation || hasSkew) {
- t.tx = node._position.x;
- t.ty = node._position.y;
- if (hasRotation) {
- var rotationRadiansX = node._rotationX * 0.017453292519943295;
- c = Math.sin(rotationRadiansX);
- d = Math.cos(rotationRadiansX);
- if (node._rotationY === node._rotationX) {
- a = d;
- b = -c;
- }
- else {
- var rotationRadiansY = node._rotationY * 0.017453292519943295;
- a = Math.cos(rotationRadiansY);
- b = -Math.sin(rotationRadiansY);
- }
- }
- t.a = a *= sx;
- t.b = b *= sx;
- t.c = c *= sy;
- t.d = d *= sy;
- if (hasSkew) {
- var skx = Math.tan(node._skewX * Math.PI / 180);
- var sky = Math.tan(node._skewY * Math.PI / 180);
- if (skx === Infinity)
- skx = 99999999;
- if (sky === Infinity)
- sky = 99999999;
- t.a = a + c * sky;
- t.b = b + d * sky;
- t.c = c + a * skx;
- t.d = d + b * skx;
- }
- if (appX || appY) {
- t.tx -= t.a * appX + t.c * appY;
- t.ty -= t.b * appX + t.d * appY;
- if (node._ignoreAnchorPointForPosition) {
- t.tx += appX;
- t.ty += appY;
- }
- }
- if (pt) {
- wt.a = t.a * pt.a + t.b * pt.c;
- wt.b = t.a * pt.b + t.b * pt.d;
- wt.c = t.c * pt.a + t.d * pt.c;
- wt.d = t.c * pt.b + t.d * pt.d;
- wt.tx = pt.a * t.tx + pt.c * t.ty + pt.tx;
- wt.ty = pt.d * t.ty + pt.ty + pt.b * t.tx;
- } else {
- wt.a = t.a;
- wt.b = t.b;
- wt.c = t.c;
- wt.d = t.d;
- wt.tx = t.tx;
- wt.ty = t.ty;
- }
- }
- else {
- t.a = sx;
- t.b = 0;
- t.c = 0;
- t.d = sy;
- t.tx = node._position.x;
- t.ty = node._position.y;
- if (appX || appY) {
- t.tx -= t.a * appX;
- t.ty -= t.d * appY;
- if (node._ignoreAnchorPointForPosition) {
- t.tx += appX;
- t.ty += appY;
- }
- }
- if (pt) {
- wt.a = t.a * pt.a + t.b * pt.c;
- wt.b = t.a * pt.b + t.b * pt.d;
- wt.c = t.c * pt.a + t.d * pt.c;
- wt.d = t.c * pt.b + t.d * pt.d;
- wt.tx = t.tx * pt.a + t.ty * pt.c + pt.tx;
- wt.ty = t.tx * pt.b + t.ty * pt.d + pt.ty;
- } else {
- wt.a = t.a;
- wt.b = t.b;
- wt.c = t.c;
- wt.d = t.d;
- wt.tx = t.tx;
- wt.ty = t.ty;
- }
- }
- if (node._additionalTransformDirty) {
- this._transform = cc.affineTransformConcat(t, node._additionalTransform);
- }
- this._updateCurrentRegions && this._updateCurrentRegions();
- this._notifyRegionStatus && this._notifyRegionStatus(cc.Node.CanvasRenderCmd.RegionStatus.DirtyDouble);
- if (recursive) {
- var locChildren = this._node._children;
- if (!locChildren || locChildren.length === 0)
- return;
- var i, len;
- for (i = 0, len = locChildren.length; i < len; i++) {
- locChildren[i]._renderCmd.transform(this, recursive);
- }
- }
- this._cacheDirty = true;
- },
- getNodeToParentTransform: function () {
- if (this._dirtyFlag & cc.Node._dirtyFlags.transformDirty) {
- this.transform();
- }
- return this._transform;
- },
- visit: function (parentCmd) {
- var node = this._node, renderer = cc.renderer;
- if (!node._visible)
- return;
- parentCmd = parentCmd || this.getParentRenderCmd();
- if (parentCmd)
- this._curLevel = parentCmd._curLevel + 1;
- if (isNaN(node._customZ)) {
- node._vertexZ = renderer.assignedZ;
- renderer.assignedZ += renderer.assignedZStep;
- }
- this._syncStatus(parentCmd);
- this.visitChildren();
- },
- _updateDisplayColor: function (parentColor) {
- var node = this._node;
- var locDispColor = this._displayedColor, locRealColor = node._realColor;
- var i, len, selChildren, item;
- this._notifyRegionStatus && this._notifyRegionStatus(cc.Node.CanvasRenderCmd.RegionStatus.Dirty);
- if (this._cascadeColorEnabledDirty && !node._cascadeColorEnabled) {
- locDispColor.r = locRealColor.r;
- locDispColor.g = locRealColor.g;
- locDispColor.b = locRealColor.b;
- var whiteColor = new cc.Color(255, 255, 255, 255);
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd._updateDisplayColor(whiteColor);
- }
- this._cascadeColorEnabledDirty = false;
- } else {
- if (parentColor === undefined) {
- var locParent = node._parent;
- if (locParent && locParent._cascadeColorEnabled)
- parentColor = locParent.getDisplayedColor();
- else
- parentColor = cc.color.WHITE;
- }
- locDispColor.r = 0 | (locRealColor.r * parentColor.r / 255.0);
- locDispColor.g = 0 | (locRealColor.g * parentColor.g / 255.0);
- locDispColor.b = 0 | (locRealColor.b * parentColor.b / 255.0);
- if (node._cascadeColorEnabled) {
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd) {
- item._renderCmd._updateDisplayColor(locDispColor);
- item._renderCmd._updateColor();
- }
- }
- }
- }
- this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.colorDirty ^ this._dirtyFlag;
- },
- _updateDisplayOpacity: function (parentOpacity) {
- var node = this._node;
- var i, len, selChildren, item;
- this._notifyRegionStatus && this._notifyRegionStatus(cc.Node.CanvasRenderCmd.RegionStatus.Dirty);
- if (this._cascadeOpacityEnabledDirty && !node._cascadeOpacityEnabled) {
- this._displayedOpacity = node._realOpacity;
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd._updateDisplayOpacity(255);
- }
- this._cascadeOpacityEnabledDirty = false;
- } else {
- if (parentOpacity === undefined) {
- var locParent = node._parent;
- parentOpacity = 255;
- if (locParent && locParent._cascadeOpacityEnabled)
- parentOpacity = locParent.getDisplayedOpacity();
- }
- this._displayedOpacity = node._realOpacity * parentOpacity / 255.0;
- if (node._cascadeOpacityEnabled) {
- selChildren = node._children;
- for (i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd) {
- item._renderCmd._updateDisplayOpacity(this._displayedOpacity);
- item._renderCmd._updateColor();
- }
- }
- }
- }
- this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.opacityDirty ^ this._dirtyFlag;
- },
- _syncDisplayColor: function (parentColor) {
- var node = this._node, locDispColor = this._displayedColor, locRealColor = node._realColor;
- if (parentColor === undefined) {
- var locParent = node._parent;
- if (locParent && locParent._cascadeColorEnabled)
- parentColor = locParent.getDisplayedColor();
- else
- parentColor = cc.color.WHITE;
- }
- locDispColor.r = 0 | (locRealColor.r * parentColor.r / 255.0);
- locDispColor.g = 0 | (locRealColor.g * parentColor.g / 255.0);
- locDispColor.b = 0 | (locRealColor.b * parentColor.b / 255.0);
- },
- _syncDisplayOpacity: function (parentOpacity) {
- var node = this._node;
- if (parentOpacity === undefined) {
- var locParent = node._parent;
- parentOpacity = 255;
- if (locParent && locParent._cascadeOpacityEnabled)
- parentOpacity = locParent.getDisplayedOpacity();
- }
- this._displayedOpacity = node._realOpacity * parentOpacity / 255.0;
- },
- _updateColor: function () {
- },
- updateStatus: function () {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- var colorDirty = locFlag & flags.colorDirty,
- opacityDirty = locFlag & flags.opacityDirty;
- this._savedDirtyFlag = this._savedDirtyFlag || locFlag;
- if (colorDirty)
- this._updateDisplayColor();
- if (opacityDirty)
- this._updateDisplayOpacity();
- if (colorDirty || opacityDirty)
- this._updateColor();
- if (locFlag & flags.transformDirty) {
- this.transform(this.getParentRenderCmd(), true);
- this._dirtyFlag = this._dirtyFlag & flags.transformDirty ^ this._dirtyFlag;
- }
- if (locFlag & flags.orderDirty)
- this._dirtyFlag = this._dirtyFlag & flags.orderDirty ^ this._dirtyFlag;
- },
- _syncStatus: function (parentCmd) {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag, parentNode = null;
- if (parentCmd) {
- parentNode = parentCmd._node;
- this._savedDirtyFlag = this._savedDirtyFlag || parentCmd._savedDirtyFlag || locFlag;
- }
- else {
- this._savedDirtyFlag = this._savedDirtyFlag || locFlag;
- }
- if (parentNode && parentNode._cascadeColorEnabled && (parentCmd._dirtyFlag & flags.colorDirty))
- locFlag |= flags.colorDirty;
- if (parentNode && parentNode._cascadeOpacityEnabled && (parentCmd._dirtyFlag & flags.opacityDirty))
- locFlag |= flags.opacityDirty;
- if (parentCmd && (parentCmd._dirtyFlag & flags.transformDirty))
- locFlag |= flags.transformDirty;
- var colorDirty = locFlag & flags.colorDirty,
- opacityDirty = locFlag & flags.opacityDirty;
- this._dirtyFlag = locFlag;
- if (colorDirty)
- this._syncDisplayColor();
- if (opacityDirty)
- this._syncDisplayOpacity();
- if (colorDirty || opacityDirty)
- this._updateColor();
- if (locFlag & flags.transformDirty)
- this.transform(parentCmd);
- if (locFlag & flags.orderDirty)
- this._dirtyFlag = this._dirtyFlag & flags.orderDirty ^ this._dirtyFlag;
- },
- visitChildren: function () {
- var renderer = cc.renderer;
- var node = this._node;
- var i, children = node._children, child;
- var len = children.length;
- if (len > 0) {
- node.sortAllChildren();
- for (i = 0; i < len; i++) {
- child = children[i];
- if (child._localZOrder < 0) {
- child._renderCmd.visit(this);
- }
- else {
- break;
- }
- }
- renderer.pushRenderCommand(this);
- for (; i < len; i++) {
- children[i]._renderCmd.visit(this);
- }
- } else {
- renderer.pushRenderCommand(this);
- }
- this._dirtyFlag = 0;
- }
- };
- cc.Node.RenderCmd.prototype.originVisit = cc.Node.RenderCmd.prototype.visit;
- cc.Node.RenderCmd.prototype.originTransform = cc.Node.RenderCmd.prototype.transform;
- (function () {
- cc.Node.CanvasRenderCmd = function (renderable) {
- cc.Node.RenderCmd.call(this, renderable);
- this._cachedParent = null;
- this._cacheDirty = false;
- this._currentRegion = new cc.Region();
- this._oldRegion = new cc.Region();
- this._regionFlag = 0;
- this._canUseDirtyRegion = false;
- };
- cc.Node.CanvasRenderCmd.RegionStatus = {
- NotDirty: 0,
- Dirty: 1,
- DirtyDouble: 2
- };
- var proto = cc.Node.CanvasRenderCmd.prototype = Object.create(cc.Node.RenderCmd.prototype);
- proto.constructor = cc.Node.CanvasRenderCmd;
- proto._notifyRegionStatus = function (status) {
- if (this._needDraw && this._regionFlag < status) {
- this._regionFlag = status;
- }
- };
- var localBB = new cc.Rect();
- proto.getLocalBB = function () {
- var node = this._node;
- localBB.x = localBB.y = 0;
- localBB.width = node._contentSize.width;
- localBB.height = node._contentSize.height;
- return localBB;
- };
- proto._updateCurrentRegions = function () {
- var temp = this._currentRegion;
- this._currentRegion = this._oldRegion;
- this._oldRegion = temp;
- if (cc.Node.CanvasRenderCmd.RegionStatus.DirtyDouble === this._regionFlag && (!this._currentRegion.isEmpty())) {
- this._oldRegion.union(this._currentRegion);
- }
- this._currentRegion.updateRegion(this.getLocalBB(), this._worldTransform);
- };
- proto.setDirtyFlag = function (dirtyFlag, child) {
- cc.Node.RenderCmd.prototype.setDirtyFlag.call(this, dirtyFlag, child);
- this._setCacheDirty(child);
- if (this._cachedParent)
- this._cachedParent.setDirtyFlag(dirtyFlag, true);
- };
- proto._setCacheDirty = function () {
- if (this._cacheDirty === false) {
- this._cacheDirty = true;
- var cachedP = this._cachedParent;
- cachedP && cachedP !== this && cachedP._setNodeDirtyForCache && cachedP._setNodeDirtyForCache();
- }
- };
- proto._setCachedParent = function (cachedParent) {
- if (this._cachedParent === cachedParent)
- return;
- this._cachedParent = cachedParent;
- var children = this._node._children;
- for (var i = 0, len = children.length; i < len; i++)
- children[i]._renderCmd._setCachedParent(cachedParent);
- };
- proto.detachFromParent = function () {
- this._cachedParent = null;
- var selChildren = this._node._children, item;
- for (var i = 0, len = selChildren.length; i < len; i++) {
- item = selChildren[i];
- if (item && item._renderCmd)
- item._renderCmd.detachFromParent();
- }
- };
- proto.setShaderProgram = function (shaderProgram) {
- };
- proto.getShaderProgram = function () {
- return null;
- };
- cc.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc = function (blendFunc) {
- if (!blendFunc)
- return "source-over";
- else {
- if (( blendFunc.src === cc.SRC_ALPHA && blendFunc.dst === cc.ONE) || (blendFunc.src === cc.ONE && blendFunc.dst === cc.ONE))
- return "lighter";
- else if (blendFunc.src === cc.ZERO && blendFunc.dst === cc.SRC_ALPHA)
- return "destination-in";
- else if (blendFunc.src === cc.ZERO && blendFunc.dst === cc.ONE_MINUS_SRC_ALPHA)
- return "destination-out";
- else
- return "source-over";
- }
- };
- })();
- cc._tmp.PrototypeTexture2D = function () {
- var _c = cc.Texture2D;
- _c.PVRImagesHavePremultipliedAlpha = function (haveAlphaPremultiplied) {
- cc.PVRHaveAlphaPremultiplied_ = haveAlphaPremultiplied;
- };
- _c.PIXEL_FORMAT_RGBA8888 = 2;
- _c.PIXEL_FORMAT_RGB888 = 3;
- _c.PIXEL_FORMAT_RGB565 = 4;
- _c.PIXEL_FORMAT_A8 = 5;
- _c.PIXEL_FORMAT_I8 = 6;
- _c.PIXEL_FORMAT_AI88 = 7;
- _c.PIXEL_FORMAT_RGBA4444 = 8;
- _c.PIXEL_FORMAT_RGB5A1 = 7;
- _c.PIXEL_FORMAT_PVRTC4 = 9;
- _c.PIXEL_FORMAT_PVRTC2 = 10;
- _c.PIXEL_FORMAT_DEFAULT = _c.PIXEL_FORMAT_RGBA8888;
- _c.defaultPixelFormat = _c.PIXEL_FORMAT_DEFAULT;
- var _M = cc.Texture2D._M = {};
- _M[_c.PIXEL_FORMAT_RGBA8888] = "RGBA8888";
- _M[_c.PIXEL_FORMAT_RGB888] = "RGB888";
- _M[_c.PIXEL_FORMAT_RGB565] = "RGB565";
- _M[_c.PIXEL_FORMAT_A8] = "A8";
- _M[_c.PIXEL_FORMAT_I8] = "I8";
- _M[_c.PIXEL_FORMAT_AI88] = "AI88";
- _M[_c.PIXEL_FORMAT_RGBA4444] = "RGBA4444";
- _M[_c.PIXEL_FORMAT_RGB5A1] = "RGB5A1";
- _M[_c.PIXEL_FORMAT_PVRTC4] = "PVRTC4";
- _M[_c.PIXEL_FORMAT_PVRTC2] = "PVRTC2";
- var _B = cc.Texture2D._B = {};
- _B[_c.PIXEL_FORMAT_RGBA8888] = 32;
- _B[_c.PIXEL_FORMAT_RGB888] = 24;
- _B[_c.PIXEL_FORMAT_RGB565] = 16;
- _B[_c.PIXEL_FORMAT_A8] = 8;
- _B[_c.PIXEL_FORMAT_I8] = 8;
- _B[_c.PIXEL_FORMAT_AI88] = 16;
- _B[_c.PIXEL_FORMAT_RGBA4444] = 16;
- _B[_c.PIXEL_FORMAT_RGB5A1] = 16;
- _B[_c.PIXEL_FORMAT_PVRTC4] = 4;
- _B[_c.PIXEL_FORMAT_PVRTC2] = 3;
- var _p = cc.Texture2D.prototype;
- _p.name;
- cc.defineGetterSetter(_p, "name", _p.getName);
- _p.pixelFormat;
- cc.defineGetterSetter(_p, "pixelFormat", _p.getPixelFormat);
- _p.pixelsWidth;
- cc.defineGetterSetter(_p, "pixelsWidth", _p.getPixelsWide);
- _p.pixelsHeight;
- cc.defineGetterSetter(_p, "pixelsHeight", _p.getPixelsHigh);
- _p.width;
- cc.defineGetterSetter(_p, "width", _p._getWidth);
- _p.height;
- cc.defineGetterSetter(_p, "height", _p._getHeight);
- };
- cc._tmp.PrototypeTextureAtlas = function () {
- var _p = cc.TextureAtlas.prototype;
- _p.totalQuads;
- cc.defineGetterSetter(_p, "totalQuads", _p.getTotalQuads);
- _p.capacity;
- cc.defineGetterSetter(_p, "capacity", _p.getCapacity);
- _p.quads;
- cc.defineGetterSetter(_p, "quads", _p.getQuads, _p.setQuads);
- };
- cc._tmp.WebGLTexture2D = function () {
- cc.Texture2D = cc.Class.extend({
- _pVRHaveAlphaPremultiplied: true,
- _pixelFormat: null,
- _pixelsWide: 0,
- _pixelsHigh: 0,
- _name: "",
- _contentSize: null,
- maxS: 0,
- maxT: 0,
- _hasPremultipliedAlpha: false,
- _hasMipmaps: false,
- shaderProgram: null,
- _textureLoaded: false,
- _htmlElementObj: null,
- _webTextureObj: null,
- url: null,
- ctor: function () {
- this._contentSize = cc.size(0, 0);
- this._pixelFormat = cc.Texture2D.defaultPixelFormat;
- },
- releaseTexture: function () {
- if (this._webTextureObj)
- cc._renderContext.deleteTexture(this._webTextureObj);
- cc.loader.release(this.url);
- },
- getPixelFormat: function () {
- return this._pixelFormat;
- },
- getPixelsWide: function () {
- return this._pixelsWide;
- },
- getPixelsHigh: function () {
- return this._pixelsHigh;
- },
- getName: function () {
- return this._webTextureObj;
- },
- getContentSize: function () {
- return cc.size(this._contentSize.width / cc.contentScaleFactor(), this._contentSize.height / cc.contentScaleFactor());
- },
- _getWidth: function () {
- return this._contentSize.width / cc.contentScaleFactor();
- },
- _getHeight: function () {
- return this._contentSize.height / cc.contentScaleFactor();
- },
- getContentSizeInPixels: function () {
- return this._contentSize;
- },
- getMaxS: function () {
- return this.maxS;
- },
- setMaxS: function (maxS) {
- this.maxS = maxS;
- },
- getMaxT: function () {
- return this.maxT;
- },
- setMaxT: function (maxT) {
- this.maxT = maxT;
- },
- getShaderProgram: function () {
- return this.shaderProgram;
- },
- setShaderProgram: function (shaderProgram) {
- this.shaderProgram = shaderProgram;
- },
- hasPremultipliedAlpha: function () {
- return this._hasPremultipliedAlpha;
- },
- hasMipmaps: function () {
- return this._hasMipmaps;
- },
- description: function () {
- var _t = this;
- return "<cc.Texture2D | Name = " + _t._name + " | Dimensions = " + _t._pixelsWide + " x " + _t._pixelsHigh
- + " | Coordinates = (" + _t.maxS + ", " + _t.maxT + ")>";
- },
- releaseData: function (data) {
- data = null;
- },
- keepData: function (data, length) {
- return data;
- },
- initWithData: function (data, pixelFormat, pixelsWide, pixelsHigh, contentSize) {
- var self = this, tex2d = cc.Texture2D;
- var gl = cc._renderContext;
- var format = gl.RGBA, type = gl.UNSIGNED_BYTE;
- var bitsPerPixel = cc.Texture2D._B[pixelFormat];
- var bytesPerRow = pixelsWide * bitsPerPixel / 8;
- if (bytesPerRow % 8 === 0) {
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 8);
- } else if (bytesPerRow % 4 === 0) {
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
- } else if (bytesPerRow % 2 === 0) {
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 2);
- } else {
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
- }
- self._webTextureObj = gl.createTexture();
- cc.glBindTexture2D(self);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- switch (pixelFormat) {
- case tex2d.PIXEL_FORMAT_RGBA8888:
- format = gl.RGBA;
- break;
- case tex2d.PIXEL_FORMAT_RGB888:
- format = gl.RGB;
- break;
- case tex2d.PIXEL_FORMAT_RGBA4444:
- type = gl.UNSIGNED_SHORT_4_4_4_4;
- break;
- case tex2d.PIXEL_FORMAT_RGB5A1:
- type = gl.UNSIGNED_SHORT_5_5_5_1;
- break;
- case tex2d.PIXEL_FORMAT_RGB565:
- type = gl.UNSIGNED_SHORT_5_6_5;
- break;
- case tex2d.PIXEL_FORMAT_AI88:
- format = gl.LUMINANCE_ALPHA;
- break;
- case tex2d.PIXEL_FORMAT_A8:
- format = gl.ALPHA;
- break;
- case tex2d.PIXEL_FORMAT_I8:
- format = gl.LUMINANCE;
- break;
- default:
- cc.assert(0, cc._LogInfos.Texture2D_initWithData);
- }
- gl.texImage2D(gl.TEXTURE_2D, 0, format, pixelsWide, pixelsHigh, 0, format, type, data);
- self._contentSize.width = contentSize.width;
- self._contentSize.height = contentSize.height;
- self._pixelsWide = pixelsWide;
- self._pixelsHigh = pixelsHigh;
- self._pixelFormat = pixelFormat;
- self.maxS = contentSize.width / pixelsWide;
- self.maxT = contentSize.height / pixelsHigh;
- self._hasPremultipliedAlpha = false;
- self._hasMipmaps = false;
- self.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE);
- self._textureLoaded = true;
- return true;
- },
- drawAtPoint: function (point) {
- var self = this;
- var coordinates = [
- 0.0, self.maxT,
- self.maxS, self.maxT,
- 0.0, 0.0,
- self.maxS, 0.0 ],
- gl = cc._renderContext;
- var width = self._pixelsWide * self.maxS,
- height = self._pixelsHigh * self.maxT;
- var vertices = [
- point.x, point.y, 0.0,
- width + point.x, point.y, 0.0,
- point.x, height + point.y, 0.0,
- width + point.x, height + point.y, 0.0 ];
- self._shaderProgram.use();
- self._shaderProgram.setUniformsForBuiltins();
- cc.glBindTexture2D(self);
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION);
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, vertices);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, coordinates);
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
- },
- drawInRect: function (rect) {
- var self = this;
- var coordinates = [
- 0.0, self.maxT,
- self.maxS, self.maxT,
- 0.0, 0.0,
- self.maxS, 0.0];
- var vertices = [ rect.x, rect.y,
- rect.x + rect.width, rect.y,
- rect.x, rect.y + rect.height,
- rect.x + rect.width, rect.y + rect.height ];
- self._shaderProgram.use();
- self._shaderProgram.setUniformsForBuiltins();
- cc.glBindTexture2D(self);
- var gl = cc._renderContext;
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION);
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 2, gl.FLOAT, false, 0, vertices);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 0, coordinates);
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
- },
- initWithImage: function (uiImage) {
- if (uiImage == null) {
- cc.log(cc._LogInfos.Texture2D_initWithImage);
- return false;
- }
- var imageWidth = uiImage.getWidth();
- var imageHeight = uiImage.getHeight();
- var maxTextureSize = cc.configuration.getMaxTextureSize();
- if (imageWidth > maxTextureSize || imageHeight > maxTextureSize) {
- cc.log(cc._LogInfos.Texture2D_initWithImage_2, imageWidth, imageHeight, maxTextureSize, maxTextureSize);
- return false;
- }
- this._textureLoaded = true;
- return this._initPremultipliedATextureWithImage(uiImage, imageWidth, imageHeight);
- },
- initWithElement: function (element) {
- if (!element)
- return;
- this._webTextureObj = cc._renderContext.createTexture();
- this._htmlElementObj = element;
- this._textureLoaded = true;
- this._hasPremultipliedAlpha = true;
- },
- getHtmlElementObj: function () {
- return this._htmlElementObj;
- },
- isLoaded: function () {
- return this._textureLoaded;
- },
- handleLoadedTexture: function (premultiplied) {
- var self = this;
- premultiplied =
- (premultiplied !== undefined)
- ? premultiplied
- : self._hasPremultipliedAlpha;
- if (!cc.game._rendererInitialized)
- return;
- if (!self._htmlElementObj) {
- var img = cc.loader.getRes(self.url);
- if (!img) return;
- self.initWithElement(img);
- }
- if (!self._htmlElementObj.width || !self._htmlElementObj.height)
- return;
- var gl = cc._renderContext;
- cc.glBindTexture2D(self);
- gl.pixelStorei(gl.UNPACK_ALIGNMENT, 4);
- if(premultiplied)
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 1);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, self._htmlElementObj);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- self.shaderProgram = cc.shaderCache.programForKey(cc.SHADER_POSITION_TEXTURE);
- cc.glBindTexture2D(null);
- if(premultiplied)
- gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
- var pixelsWide = self._htmlElementObj.width;
- var pixelsHigh = self._htmlElementObj.height;
- self._pixelsWide = self._contentSize.width = pixelsWide;
- self._pixelsHigh = self._contentSize.height = pixelsHigh;
- self._pixelFormat = cc.Texture2D.PIXEL_FORMAT_RGBA8888;
- self.maxS = 1;
- self.maxT = 1;
- self._hasPremultipliedAlpha = premultiplied;
- self._hasMipmaps = false;
- self.dispatchEvent("load");
- },
- initWithString: function (text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
- cc.log(cc._LogInfos.Texture2D_initWithString);
- return null;
- },
- initWithETCFile: function (file) {
- cc.log(cc._LogInfos.Texture2D_initWithETCFile_2);
- return false;
- },
- initWithPVRFile: function (file) {
- cc.log(cc._LogInfos.Texture2D_initWithPVRFile_2);
- return false;
- },
- initWithPVRTCData: function (data, level, bpp, hasAlpha, length, pixelFormat) {
- cc.log(cc._LogInfos.Texture2D_initWithPVRTCData_2);
- return false;
- },
- setTexParameters: function (texParams, magFilter, wrapS, wrapT) {
- var _t = this;
- var gl = cc._renderContext;
- if(magFilter !== undefined)
- texParams = {minFilter: texParams, magFilter: magFilter, wrapS: wrapS, wrapT: wrapT};
- cc.assert((_t._pixelsWide === cc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === cc.NextPOT(_t._pixelsHigh)) ||
- (texParams.wrapS === gl.CLAMP_TO_EDGE && texParams.wrapT === gl.CLAMP_TO_EDGE),
- "WebGLRenderingContext.CLAMP_TO_EDGE should be used in NPOT textures");
- cc.glBindTexture2D(_t);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texParams.minFilter);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texParams.magFilter);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, texParams.wrapS);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, texParams.wrapT);
- },
- setAntiAliasTexParameters: function () {
- var gl = cc._renderContext;
- cc.glBindTexture2D(this);
- if (!this._hasMipmaps)
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
- else
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
- },
- setAliasTexParameters: function () {
- var gl = cc._renderContext;
- cc.glBindTexture2D(this);
- if (!this._hasMipmaps)
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
- else
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_NEAREST);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
- },
- generateMipmap: function () {
- var _t = this;
- cc.assert(_t._pixelsWide === cc.NextPOT(_t._pixelsWide) && _t._pixelsHigh === cc.NextPOT(_t._pixelsHigh), "Mimpap texture only works in POT textures");
- cc.glBindTexture2D(_t);
- cc._renderContext.generateMipmap(cc._renderContext.TEXTURE_2D);
- _t._hasMipmaps = true;
- },
- stringForFormat: function () {
- return cc.Texture2D._M[this._pixelFormat];
- },
- bitsPerPixelForFormat: function (format) {//TODO I want to delete the format argument, use this._pixelFormat
- format = format || this._pixelFormat;
- var value = cc.Texture2D._B[format];
- if (value != null) return value;
- cc.log(cc._LogInfos.Texture2D_bitsPerPixelForFormat, format);
- return -1;
- },
- _initPremultipliedATextureWithImage: function (uiImage, width, height) {
- var tex2d = cc.Texture2D;
- var tempData = uiImage.getData();
- var inPixel32 = null;
- var inPixel8 = null;
- var outPixel16 = null;
- var hasAlpha = uiImage.hasAlpha();
- var imageSize = cc.size(uiImage.getWidth(), uiImage.getHeight());
- var pixelFormat = tex2d.defaultPixelFormat;
- var bpp = uiImage.getBitsPerComponent();
- var i;
- if (!hasAlpha) {
- if (bpp >= 8) {
- pixelFormat = tex2d.PIXEL_FORMAT_RGB888;
- } else {
- cc.log(cc._LogInfos.Texture2D__initPremultipliedATextureWithImage);
- pixelFormat = tex2d.PIXEL_FORMAT_RGB565;
- }
- }
- var length = width * height;
- if (pixelFormat === tex2d.PIXEL_FORMAT_RGB565) {
- if (hasAlpha) {
- tempData = new Uint16Array(width * height);
- inPixel32 = uiImage.getData();
- for (i = 0; i < length; ++i) {
- tempData[i] =
- ((((inPixel32[i] >> 0) & 0xFF) >> 3) << 11) |
- ((((inPixel32[i] >> 8) & 0xFF) >> 2) << 5) |
- ((((inPixel32[i] >> 16) & 0xFF) >> 3) << 0);
- }
- } else {
- tempData = new Uint16Array(width * height);
- inPixel8 = uiImage.getData();
- for (i = 0; i < length; ++i) {
- tempData[i] =
- (((inPixel8[i] & 0xFF) >> 3) << 11) |
- (((inPixel8[i] & 0xFF) >> 2) << 5) |
- (((inPixel8[i] & 0xFF) >> 3) << 0);
- }
- }
- } else if (pixelFormat === tex2d.PIXEL_FORMAT_RGBA4444) {
- tempData = new Uint16Array(width * height);
- inPixel32 = uiImage.getData();
- for (i = 0; i < length; ++i) {
- tempData[i] =
- ((((inPixel32[i] >> 0) & 0xFF) >> 4) << 12) |
- ((((inPixel32[i] >> 8) & 0xFF) >> 4) << 8) |
- ((((inPixel32[i] >> 16) & 0xFF) >> 4) << 4) |
- ((((inPixel32[i] >> 24) & 0xFF) >> 4) << 0);
- }
- } else if (pixelFormat === tex2d.PIXEL_FORMAT_RGB5A1) {
- tempData = new Uint16Array(width * height);
- inPixel32 = uiImage.getData();
- for (i = 0; i < length; ++i) {
- tempData[i] =
- ((((inPixel32[i] >> 0) & 0xFF) >> 3) << 11) |
- ((((inPixel32[i] >> 8) & 0xFF) >> 3) << 6) |
- ((((inPixel32[i] >> 16) & 0xFF) >> 3) << 1) |
- ((((inPixel32[i] >> 24) & 0xFF) >> 7) << 0);
- }
- } else if (pixelFormat === tex2d.PIXEL_FORMAT_A8) {
- tempData = new Uint8Array(width * height);
- inPixel32 = uiImage.getData();
- for (i = 0; i < length; ++i) {
- tempData[i] = (inPixel32 >> 24) & 0xFF;
- }
- }
- if (hasAlpha && pixelFormat === tex2d.PIXEL_FORMAT_RGB888) {
- inPixel32 = uiImage.getData();
- tempData = new Uint8Array(width * height * 3);
- for (i = 0; i < length; ++i) {
- tempData[i * 3] = (inPixel32 >> 0) & 0xFF;
- tempData[i * 3 + 1] = (inPixel32 >> 8) & 0xFF;
- tempData[i * 3 + 2] = (inPixel32 >> 16) & 0xFF;
- }
- }
- this.initWithData(tempData, pixelFormat, width, height, imageSize);
- if (tempData != uiImage.getData())
- tempData = null;
- this._hasPremultipliedAlpha = uiImage.isPremultipliedAlpha();
- return true;
- },
- addLoadedEventListener: function (callback, target) {
- this.addEventListener("load", callback, target);
- },
- removeLoadedEventListener: function (target) {
- this.removeEventTarget("load", target);
- }
- });
- };
- cc._tmp.WebGLTextureAtlas = function () {
- var _p = cc.TextureAtlas.prototype;
- _p._setupVBO = function () {
- var _t = this;
- var gl = cc._renderContext;
- _t._buffersVBO[0] = gl.createBuffer();
- _t._buffersVBO[1] = gl.createBuffer();
- _t._quadsWebBuffer = gl.createBuffer();
- _t._mapBuffers();
- };
- _p._mapBuffers = function () {
- var _t = this;
- var gl = cc._renderContext;
- gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer);
- gl.bufferData(gl.ARRAY_BUFFER, _t._quadsArrayBuffer, gl.DYNAMIC_DRAW);
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]);
- gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, _t._indices, gl.STATIC_DRAW);
- };
- _p.drawNumberOfQuads = function (n, start) {
- var _t = this;
- start = start || 0;
- if (0 === n || !_t.texture || !_t.texture.isLoaded())
- return;
- var gl = cc._renderContext;
- cc.glBindTexture2D(_t.texture);
- gl.bindBuffer(gl.ARRAY_BUFFER, _t._quadsWebBuffer);
- if (_t.dirty){
- gl.bufferData(gl.ARRAY_BUFFER, _t._quadsArrayBuffer, gl.DYNAMIC_DRAW);
- _t.dirty = false;
- }
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_POSITION);
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_COLOR);
- gl.enableVertexAttribArray(cc.VERTEX_ATTRIB_TEX_COORDS);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_POSITION, 3, gl.FLOAT, false, 24, 0);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_COLOR, 4, gl.UNSIGNED_BYTE, true, 24, 12);
- gl.vertexAttribPointer(cc.VERTEX_ATTRIB_TEX_COORDS, 2, gl.FLOAT, false, 24, 16);
- gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _t._buffersVBO[1]);
- if (cc.TEXTURE_ATLAS_USE_TRIANGLE_STRIP)
- gl.drawElements(gl.TRIANGLE_STRIP, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT);
- else
- gl.drawElements(gl.TRIANGLES, n * 6, gl.UNSIGNED_SHORT, start * 6 * _t._indices.BYTES_PER_ELEMENT);
- cc.g_NumberOfDraws++;
- };
- };
- cc._tmp.WebGLTextureCache = function () {
- var _p = cc.textureCache;
- _p.handleLoadedTexture = function (url) {
- var locTexs = this._textures, tex, ext;
- if (!cc.game._rendererInitialized) {
- locTexs = this._loadedTexturesBefore;
- }
- tex = locTexs[url];
- if (!tex) {
- tex = locTexs[url] = new cc.Texture2D();
- tex.url = url;
- }
- ext = cc.path.extname(url);
- if (ext === ".png") {
- tex.handleLoadedTexture(true);
- }
- else {
- tex.handleLoadedTexture();
- }
- };
- _p.addImage = function (url, cb, target) {
- cc.assert(url, cc._LogInfos.Texture2D_addImage_2);
- var locTexs = this._textures;
- if (!cc.game._rendererInitialized) {
- locTexs = this._loadedTexturesBefore;
- }
- var tex = locTexs[url] || locTexs[cc.loader._getAliase(url)];
- if (tex) {
- if(tex.isLoaded()) {
- cb && cb.call(target, tex);
- return tex;
- }
- else
- {
- tex.addEventListener("load", function(){
- cb && cb.call(target, tex);
- }, target);
- return tex;
- }
- }
- tex = locTexs[url] = new cc.Texture2D();
- tex.url = url;
- var basePath = cc.loader.getBasePath ? cc.loader.getBasePath() : cc.loader.resPath;
- cc.loader.loadImg(cc.path.join(basePath || "", url), function (err, img) {
- if (err)
- return cb && cb.call(target, err);
- if (!cc.loader.cache[url]) {
- cc.loader.cache[url] = img;
- }
- cc.textureCache.handleLoadedTexture(url);
- var texResult = locTexs[url];
- cb && cb.call(target, texResult);
- });
- return tex;
- };
- _p.addImageAsync = _p.addImage;
- _p = null;
- };
- cc.ALIGN_CENTER = 0x33;
- cc.ALIGN_TOP = 0x13;
- cc.ALIGN_TOP_RIGHT = 0x12;
- cc.ALIGN_RIGHT = 0x32;
- cc.ALIGN_BOTTOM_RIGHT = 0x22;
- cc.ALIGN_BOTTOM = 0x23;
- cc.ALIGN_BOTTOM_LEFT = 0x21;
- cc.ALIGN_LEFT = 0x31;
- cc.ALIGN_TOP_LEFT = 0x11;
- cc.PVRHaveAlphaPremultiplied_ = false;
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if(cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- var proto = {
- _contentSize: null,
- _textureLoaded: false,
- _htmlElementObj: null,
- url: null,
- _pattern: null,
- ctor: function () {
- this._contentSize = cc.size(0, 0);
- this._textureLoaded = false;
- this._htmlElementObj = null;
- this._pattern = "";
- },
- getPixelsWide: function () {
- return this._contentSize.width;
- },
- getPixelsHigh: function () {
- return this._contentSize.height;
- },
- getContentSize: function () {
- var locScaleFactor = cc.contentScaleFactor();
- return cc.size(this._contentSize.width / locScaleFactor, this._contentSize.height / locScaleFactor);
- },
- _getWidth: function () {
- return this._contentSize.width / cc.contentScaleFactor();
- },
- _getHeight: function () {
- return this._contentSize.height / cc.contentScaleFactor();
- },
- getContentSizeInPixels: function () {
- return this._contentSize;
- },
- initWithElement: function (element) {
- if (!element)
- return;
- this._htmlElementObj = element;
- this._contentSize.width = element.width;
- this._contentSize.height = element.height;
- this._textureLoaded = true;
- },
- getHtmlElementObj: function () {
- return this._htmlElementObj;
- },
- isLoaded: function () {
- return this._textureLoaded;
- },
- handleLoadedTexture: function () {
- var self = this;
- if (self._textureLoaded) return;
- if (!self._htmlElementObj) {
- var img = cc.loader.getRes(self.url);
- if (!img) return;
- self.initWithElement(img);
- }
- var locElement = self._htmlElementObj;
- self._contentSize.width = locElement.width;
- self._contentSize.height = locElement.height;
- self.dispatchEvent("load");
- },
- description: function () {
- return "<cc.Texture2D | width = " + this._contentSize.width + " height " + this._contentSize.height + ">";
- },
- initWithData: function (data, pixelFormat, pixelsWide, pixelsHigh, contentSize) {
- return false;
- },
- initWithImage: function (uiImage) {
- return false;
- },
- initWithString: function (text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
- return false;
- },
- releaseTexture: function () {
- cc.loader.release(this.url);
- },
- getName: function () {
- return null;
- },
- getMaxS: function () {
- return 1;
- },
- setMaxS: function (maxS) {
- },
- getMaxT: function () {
- return 1;
- },
- setMaxT: function (maxT) {
- },
- getPixelFormat: function () {
- return null;
- },
- getShaderProgram: function () {
- return null;
- },
- setShaderProgram: function (shaderProgram) {
- },
- hasPremultipliedAlpha: function () {
- return false;
- },
- hasMipmaps: function () {
- return false;
- },
- releaseData: function (data) {
- data = null;
- },
- keepData: function (data, length) {
- return data;
- },
- drawAtPoint: function (point) {
- },
- drawInRect: function (rect) {
- },
- initWithETCFile: function (file) {
- cc.log(cc._LogInfos.Texture2D_initWithETCFile);
- return false;
- },
- initWithPVRFile: function (file) {
- cc.log(cc._LogInfos.Texture2D_initWithPVRFile);
- return false;
- },
- initWithPVRTCData: function (data, level, bpp, hasAlpha, length, pixelFormat) {
- cc.log(cc._LogInfos.Texture2D_initWithPVRTCData);
- return false;
- },
- setTexParameters: function (texParams, magFilter, wrapS, wrapT) {
- if(magFilter !== undefined)
- texParams = {minFilter: texParams, magFilter: magFilter, wrapS: wrapS, wrapT: wrapT};
- if(texParams.wrapS === cc.REPEAT && texParams.wrapT === cc.REPEAT){
- this._pattern = "repeat";
- return;
- }
- if(texParams.wrapS === cc.REPEAT ){
- this._pattern = "repeat-x";
- return;
- }
- if(texParams.wrapT === cc.REPEAT){
- this._pattern = "repeat-y";
- return;
- }
- this._pattern = "";
- },
- setAntiAliasTexParameters: function () {
- },
- setAliasTexParameters: function () {
- },
- generateMipmap: function () {
- },
- stringForFormat: function () {
- return "";
- },
- bitsPerPixelForFormat: function (format) {
- return -1;
- },
- addLoadedEventListener: function (callback, target) {
- this.addEventListener("load", callback, target);
- },
- removeLoadedEventListener: function (target) {
- this.removeEventTarget("load", target);
- },
- _generateColorTexture: function(){},
- _generateTextureCacheForColor: function(){
- if (this.channelCache)
- return this.channelCache;
- var textureCache = [
- document.createElement("canvas"),
- document.createElement("canvas"),
- document.createElement("canvas"),
- document.createElement("canvas")
- ];
- renderToCache(this._htmlElementObj, textureCache);
- return this.channelCache = textureCache;
- },
- _grayElementObj: null,
- _backupElement: null,
- _isGray: false,
- _switchToGray: function(toGray){
- if(!this._textureLoaded || this._isGray === toGray)
- return;
- this._isGray = toGray;
- if(this._isGray){
- this._backupElement = this._htmlElementObj;
- if(!this._grayElementObj)
- this._grayElementObj = cc.Texture2D._generateGrayTexture(this._htmlElementObj);
- this._htmlElementObj = this._grayElementObj;
- } else {
- if(this._backupElement !== null)
- this._htmlElementObj = this._backupElement;
- }
- }
- };
- var renderToCache = function(image, cache){
- var w = image.width;
- var h = image.height;
- cache[0].width = w;
- cache[0].height = h;
- cache[1].width = w;
- cache[1].height = h;
- cache[2].width = w;
- cache[2].height = h;
- cache[3].width = w;
- cache[3].height = h;
- var cacheCtx = cache[3].getContext("2d");
- cacheCtx.drawImage(image, 0, 0);
- var pixels = cacheCtx.getImageData(0, 0, w, h).data;
- var ctx;
- for (var rgbI = 0; rgbI < 4; rgbI++) {
- ctx = cache[rgbI].getContext("2d");
- var to = ctx.getImageData(0, 0, w, h);
- var data = to.data;
- for (var i = 0; i < pixels.length; i += 4) {
- data[i ] = (rgbI === 0) ? pixels[i ] : 0;
- data[i + 1] = (rgbI === 1) ? pixels[i + 1] : 0;
- data[i + 2] = (rgbI === 2) ? pixels[i + 2] : 0;
- data[i + 3] = pixels[i + 3];
- }
- ctx.putImageData(to, 0, 0);
- }
- image.onload = null;
- };
- if(cc.sys._supportCanvasNewBlendModes){
- proto._generateColorTexture = function(r, g, b, rect, canvas){
- var onlyCanvas = false;
- if(canvas)
- onlyCanvas = true;
- else
- canvas = document.createElement("canvas");
- var textureImage = this._htmlElementObj;
- if(!rect)
- rect = cc.rect(0, 0, textureImage.width, textureImage.height);
- canvas.width = rect.width;
- canvas.height = rect.height;
- var context = canvas.getContext("2d");
- context.globalCompositeOperation = "source-over";
- context.fillStyle = "rgb(" + (r|0) + "," + (g|0) + "," + (b|0) + ")";
- context.fillRect(0, 0, rect.width, rect.height);
- context.globalCompositeOperation = "multiply";
- context.drawImage(
- textureImage,
- rect.x, rect.y, rect.width, rect.height,
- 0, 0, rect.width, rect.height
- );
- context.globalCompositeOperation = "destination-atop";
- context.drawImage(
- textureImage,
- rect.x, rect.y, rect.width, rect.height,
- 0, 0, rect.width, rect.height
- );
- if(onlyCanvas)
- return canvas;
- var newTexture = new cc.Texture2D();
- newTexture.initWithElement(canvas);
- newTexture.handleLoadedTexture();
- return newTexture;
- };
- }else{
- proto._generateColorTexture = function(r, g, b, rect, canvas){
- var onlyCanvas = false;
- if(canvas)
- onlyCanvas = true;
- else
- canvas = document.createElement("canvas");
- var textureImage = this._htmlElementObj;
- if(!rect)
- rect = cc.rect(0, 0, textureImage.width, textureImage.height);
- var x, y, w, h;
- x = rect.x; y = rect.y; w = rect.width; h = rect.height;
- if(!w || !h)
- return;
- canvas.width = w;
- canvas.height = h;
- var context = canvas.getContext("2d");
- var tintedImgCache = cc.textureCache.getTextureColors(this);
- context.globalCompositeOperation = 'lighter';
- context.drawImage(
- tintedImgCache[3],
- x, y, w, h,
- 0, 0, w, h
- );
- if (r > 0) {
- context.globalAlpha = r / 255;
- context.drawImage(
- tintedImgCache[0],
- x, y, w, h,
- 0, 0, w, h
- );
- }
- if (g > 0) {
- context.globalAlpha = g / 255;
- context.drawImage(
- tintedImgCache[1],
- x, y, w, h,
- 0, 0, w, h
- );
- }
- if (b > 0) {
- context.globalAlpha = b / 255;
- context.drawImage(
- tintedImgCache[2],
- x, y, w, h,
- 0, 0, w, h
- );
- }
- if(onlyCanvas)
- return canvas;
- var newTexture = new cc.Texture2D();
- newTexture.initWithElement(canvas);
- newTexture.handleLoadedTexture();
- return newTexture;
- };
- }
- cc.Texture2D = cc.Class.extend(proto);
- cc.Texture2D._generateGrayTexture = function(texture, rect, renderCanvas){
- if (texture === null)
- return null;
- renderCanvas = renderCanvas || document.createElement("canvas");
- rect = rect || cc.rect(0, 0, texture.width, texture.height);
- renderCanvas.width = rect.width;
- renderCanvas.height = rect.height;
- var context = renderCanvas.getContext("2d");
- context.drawImage(texture, rect.x, rect.y, rect.width, rect.height, 0, 0, rect.width, rect.height);
- var imgData = context.getImageData(0, 0, rect.width, rect.height);
- var data = imgData.data;
- for (var i = 0, len = data.length; i < len; i += 4) {
- data[i] = data[i + 1] = data[i + 2] = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
- }
- context.putImageData(imgData, 0, 0);
- return renderCanvas;
- };
- } else if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
- cc.assert(cc.isFunction(cc._tmp.WebGLTexture2D), cc._LogInfos.MissingFile, "TexturesWebGL.js");
- cc._tmp.WebGLTexture2D();
- delete cc._tmp.WebGLTexture2D;
- }
- cc.EventHelper.prototype.apply(cc.Texture2D.prototype);
- cc.assert(cc.isFunction(cc._tmp.PrototypeTexture2D), cc._LogInfos.MissingFile, "TexturesPropertyDefine.js");
- cc._tmp.PrototypeTexture2D();
- delete cc._tmp.PrototypeTexture2D;
- });
- cc.textureCache = {
- _textures: {},
- _textureColorsCache: {},
- _textureKeySeq: (0 | Math.random() * 1000),
- _loadedTexturesBefore: {},
- _initializingRenderer: function () {
- var selPath;
- var locLoadedTexturesBefore = this._loadedTexturesBefore, locTextures = this._textures;
- for (selPath in locLoadedTexturesBefore) {
- var tex2d = locLoadedTexturesBefore[selPath];
- tex2d.handleLoadedTexture();
- locTextures[selPath] = tex2d;
- }
- this._loadedTexturesBefore = {};
- },
- addPVRTCImage: function (filename) {
- cc.log(cc._LogInfos.textureCache_addPVRTCImage);
- },
- addETCImage: function (filename) {
- cc.log(cc._LogInfos.textureCache_addETCImage);
- },
- description: function () {
- return "<TextureCache | Number of textures = " + this._textures.length + ">";
- },
- textureForKey: function (textureKeyName) {
- cc.log(cc._LogInfos.textureCache_textureForKey);
- return this.getTextureForKey(textureKeyName);
- },
- getTextureForKey: function(textureKeyName){
- return this._textures[textureKeyName] || this._textures[cc.loader._getAliase(textureKeyName)];
- },
- getKeyByTexture: function (texture) {
- for (var key in this._textures) {
- if (this._textures[key] === texture) {
- return key;
- }
- }
- return null;
- },
- _generalTextureKey: function (id) {
- return "_textureKey_" + id;
- },
- getTextureColors: function (texture) {
- var image = texture._htmlElementObj;
- var key = this.getKeyByTexture(image);
- if (!key) {
- if (image instanceof HTMLImageElement)
- key = image.src;
- else
- key = this._generalTextureKey(texture.__instanceId);
- }
- if (!this._textureColorsCache[key])
- this._textureColorsCache[key] = texture._generateTextureCacheForColor();
- return this._textureColorsCache[key];
- },
- addPVRImage: function (path) {
- cc.log(cc._LogInfos.textureCache_addPVRImage);
- },
- removeAllTextures: function () {
- var locTextures = this._textures;
- for (var selKey in locTextures) {
- if (locTextures[selKey])
- locTextures[selKey].releaseTexture();
- }
- this._textures = {};
- },
- removeTexture: function (texture) {
- if (!texture)
- return;
- var locTextures = this._textures;
- for (var selKey in locTextures) {
- if (locTextures[selKey] === texture) {
- locTextures[selKey].releaseTexture();
- delete(locTextures[selKey]);
- }
- }
- },
- removeTextureForKey: function (textureKeyName) {
- if (textureKeyName == null)
- return;
- if (this._textures[textureKeyName])
- delete(this._textures[textureKeyName]);
- },
- cacheImage: function (path, texture) {
- if (texture instanceof cc.Texture2D) {
- this._textures[path] = texture;
- return;
- }
- var texture2d = new cc.Texture2D();
- texture2d.initWithElement(texture);
- texture2d.handleLoadedTexture();
- this._textures[path] = texture2d;
- },
- addUIImage: function (image, key) {
- cc.assert(image, cc._LogInfos.textureCache_addUIImage_2);
- if (key) {
- if (this._textures[key])
- return this._textures[key];
- }
- var texture = new cc.Texture2D();
- texture.initWithImage(image);
- if (key != null)
- this._textures[key] = texture;
- else
- cc.log(cc._LogInfos.textureCache_addUIImage);
- return texture;
- },
- dumpCachedTextureInfo: function () {
- var count = 0;
- var totalBytes = 0, locTextures = this._textures;
- for (var key in locTextures) {
- var selTexture = locTextures[key];
- count++;
- if (selTexture.getHtmlElementObj() instanceof HTMLImageElement)
- cc.log(cc._LogInfos.textureCache_dumpCachedTextureInfo, key, selTexture.getHtmlElementObj().src, selTexture.pixelsWidth, selTexture.pixelsHeight);
- else {
- cc.log(cc._LogInfos.textureCache_dumpCachedTextureInfo_2, key, selTexture.pixelsWidth, selTexture.pixelsHeight);
- }
- totalBytes += selTexture.pixelsWidth * selTexture.pixelsHeight * 4;
- }
- var locTextureColorsCache = this._textureColorsCache;
- for (key in locTextureColorsCache) {
- var selCanvasColorsArr = locTextureColorsCache[key];
- for (var selCanvasKey in selCanvasColorsArr) {
- var selCanvas = selCanvasColorsArr[selCanvasKey];
- count++;
- cc.log(cc._LogInfos.textureCache_dumpCachedTextureInfo_2, key, selCanvas.width, selCanvas.height);
- totalBytes += selCanvas.width * selCanvas.height * 4;
- }
- }
- cc.log(cc._LogInfos.textureCache_dumpCachedTextureInfo_3, count, totalBytes / 1024, (totalBytes / (1024.0 * 1024.0)).toFixed(2));
- },
- _clear: function () {
- this._textures = {};
- this._textureColorsCache = {};
- this._textureKeySeq = (0 | Math.random() * 1000);
- this._loadedTexturesBefore = {};
- }
- };
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- var _p = cc.textureCache;
- _p.handleLoadedTexture = function (url) {
- var locTexs = this._textures;
- var tex = locTexs[url];
- if (!tex) {
- tex = locTexs[url] = new cc.Texture2D();
- tex.url = url;
- }
- tex.handleLoadedTexture();
- };
- _p.addImage = function (url, cb, target) {
- cc.assert(url, cc._LogInfos.Texture2D_addImage);
- var locTexs = this._textures;
- var tex = locTexs[url] || locTexs[cc.loader._getAliase(url)];
- if (tex) {
- if(tex.isLoaded()) {
- cb && cb.call(target, tex);
- return tex;
- }
- else
- {
- tex.addEventListener("load", function(){
- cb && cb.call(target, tex);
- }, target);
- return tex;
- }
- }
- tex = locTexs[url] = new cc.Texture2D();
- tex.url = url;
- var basePath = cc.loader.getBasePath ? cc.loader.getBasePath() : cc.loader.resPath;
- cc.loader.loadImg(cc.path.join(basePath || "", url), function (err, img) {
- if (err)
- return cb && cb.call(target, err);
- if (!cc.loader.cache[url]) {
- cc.loader.cache[url] = img;
- }
- cc.textureCache.handleLoadedTexture(url);
- var texResult = locTexs[url];
- cb && cb.call(target, texResult);
- });
- return tex;
- };
- _p.addImageAsync = _p.addImage;
- _p = null;
- } else if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
- cc.assert(cc.isFunction(cc._tmp.WebGLTextureCache), cc._LogInfos.MissingFile, "TexturesWebGL.js");
- cc._tmp.WebGLTextureCache();
- delete cc._tmp.WebGLTextureCache;
- }
- });
- cc.Scene = cc.Node.extend({
- _className:"Scene",
- ctor:function () {
- cc.Node.prototype.ctor.call(this);
- this._ignoreAnchorPointForPosition = true;
- this.setAnchorPoint(0.5, 0.5);
- this.setContentSize(cc.director.getWinSize());
- }
- });
- cc.Scene.create = function () {
- return new cc.Scene();
- };
- cc.LoaderScene = cc.Scene.extend({
- _interval : null,
- _label : null,
- _className:"LoaderScene",
- cb: null,
- target: null,
- init : function(){
- var self = this;
- var logoWidth = 160;
- var logoHeight = 200;
- var bgLayer = self._bgLayer = new cc.LayerColor(cc.color(32, 32, 32, 255));
- self.addChild(bgLayer, 0);
- var fontSize = 24, lblHeight = -logoHeight / 2 + 100;
- if(cc._loaderImage){
- cc.loader.loadImg(cc._loaderImage, {isCrossOrigin : false }, function(err, img){
- logoWidth = img.width;
- logoHeight = img.height;
- self._initStage(img, cc.visibleRect.center);
- });
- fontSize = 14;
- lblHeight = -logoHeight / 2 - 10;
- }
- var label = self._label = new cc.LabelTTF("Loading... 0%", "Arial", fontSize);
- label.setPosition(cc.pAdd(cc.visibleRect.center, cc.p(0, lblHeight)));
- label.setColor(cc.color(180, 180, 180));
- bgLayer.addChild(this._label, 10);
- return true;
- },
- _initStage: function (img, centerPos) {
- var self = this;
- var texture2d = self._texture2d = new cc.Texture2D();
- texture2d.initWithElement(img);
- texture2d.handleLoadedTexture();
- var logo = self._logo = new cc.Sprite(texture2d);
- logo.setScale(cc.contentScaleFactor());
- logo.x = centerPos.x;
- logo.y = centerPos.y;
- self._bgLayer.addChild(logo, 10);
- },
- onEnter: function () {
- var self = this;
- cc.Node.prototype.onEnter.call(self);
- self.schedule(self._startLoading, 0.3);
- },
- onExit: function () {
- cc.Node.prototype.onExit.call(this);
- var tmpStr = "Loading... 0%";
- this._label.setString(tmpStr);
- },
- initWithResources: function (resources, cb, target) {
- if(cc.isString(resources))
- resources = [resources];
- this.resources = resources || [];
- this.cb = cb;
- this.target = target;
- },
- _startLoading: function () {
- var self = this;
- self.unschedule(self._startLoading);
- var res = self.resources;
- cc.loader.load(res,
- function (result, count, loadedCount) {
- var percent = (loadedCount / count * 100) | 0;
- percent = Math.min(percent, 100);
- self._label.setString("Loading... " + percent + "%");
- }, function () {
- if (self.cb)
- self.cb.call(self.target);
- });
- },
- _updateTransform: function(){
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- this._bgLayer._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- this._label._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- this._logo._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- }
- });
- cc.LoaderScene.preload = function(resources, cb, target){
- var _cc = cc;
- if(!_cc.loaderScene) {
- _cc.loaderScene = new cc.LoaderScene();
- _cc.loaderScene.init();
- cc.eventManager.addCustomListener(cc.Director.EVENT_PROJECTION_CHANGED, function(){
- _cc.loaderScene._updateTransform();
- });
- }
- _cc.loaderScene.initWithResources(resources, cb, target);
- cc.director.runScene(_cc.loaderScene);
- return _cc.loaderScene;
- };
- cc.Layer = cc.Node.extend({
- _className: "Layer",
- ctor: function () {
- cc.Node.prototype.ctor.call(this);
- this._ignoreAnchorPointForPosition = true;
- this.setAnchorPoint(0.5, 0.5);
- this.setContentSize(cc.winSize);
- },
- init: function(){
- var _t = this;
- _t._ignoreAnchorPointForPosition = true;
- _t.setAnchorPoint(0.5, 0.5);
- _t.setContentSize(cc.winSize);
- _t._cascadeColorEnabled = false;
- _t._cascadeOpacityEnabled = false;
- return true;
- },
- bake: function(){
- this._renderCmd.bake();
- },
- unbake: function(){
- this._renderCmd.unbake();
- },
- isBaked: function(){
- return this._renderCmd._isBaked;
- },
- addChild: function(child, localZOrder, tag){
- cc.Node.prototype.addChild.call(this, child, localZOrder, tag);
- this._renderCmd._bakeForAddChild(child);
- },
- _createRenderCmd: function(){
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.Layer.CanvasRenderCmd(this);
- else
- return new cc.Layer.WebGLRenderCmd(this);
- }
- });
- cc.Layer.create = function () {
- return new cc.Layer();
- };
- cc.LayerColor = cc.Layer.extend({
- _blendFunc: null,
- _className: "LayerColor",
- getBlendFunc: function () {
- return this._blendFunc;
- },
- changeWidthAndHeight: function (w, h) {
- this.width = w;
- this.height = h;
- },
- changeWidth: function (w) {
- this.width = w;
- },
- changeHeight: function (h) {
- this.height = h;
- },
- setOpacityModifyRGB: function (value) {
- },
- isOpacityModifyRGB: function () {
- return false;
- },
- ctor: function(color, width, height){
- cc.Layer.prototype.ctor.call(this);
- this._blendFunc = cc.BlendFunc._alphaNonPremultiplied();
- cc.LayerColor.prototype.init.call(this, color, width, height);
- },
- init: function (color, width, height) {
- var winSize = cc.director.getWinSize();
- color = color || cc.color(0, 0, 0, 255);
- width = width === undefined ? winSize.width : width;
- height = height === undefined ? winSize.height : height;
- var locRealColor = this._realColor;
- locRealColor.r = color.r;
- locRealColor.g = color.g;
- locRealColor.b = color.b;
- this._realOpacity = color.a;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty|cc.Node._dirtyFlags.opacityDirty);
- cc.LayerColor.prototype.setContentSize.call(this, width, height);
- return true;
- },
- setBlendFunc: function (src, dst) {
- var locBlendFunc = this._blendFunc;
- if (dst === undefined) {
- locBlendFunc.src = src.src;
- locBlendFunc.dst = src.dst;
- } else {
- locBlendFunc.src = src;
- locBlendFunc.dst = dst;
- }
- this._renderCmd.updateBlendFunc(locBlendFunc);
- },
- _createRenderCmd: function(){
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.LayerColor.CanvasRenderCmd(this);
- else
- return new cc.LayerColor.WebGLRenderCmd(this);
- }
- });
- cc.LayerColor.create = function (color, width, height) {
- return new cc.LayerColor(color, width, height);
- };
- (function(){
- var proto = cc.LayerColor.prototype;
- cc.defineGetterSetter(proto, "width", proto._getWidth, proto._setWidth);
- cc.defineGetterSetter(proto, "height", proto._getHeight, proto._setHeight);
- })();
- cc.LayerGradient = cc.LayerColor.extend({
- _endColor: null,
- _startOpacity: 255,
- _endOpacity: 255,
- _alongVector: null,
- _compressedInterpolation: false,
- _className: "LayerGradient",
- _colorStops: [],
- ctor: function (start, end, v, stops) {
- cc.LayerColor.prototype.ctor.call(this);
- this._endColor = cc.color(0, 0, 0, 255);
- this._alongVector = cc.p(0, -1);
- this._startOpacity = 255;
- this._endOpacity = 255;
- if(stops && stops instanceof Array){
- this._colorStops = stops;
- stops.splice(0, 0, {p:0, color: start || cc.color.BLACK});
- stops.push({p:1, color: end || cc.color.BLACK});
- } else
- this._colorStops = [{p:0, color: start || cc.color.BLACK}, {p:1, color: end || cc.color.BLACK}];
- cc.LayerGradient.prototype.init.call(this, start, end, v, stops);
- },
- init: function (start, end, v, stops) {
- start = start || cc.color(0, 0, 0, 255);
- end = end || cc.color(0, 0, 0, 255);
- v = v || cc.p(0, -1);
- var _t = this;
- var locEndColor = _t._endColor;
- _t._startOpacity = start.a;
- locEndColor.r = end.r;
- locEndColor.g = end.g;
- locEndColor.b = end.b;
- _t._endOpacity = end.a;
- _t._alongVector = v;
- _t._compressedInterpolation = true;
- cc.LayerColor.prototype.init.call(_t, cc.color(start.r, start.g, start.b, 255));
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty|cc.Node._dirtyFlags.opacityDirty|cc.Node._dirtyFlags.gradientDirty);
- return true;
- },
- setContentSize: function (size, height) {
- cc.LayerColor.prototype.setContentSize.call(this, size, height);
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.gradientDirty);
- },
- _setWidth: function (width) {
- cc.LayerColor.prototype._setWidth.call(this, width);
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.gradientDirty);
- },
- _setHeight: function (height) {
- cc.LayerColor.prototype._setHeight.call(this, height);
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.gradientDirty);
- },
- getStartColor: function () {
- return cc.color(this._realColor);
- },
- setStartColor: function (color) {
- this.color = color;
- var stops = this._colorStops;
- if(stops && stops.length > 0){
- var selColor = stops[0].color;
- selColor.r = color.r;
- selColor.g = color.g;
- selColor.b = color.b;
- }
- },
- setEndColor: function (color) {
- var locColor = this._endColor;
- locColor.r = color.r;
- locColor.g = color.g;
- locColor.b = color.b;
- var stops = this._colorStops;
- if(stops && stops.length > 0){
- var selColor = stops[stops.length -1].color;
- selColor.r = color.r;
- selColor.g = color.g;
- selColor.b = color.b;
- }
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty);
- },
- getEndColor: function () {
- return cc.color(this._endColor);
- },
- setStartOpacity: function (o) {
- this._startOpacity = o;
- var stops = this._colorStops;
- if(stops && stops.length > 0)
- stops[0].color.a = o;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.opacityDirty);
- },
- getStartOpacity: function () {
- return this._startOpacity;
- },
- setEndOpacity: function (o) {
- this._endOpacity = o;
- var stops = this._colorStops;
- if(stops && stops.length > 0)
- stops[stops.length -1].color.a = o;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.opacityDirty);
- },
- getEndOpacity: function () {
- return this._endOpacity;
- },
- setVector: function (Var) {
- this._alongVector.x = Var.x;
- this._alongVector.y = Var.y;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.gradientDirty);
- },
- getVector: function () {
- return cc.p(this._alongVector.x, this._alongVector.y);
- },
- isCompressedInterpolation: function () {
- return this._compressedInterpolation;
- },
- setCompressedInterpolation: function (compress) {
- this._compressedInterpolation = compress;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.gradientDirty);
- },
- getColorStops: function(){
- return this._colorStops;
- },
- setColorStops: function(colorStops){
- this._colorStops = colorStops;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.colorDirty|cc.Node._dirtyFlags.opacityDirty|cc.Node._dirtyFlags.gradientDirty);
- },
- _createRenderCmd: function(){
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.LayerGradient.CanvasRenderCmd(this);
- else
- return new cc.LayerGradient.WebGLRenderCmd(this);
- }
- });
- cc.LayerGradient.create = function (start, end, v, stops) {
- return new cc.LayerGradient(start, end, v, stops);
- };
- (function(){
- var proto = cc.LayerGradient.prototype;
- proto.startColor;
- cc.defineGetterSetter(proto, "startColor", proto.getStartColor, proto.setStartColor);
- proto.endColor;
- cc.defineGetterSetter(proto, "endColor", proto.getEndColor, proto.setEndColor);
- proto.startOpacity;
- cc.defineGetterSetter(proto, "startOpacity", proto.getStartOpacity, proto.setStartOpacity);
- proto.endOpacity;
- cc.defineGetterSetter(proto, "endOpacity", proto.getEndOpacity, proto.setEndOpacity);
- proto.vector;
- cc.defineGetterSetter(proto, "vector", proto.getVector, proto.setVector);
- proto.colorStops;
- cc.defineGetterSetter(proto, "colorStops", proto.getColorStops, proto.setColorStops);
- })();
- cc.LayerMultiplex = cc.Layer.extend({
- _enabledLayer: 0,
- _layers: null,
- _className: "LayerMultiplex",
- ctor: function (layers) {
- cc.Layer.prototype.ctor.call(this);
- if (layers instanceof Array)
- cc.LayerMultiplex.prototype.initWithLayers.call(this, layers);
- else
- cc.LayerMultiplex.prototype.initWithLayers.call(this, Array.prototype.slice.call(arguments));
- },
- initWithLayers: function (layers) {
- if ((layers.length > 0) && (layers[layers.length - 1] == null))
- cc.log(cc._LogInfos.LayerMultiplex_initWithLayers);
- this._layers = layers;
- this._enabledLayer = 0;
- this.addChild(this._layers[this._enabledLayer]);
- return true;
- },
- switchTo: function (n) {
- if (n >= this._layers.length) {
- cc.log(cc._LogInfos.LayerMultiplex_switchTo);
- return;
- }
- this.removeChild(this._layers[this._enabledLayer], true);
- this._enabledLayer = n;
- this.addChild(this._layers[n]);
- },
- switchToAndReleaseMe: function (n) {
- if (n >= this._layers.length) {
- cc.log(cc._LogInfos.LayerMultiplex_switchToAndReleaseMe);
- return;
- }
- this.removeChild(this._layers[this._enabledLayer], true);
- this._layers[this._enabledLayer] = null;
- this._enabledLayer = n;
- this.addChild(this._layers[n]);
- },
- addLayer: function (layer) {
- if (!layer) {
- cc.log(cc._LogInfos.LayerMultiplex_addLayer);
- return;
- }
- this._layers.push(layer);
- }
- });
- cc.LayerMultiplex.create = function () {
- return new cc.LayerMultiplex(Array.prototype.slice.call(arguments));
- };
- (function(){
- cc.Layer.CanvasRenderCmd = function(renderable){
- cc.Node.CanvasRenderCmd.call(this, renderable);
- this._isBaked = false;
- this._bakeSprite = null;
- this._canUseDirtyRegion = true;
- this._updateCache = 2;
- };
- var proto = cc.Layer.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
- proto.constructor = cc.Layer.CanvasRenderCmd;
- proto._setCacheDirty = function(child){
- if(child && this._updateCache === 0)
- this._updateCache = 2;
- if (this._cacheDirty === false) {
- this._cacheDirty = true;
- var cachedP = this._cachedParent;
- cachedP && cachedP !== this && cachedP._setNodeDirtyForCache && cachedP._setNodeDirtyForCache();
- }
- };
- proto.updateStatus = function () {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.orderDirty) {
- this._cacheDirty = true;
- if(this._updateCache === 0)
- this._updateCache = 2;
- this._dirtyFlag = locFlag & flags.orderDirty ^ locFlag;
- }
- cc.Node.RenderCmd.prototype.updateStatus.call(this);
- };
- proto._syncStatus = function (parentCmd) {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.orderDirty) {
- this._cacheDirty = true;
- if(this._updateCache === 0)
- this._updateCache = 2;
- this._dirtyFlag = locFlag & flags.orderDirty ^ locFlag;
- }
- cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);
- };
- proto.transform = function (parentCmd, recursive) {
- var wt = this._worldTransform;
- var a = wt.a, b = wt.b, c = wt.c, d = wt.d, tx = wt.tx, ty = wt.ty;
- cc.Node.CanvasRenderCmd.prototype.transform.call(this, parentCmd, recursive);
- if(( wt.a !== a || wt.b !== b || wt.c !== c || wt.d !== d ) && this._updateCache === 0)
- this._updateCache = 2;
- };
- proto.bake = function(){
- if (!this._isBaked) {
- this._needDraw = true;
- cc.renderer.childrenOrderDirty = true;
- this._isBaked = this._cacheDirty = true;
- if(this._updateCache === 0)
- this._updateCache = 2;
- var children = this._node._children;
- for(var i = 0, len = children.length; i < len; i++)
- children[i]._renderCmd._setCachedParent(this);
- if (!this._bakeSprite) {
- this._bakeSprite = new cc.BakeSprite();
- this._bakeSprite.setAnchorPoint(0,0);
- }
- }
- };
- proto.unbake = function(){
- if (this._isBaked) {
- cc.renderer.childrenOrderDirty = true;
- this._needDraw = false;
- this._isBaked = false;
- this._cacheDirty = true;
- if(this._updateCache === 0)
- this._updateCache = 2;
- var children = this._node._children;
- for(var i = 0, len = children.length; i < len; i++)
- children[i]._renderCmd._setCachedParent(null);
- }
- };
- proto.isBaked = function(){
- return this._isBaked;
- };
- proto.rendering = function(){
- if(this._cacheDirty){
- var node = this._node;
- var children = node._children, locBakeSprite = this._bakeSprite;
- this.transform(this.getParentRenderCmd(), true);
- var boundingBox = this._getBoundingBoxForBake();
- boundingBox.width = 0|(boundingBox.width+0.5);
- boundingBox.height = 0|(boundingBox.height+0.5);
- var bakeContext = locBakeSprite.getCacheContext();
- var ctx = bakeContext.getContext();
- locBakeSprite.setPosition(boundingBox.x, boundingBox.y);
- if(this._updateCache > 0){
- locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
- bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
- node.sortAllChildren();
- cc.renderer._turnToCacheMode(this.__instanceId);
- for (var i = 0, len = children.length; i < len; i++) {
- children[i].visit(this);
- }
- cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
- locBakeSprite.transform();
- this._updateCache--;
- }
- this._cacheDirty = false;
- }
- };
- proto.visit = function(parentCmd){
- if(!this._isBaked){
- this.originVisit(parentCmd);
- return;
- }
- var node = this._node, children = node._children;
- var len = children.length;
- if (!node._visible || len === 0)
- return;
- this._syncStatus(parentCmd);
- cc.renderer.pushRenderCommand(this);
- this._bakeSprite.visit(this);
- this._dirtyFlag = 0;
- };
- proto._bakeForAddChild = function(child){
- if(child._parent === this._node && this._isBaked)
- child._renderCmd._setCachedParent(this);
- };
- proto._getBoundingBoxForBake = function(){
- var rect = null, node = this._node;
- if (!node._children || node._children.length === 0)
- return cc.rect(0, 0, 10, 10);
- var trans = node.getNodeToWorldTransform();
- var locChildren = node._children;
- for (var i = 0, len = locChildren.length; i < len; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- if(rect){
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- if (childRect)
- rect = cc.rectUnion(rect, childRect);
- }else{
- rect = child._getBoundingBoxToCurrentNode(trans);
- }
- }
- }
- return rect;
- };
- })();
- (function(){
- cc.LayerColor.CanvasRenderCmd = function(renderable){
- cc.Layer.CanvasRenderCmd.call(this, renderable);
- this._needDraw = true;
- this._blendFuncStr = "source-over";
- this._bakeRenderCmd = new cc.CustomRenderCmd(this, this._bakeRendering);
- };
- var proto = cc.LayerColor.CanvasRenderCmd.prototype = Object.create(cc.Layer.CanvasRenderCmd.prototype);
- proto.constructor = cc.LayerColor.CanvasRenderCmd;
- proto.unbake = function(){
- cc.Layer.CanvasRenderCmd.prototype.unbake.call(this);
- this._needDraw = true;
- };
- proto.rendering = function (ctx, scaleX, scaleY) {
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext(),
- node = this._node,
- curColor = this._displayedColor,
- opacity = this._displayedOpacity / 255,
- locWidth = node._contentSize.width,
- locHeight = node._contentSize.height;
- if (opacity === 0)
- return;
- wrapper.setCompositeOperation(this._blendFuncStr);
- wrapper.setGlobalAlpha(opacity);
- wrapper.setFillStyle("rgba(" + (0 | curColor.r) + "," + (0 | curColor.g) + ","
- + (0 | curColor.b) + ", 1)");
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- context.fillRect(0, 0, locWidth , -locHeight );
- cc.g_NumberOfDraws++;
- };
- proto.updateBlendFunc = function(blendFunc){
- this._blendFuncStr = cc.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(blendFunc);
- };
- proto._updateSquareVertices =
- proto._updateSquareVerticesWidth =
- proto._updateSquareVerticesHeight = function(){};
- proto._bakeRendering = function(){
- if(this._cacheDirty){
- var node = this._node;
- var locBakeSprite = this._bakeSprite, children = node._children;
- var len = children.length, i;
- this.transform(this.getParentRenderCmd(), true);
- var boundingBox = this._getBoundingBoxForBake();
- boundingBox.width = 0|(boundingBox.width+0.5);
- boundingBox.height = 0|(boundingBox.height+0.5);
- var bakeContext = locBakeSprite.getCacheContext();
- var ctx = bakeContext.getContext();
- locBakeSprite.setPosition(boundingBox.x, boundingBox.y);
- if(this._updateCache > 0) {
- ctx.fillStyle = bakeContext._currentFillStyle;
- locBakeSprite.resetCanvasSize(boundingBox.width, boundingBox.height);
- bakeContext.setOffset(0 - boundingBox.x, ctx.canvas.height - boundingBox.height + boundingBox.y );
- var child;
- cc.renderer._turnToCacheMode(this.__instanceId);
- if (len > 0) {
- node.sortAllChildren();
- for (i = 0; i < len; i++) {
- child = children[i];
- if (child._localZOrder < 0)
- child._renderCmd.visit(this);
- else
- break;
- }
- cc.renderer.pushRenderCommand(this);
- for (; i < len; i++) {
- children[i]._renderCmd.visit(this);
- }
- } else
- cc.renderer.pushRenderCommand(this);
- cc.renderer._renderingToCacheCanvas(bakeContext, this.__instanceId);
- locBakeSprite.transform();
- this._updateCache--;
- }
- this._cacheDirty = false;
- }
- };
- proto.visit = function(parentCmd){
- if(!this._isBaked){
- this.originVisit();
- return;
- }
- var node = this._node;
- if (!node._visible)
- return;
- this._syncStatus(parentCmd);
- cc.renderer.pushRenderCommand(this._bakeRenderCmd);
- this._bakeSprite._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- this._bakeSprite.visit(this);
- this._dirtyFlag = 0;
- };
- proto._getBoundingBoxForBake = function(){
- var node = this._node;
- var rect = cc.rect(0, 0, node._contentSize.width, node._contentSize.height);
- var trans = node.getNodeToWorldTransform();
- rect = cc.rectApplyAffineTransform(rect, node.getNodeToWorldTransform());
- if (!node._children || node._children.length === 0)
- return rect;
- var locChildren = node._children;
- for (var i = 0; i < locChildren.length; i++) {
- var child = locChildren[i];
- if (child && child._visible) {
- var childRect = child._getBoundingBoxToCurrentNode(trans);
- rect = cc.rectUnion(rect, childRect);
- }
- }
- return rect;
- };
- })();
- (function(){
- cc.LayerGradient.CanvasRenderCmd = function(renderable){
- cc.LayerColor.CanvasRenderCmd.call(this, renderable);
- this._needDraw = true;
- this._startPoint = cc.p(0, 0);
- this._endPoint = cc.p(0, 0);
- this._startStopStr = null;
- this._endStopStr = null;
- };
- var proto = cc.LayerGradient.CanvasRenderCmd.prototype = Object.create(cc.LayerColor.CanvasRenderCmd.prototype);
- proto.constructor = cc.LayerGradient.CanvasRenderCmd;
- proto.rendering = function (ctx, scaleX, scaleY) {
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext(),
- node = this._node,
- opacity = this._displayedOpacity / 255;
- if (opacity === 0)
- return;
- var locWidth = node._contentSize.width, locHeight = node._contentSize.height;
- wrapper.setCompositeOperation(this._blendFuncStr);
- wrapper.setGlobalAlpha(opacity);
- var gradient = context.createLinearGradient(this._startPoint.x, this._startPoint.y, this._endPoint.x, this._endPoint.y);
- if(node._colorStops){
- for(var i=0; i < node._colorStops.length; i++) {
- var stop = node._colorStops[i];
- gradient.addColorStop(stop.p, this._colorStopsStr[i]);
- }
- }else{
- gradient.addColorStop(0, this._startStopStr);
- gradient.addColorStop(1, this._endStopStr);
- }
- wrapper.setFillStyle(gradient);
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- context.fillRect(0, 0, locWidth , -locHeight );
- cc.g_NumberOfDraws++;
- };
- proto.updateStatus = function () {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.gradientDirty) {
- this._dirtyFlag |= flags.colorDirty;
- this._dirtyFlag = locFlag & flags.gradientDirty ^ locFlag;
- }
- cc.Node.RenderCmd.prototype.updateStatus.call(this);
- };
- proto._syncStatus = function (parentCmd) {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.gradientDirty) {
- this._dirtyFlag |= flags.colorDirty;
- this._dirtyFlag = locFlag & flags.gradientDirty ^ locFlag;
- }
- cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);
- };
- proto._updateColor = function() {
- var node = this._node;
- var contentSize = node._contentSize;
- var tWidth = contentSize.width * 0.5, tHeight = contentSize.height * 0.5;
- var angle = cc.pAngleSigned(cc.p(0, -1), node._alongVector);
- var p1 = cc.pRotateByAngle(cc.p(0, -1), cc.p(0,0), angle);
- var factor = Math.min(Math.abs(1 / p1.x), Math.abs(1/ p1.y));
- this._startPoint.x = tWidth * (-p1.x * factor) + tWidth;
- this._startPoint.y = tHeight * (p1.y * factor) - tHeight;
- this._endPoint.x = tWidth * (p1.x * factor) + tWidth;
- this._endPoint.y = tHeight * (-p1.y * factor) - tHeight;
- var locStartColor = this._displayedColor, locEndColor = node._endColor;
- var startOpacity = node._startOpacity/255, endOpacity = node._endOpacity/255;
- this._startStopStr = "rgba(" + Math.round(locStartColor.r) + "," + Math.round(locStartColor.g) + ","
- + Math.round(locStartColor.b) + "," + startOpacity.toFixed(4) + ")";
- this._endStopStr = "rgba(" + Math.round(locEndColor.r) + "," + Math.round(locEndColor.g) + ","
- + Math.round(locEndColor.b) + "," + endOpacity.toFixed(4) + ")";
- if( node._colorStops){
- this._startOpacity = 0;
- this._endOpacity = 0;
- this._colorStopsStr = [];
- for(var i =0; i < node._colorStops.length; i++){
- var stopColor = node._colorStops[i].color;
- var stopOpacity = stopColor.a == null ? 1 : stopColor.a / 255;
- this._colorStopsStr.push("rgba(" + Math.round(stopColor.r) + "," + Math.round(stopColor.g) + ","
- + Math.round(stopColor.b) + "," + stopOpacity.toFixed(4) + ")");
- }
- }
- };
- })();
- cc._tmp.PrototypeSprite = function () {
- var _p = cc.Sprite.prototype;
- cc.defineGetterSetter(_p, "opacityModifyRGB", _p.isOpacityModifyRGB, _p.setOpacityModifyRGB);
- cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
- cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
- _p.dirty;
- _p.flippedX;
- cc.defineGetterSetter(_p, "flippedX", _p.isFlippedX, _p.setFlippedX);
- _p.flippedY;
- cc.defineGetterSetter(_p, "flippedY", _p.isFlippedY, _p.setFlippedY);
- _p.offsetX;
- cc.defineGetterSetter(_p, "offsetX", _p._getOffsetX);
- _p.offsetY;
- cc.defineGetterSetter(_p, "offsetY", _p._getOffsetY);
- _p.atlasIndex;
- _p.texture;
- cc.defineGetterSetter(_p, "texture", _p.getTexture, _p.setTexture);
- _p.textureRectRotated;
- cc.defineGetterSetter(_p, "textureRectRotated", _p.isTextureRectRotated);
- _p.textureAtlas;
- _p.batchNode;
- cc.defineGetterSetter(_p, "batchNode", _p.getBatchNode, _p.setBatchNode);
- _p.quad;
- cc.defineGetterSetter(_p, "quad", _p.getQuad);
- };
- cc.Sprite = cc.Node.extend({
- dirty:false,
- atlasIndex:0,
- textureAtlas:null,
- _batchNode:null,
- _recursiveDirty:null,
- _hasChildren:null,
- _shouldBeHidden:false,
- _transformToBatch:null,
- _blendFunc:null,
- _texture:null,
- _rect:null,
- _rectRotated:false,
- _offsetPosition:null,
- _unflippedOffsetPositionFromCenter:null,
- _opacityModifyRGB:false,
- _flippedX:false,
- _flippedY:false,
- _textureLoaded:false,
- _className:"Sprite",
- ctor: function (fileName, rect, rotated) {
- var self = this;
- cc.Node.prototype.ctor.call(self);
- this.setAnchorPoint(0.5, 0.5);
- self._loader = new cc.Sprite.LoadManager();
- self._shouldBeHidden = false;
- self._offsetPosition = cc.p(0, 0);
- self._unflippedOffsetPositionFromCenter = cc.p(0, 0);
- self._blendFunc = {src: cc.BLEND_SRC, dst: cc.BLEND_DST};
- self._rect = cc.rect(0, 0, 0, 0);
- self._softInit(fileName, rect, rotated);
- },
- textureLoaded:function(){
- return this._textureLoaded;
- },
- addLoadedEventListener:function(callback, target){
- this.addEventListener("load", callback, target);
- },
- isDirty:function () {
- return this.dirty;
- },
- setDirty:function (bDirty) {
- this.dirty = bDirty;
- },
- isTextureRectRotated:function () {
- return this._rectRotated;
- },
- getAtlasIndex:function () {
- return this.atlasIndex;
- },
- setAtlasIndex:function (atlasIndex) {
- this.atlasIndex = atlasIndex;
- },
- getTextureRect:function () {
- return cc.rect(this._rect);
- },
- getTextureAtlas:function () {
- return this.textureAtlas;
- },
- setTextureAtlas:function (textureAtlas) {
- this.textureAtlas = textureAtlas;
- },
- getOffsetPosition:function () {
- return cc.p(this._offsetPosition);
- },
- _getOffsetX: function () {
- return this._offsetPosition.x;
- },
- _getOffsetY: function () {
- return this._offsetPosition.y;
- },
- getBlendFunc:function () {
- return this._blendFunc;
- },
- initWithSpriteFrame:function (spriteFrame) {
- cc.assert(spriteFrame, cc._LogInfos.Sprite_initWithSpriteFrame);
- return this.setSpriteFrame(spriteFrame);
- },
- initWithSpriteFrameName:function (spriteFrameName) {
- cc.assert(spriteFrameName, cc._LogInfos.Sprite_initWithSpriteFrameName);
- var frame = cc.spriteFrameCache.getSpriteFrame(spriteFrameName);
- cc.assert(frame, spriteFrameName + cc._LogInfos.Sprite_initWithSpriteFrameName1);
- return this.initWithSpriteFrame(frame);
- },
- useBatchNode:function (batchNode) {
- this.textureAtlas = batchNode.getTextureAtlas();
- this._batchNode = batchNode;
- },
- setVertexRect:function (rect) {
- var locRect = this._rect;
- locRect.x = rect.x;
- locRect.y = rect.y;
- locRect.width = rect.width;
- locRect.height = rect.height;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- sortAllChildren:function () {
- if (this._reorderChildDirty) {
- var _children = this._children;
- cc.Node.prototype.sortAllChildren.call(this);
- if (this._batchNode) {
- this._arrayMakeObjectsPerformSelector(_children, cc.Node._stateCallbackType.sortAllChildren);
- }
- this._reorderChildDirty = false;
- }
- },
- reorderChild:function (child, zOrder) {
- cc.assert(child, cc._LogInfos.Sprite_reorderChild_2);
- if(this._children.indexOf(child) === -1){
- cc.log(cc._LogInfos.Sprite_reorderChild);
- return;
- }
- if (zOrder === child.zIndex)
- return;
- if (this._batchNode && !this._reorderChildDirty) {
- this._setReorderChildDirtyRecursively();
- this._batchNode.reorderBatch(true);
- }
- cc.Node.prototype.reorderChild.call(this, child, zOrder);
- },
- removeChild:function (child, cleanup) {
- if (this._batchNode)
- this._batchNode.removeSpriteFromAtlas(child);
- cc.Node.prototype.removeChild.call(this, child, cleanup);
- },
- setVisible:function (visible) {
- cc.Node.prototype.setVisible.call(this, visible);
- this._renderCmd.setDirtyRecursively(true);
- },
- removeAllChildren:function (cleanup) {
- var locChildren = this._children, locBatchNode = this._batchNode;
- if (locBatchNode && locChildren != null) {
- for (var i = 0, len = locChildren.length; i < len; i++)
- locBatchNode.removeSpriteFromAtlas(locChildren[i]);
- }
- cc.Node.prototype.removeAllChildren.call(this, cleanup);
- this._hasChildren = false;
- },
- ignoreAnchorPointForPosition:function (relative) {
- if(this._batchNode){
- cc.log(cc._LogInfos.Sprite_ignoreAnchorPointForPosition);
- return;
- }
- cc.Node.prototype.ignoreAnchorPointForPosition.call(this, relative);
- },
- setFlippedX:function (flippedX) {
- if (this._flippedX !== flippedX) {
- this._flippedX = flippedX;
- this.setTextureRect(this._rect, this._rectRotated, this._contentSize);
- this.setNodeDirty(true);
- }
- },
- setFlippedY:function (flippedY) {
- if (this._flippedY !== flippedY) {
- this._flippedY = flippedY;
- this.setTextureRect(this._rect, this._rectRotated, this._contentSize);
- this.setNodeDirty(true);
- }
- },
- isFlippedX:function () {
- return this._flippedX;
- },
- isFlippedY:function () {
- return this._flippedY;
- },
- setOpacityModifyRGB: function (modify) {
- if (this._opacityModifyRGB !== modify) {
- this._opacityModifyRGB = modify;
- this._renderCmd._setColorDirty();
- }
- },
- isOpacityModifyRGB:function () {
- return this._opacityModifyRGB;
- },
- setDisplayFrameWithAnimationName:function (animationName, frameIndex) {
- cc.assert(animationName, cc._LogInfos.Sprite_setDisplayFrameWithAnimationName_3);
- var cache = cc.animationCache.getAnimation(animationName);
- if(!cache){
- cc.log(cc._LogInfos.Sprite_setDisplayFrameWithAnimationName);
- return;
- }
- var animFrame = cache.getFrames()[frameIndex];
- if(!animFrame){
- cc.log(cc._LogInfos.Sprite_setDisplayFrameWithAnimationName_2);
- return;
- }
- this.setSpriteFrame(animFrame.getSpriteFrame());
- },
- getBatchNode:function () {
- return this._batchNode;
- },
- _setReorderChildDirtyRecursively:function () {
- if (!this._reorderChildDirty) {
- this._reorderChildDirty = true;
- var pNode = this._parent;
- while (pNode && pNode !== this._batchNode) {
- pNode._setReorderChildDirtyRecursively();
- pNode = pNode.parent;
- }
- }
- },
- getTexture:function () {
- return this._texture;
- },
- _softInit: function (fileName, rect, rotated) {
- if (fileName === undefined)
- cc.Sprite.prototype.init.call(this);
- else if (cc.isString(fileName)) {
- if (fileName[0] === "#") {
- var frameName = fileName.substr(1, fileName.length - 1);
- var spriteFrame = cc.spriteFrameCache.getSpriteFrame(frameName);
- if (spriteFrame)
- this.initWithSpriteFrame(spriteFrame);
- else
- cc.log("%s does not exist", fileName);
- } else {
- cc.Sprite.prototype.init.call(this, fileName, rect);
- }
- } else if (typeof fileName === "object") {
- if (fileName instanceof cc.Texture2D) {
- this.initWithTexture(fileName, rect, rotated);
- } else if (fileName instanceof cc.SpriteFrame) {
- this.initWithSpriteFrame(fileName);
- } else if ((fileName instanceof HTMLImageElement) || (fileName instanceof HTMLCanvasElement)) {
- var texture2d = new cc.Texture2D();
- texture2d.initWithElement(fileName);
- texture2d.handleLoadedTexture();
- this.initWithTexture(texture2d);
- }
- }
- },
- getQuad:function () {
- return null;
- },
- setBlendFunc: function (src, dst) {
- var locBlendFunc = this._blendFunc;
- if (dst === undefined) {
- locBlendFunc.src = src.src;
- locBlendFunc.dst = src.dst;
- } else {
- locBlendFunc.src = src;
- locBlendFunc.dst = dst;
- }
- this._renderCmd.updateBlendFunc(locBlendFunc);
- },
- init: function () {
- var _t = this;
- if (arguments.length > 0)
- return _t.initWithFile(arguments[0], arguments[1]);
- cc.Node.prototype.init.call(_t);
- _t.dirty = _t._recursiveDirty = false;
- _t._blendFunc.src = cc.BLEND_SRC;
- _t._blendFunc.dst = cc.BLEND_DST;
- _t.texture = null;
- _t._flippedX = _t._flippedY = false;
- _t.anchorX = 0.5;
- _t.anchorY = 0.5;
- _t._offsetPosition.x = 0;
- _t._offsetPosition.y = 0;
- _t._hasChildren = false;
- _t.setTextureRect(cc.rect(0, 0, 0, 0), false, cc.size(0, 0));
- return true;
- },
- initWithFile:function (filename, rect) {
- cc.assert(filename, cc._LogInfos.Sprite_initWithFile);
- var tex = cc.textureCache.getTextureForKey(filename);
- if (!tex) {
- tex = cc.textureCache.addImage(filename);
- }
- if (!tex.isLoaded()) {
- this._loader.clear();
- this._loader.once(tex, function () {
- this.initWithFile(filename, rect);
- this.dispatchEvent("load");
- }, this);
- return false;
- }
- if (!rect) {
- var size = tex.getContentSize();
- rect = cc.rect(0, 0, size.width, size.height);
- }
- return this.initWithTexture(tex, rect);
- },
- initWithTexture: function (texture, rect, rotated, counterclockwise) {
- var _t = this;
- cc.assert(arguments.length !== 0, cc._LogInfos.CCSpriteBatchNode_initWithTexture);
- this._loader.clear();
- _t._textureLoaded = texture.isLoaded();
- if (!_t._textureLoaded) {
- this._loader.once(texture, function () {
- this.initWithTexture(texture, rect, rotated, counterclockwise);
- this.dispatchEvent("load");
- }, this);
- return false;
- }
- rotated = rotated || false;
- texture = this._renderCmd._handleTextureForRotatedTexture(texture, rect, rotated, counterclockwise);
- if (!cc.Node.prototype.init.call(_t))
- return false;
- _t._batchNode = null;
- _t._recursiveDirty = false;
- _t.dirty = false;
- _t._opacityModifyRGB = true;
- _t._blendFunc.src = cc.BLEND_SRC;
- _t._blendFunc.dst = cc.BLEND_DST;
- _t._flippedX = _t._flippedY = false;
- _t._offsetPosition.x = 0;
- _t._offsetPosition.y = 0;
- _t._hasChildren = false;
- _t._rectRotated = rotated;
- if (rect) {
- _t._rect.x = rect.x;
- _t._rect.y = rect.y;
- _t._rect.width = rect.width;
- _t._rect.height = rect.height;
- }
- if (!rect)
- rect = cc.rect(0, 0, texture.width, texture.height);
- this._renderCmd._checkTextureBoundary(texture, rect, rotated);
- _t.setTexture(texture);
- _t.setTextureRect(rect, rotated);
- _t.setBatchNode(null);
- return true;
- },
- setTextureRect: function (rect, rotated, untrimmedSize, needConvert) {
- var _t = this;
- _t._rectRotated = rotated || false;
- _t.setContentSize(untrimmedSize || rect);
- _t.setVertexRect(rect);
- _t._renderCmd._setTextureCoords(rect, needConvert);
- var relativeOffsetX = _t._unflippedOffsetPositionFromCenter.x, relativeOffsetY = _t._unflippedOffsetPositionFromCenter.y;
- if (_t._flippedX)
- relativeOffsetX = -relativeOffsetX;
- if (_t._flippedY)
- relativeOffsetY = -relativeOffsetY;
- var locRect = _t._rect;
- _t._offsetPosition.x = relativeOffsetX + (_t._contentSize.width - locRect.width) / 2;
- _t._offsetPosition.y = relativeOffsetY + (_t._contentSize.height - locRect.height) / 2;
- },
- addChild: function (child, localZOrder, tag) {
- cc.assert(child, cc._LogInfos.CCSpriteBatchNode_addChild_2);
- if (localZOrder == null)
- localZOrder = child._localZOrder;
- if (tag == null)
- tag = child.tag;
- if(this._renderCmd._setBatchNodeForAddChild(child)){
- cc.Node.prototype.addChild.call(this, child, localZOrder, tag);
- this._hasChildren = true;
- }
- },
- setSpriteFrame: function (newFrame) {
- var _t = this;
- if(cc.isString(newFrame)){
- newFrame = cc.spriteFrameCache.getSpriteFrame(newFrame);
- cc.assert(newFrame, cc._LogInfos.Sprite_setSpriteFrame)
- }
- this._loader.clear();
- this.setNodeDirty(true);
- var pNewTexture = newFrame.getTexture();
- _t._textureLoaded = newFrame.textureLoaded();
- this._loader.clear();
- if (!_t._textureLoaded) {
- this._loader.once(pNewTexture, function () {
- this.setSpriteFrame(newFrame);
- this.dispatchEvent("load");
- }, this);
- return false;
- }
- var frameOffset = newFrame.getOffset();
- _t._unflippedOffsetPositionFromCenter.x = frameOffset.x;
- _t._unflippedOffsetPositionFromCenter.y = frameOffset.y;
- if (pNewTexture !== _t._texture) {
- this._renderCmd._setTexture(pNewTexture);
- _t.setColor(_t._realColor);
- }
- _t.setTextureRect(newFrame.getRect(), newFrame.isRotated(), newFrame.getOriginalSize());
- },
- setDisplayFrame: function(newFrame){
- cc.log(cc._LogInfos.Sprite_setDisplayFrame);
- this.setSpriteFrame(newFrame);
- },
- isFrameDisplayed: function(frame){
- return this._renderCmd.isFrameDisplayed(frame);
- },
- displayFrame: function () {
- return this.getSpriteFrame();
- },
- getSpriteFrame: function () {
- return new cc.SpriteFrame(this._texture,
- cc.rectPointsToPixels(this._rect),
- this._rectRotated,
- cc.pointPointsToPixels(this._unflippedOffsetPositionFromCenter),
- cc.sizePointsToPixels(this._contentSize));
- },
- setBatchNode:function (spriteBatchNode) {
- var _t = this;
- _t._batchNode = spriteBatchNode;
- if (!_t._batchNode) {
- _t.atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED;
- _t.textureAtlas = null;
- _t._recursiveDirty = false;
- _t.dirty = false;
- } else {
- _t._transformToBatch = cc.affineTransformIdentity();
- _t.textureAtlas = _t._batchNode.getTextureAtlas();
- }
- },
- setTexture: function (texture) {
- if(!texture)
- return this._renderCmd._setTexture(null);
- var isFileName = cc.isString(texture);
- if(isFileName)
- texture = cc.textureCache.addImage(texture);
- this._loader.clear();
- if (!texture._textureLoaded) {
- this._loader.once(texture, function () {
- this.setTexture(texture);
- this.dispatchEvent("load");
- }, this);
- return false;
- }
- this._renderCmd._setTexture(texture);
- if (isFileName)
- this._changeRectWithTexture(texture);
- this.setColor(this._realColor);
- this._textureLoaded = true;
- },
- _changeRectWithTexture: function(texture){
- var contentSize = texture._contentSize;
- var rect = cc.rect(
- 0, 0,
- contentSize.width, contentSize.height
- );
- this.setTextureRect(rect);
- },
- _createRenderCmd: function(){
- if(cc._renderType === cc.game.RENDER_TYPE_CANVAS)
- return new cc.Sprite.CanvasRenderCmd(this);
- else
- return new cc.Sprite.WebGLRenderCmd(this);
- }
- });
- cc.Sprite.create = function (fileName, rect, rotated) {
- return new cc.Sprite(fileName, rect, rotated);
- };
- cc.Sprite.createWithTexture = cc.Sprite.create;
- cc.Sprite.createWithSpriteFrameName = cc.Sprite.create;
- cc.Sprite.createWithSpriteFrame = cc.Sprite.create;
- cc.Sprite.INDEX_NOT_INITIALIZED = -1;
- cc.EventHelper.prototype.apply(cc.Sprite.prototype);
- cc.assert(cc.isFunction(cc._tmp.PrototypeSprite), cc._LogInfos.MissingFile, "SpritesPropertyDefine.js");
- cc._tmp.PrototypeSprite();
- delete cc._tmp.PrototypeSprite;
- (function () {
- var manager = cc.Sprite.LoadManager = function () {
- this.list = [];
- };
- manager.prototype.add = function (source, callback, target) {
- if (!source || !source.addEventListener) return;
- source.addEventListener('load', callback, target);
- this.list.push({
- source: source,
- listener: callback,
- target: target
- });
- };
- manager.prototype.once = function (source, callback, target) {
- if (!source || !source.addEventListener) return;
- var tmpCallback = function (event) {
- source.removeEventListener('load', tmpCallback, target);
- callback.call(target, event);
- };
- source.addEventListener('load', tmpCallback, target);
- this.list.push({
- source: source,
- listener: tmpCallback,
- target: target
- });
- };
- manager.prototype.clear = function () {
- while (this.list.length > 0) {
- var item = this.list.pop();
- item.source.removeEventListener('load', item.listener, item.target);
- }
- };
- })();
- (function() {
- cc.Sprite.CanvasRenderCmd = function (renderable) {
- cc.Node.CanvasRenderCmd.call(this, renderable);
- this._needDraw = true;
- this._textureCoord = {
- renderX: 0,
- renderY: 0,
- x: 0,
- y: 0,
- width: 0,
- height: 0,
- validRect: false
- };
- this._blendFuncStr = "source-over";
- this._colorized = false;
- this._canUseDirtyRegion = true;
- this._textureToRender = null;
- };
- var proto = cc.Sprite.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
- proto.constructor = cc.Sprite.CanvasRenderCmd;
- proto.setDirtyRecursively = function (value) {};
- proto._setTexture = function (texture) {
- var node = this._node;
- if (node._texture !== texture) {
- if (texture) {
- node._textureLoaded = texture._textureLoaded;
- }else{
- node._textureLoaded = false;
- }
- node._texture = texture;
- this._updateColor();
- }
- };
- proto._setColorDirty = function () {
- this.setDirtyFlag(cc.Node._dirtyFlags.colorDirty | cc.Node._dirtyFlags.opacityDirty);
- };
- proto.isFrameDisplayed = function (frame) {
- var node = this._node;
- if (frame.getTexture() !== node._texture)
- return false;
- return cc.rectEqualToRect(frame.getRect(), node._rect);
- };
- proto.updateBlendFunc = function (blendFunc) {
- this._blendFuncStr = cc.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(blendFunc);
- };
- proto._setBatchNodeForAddChild = function (child) {
- return true;
- };
- proto._handleTextureForRotatedTexture = function (texture, rect, rotated, counterclockwise) {
- if (rotated && texture.isLoaded()) {
- var tempElement = texture.getHtmlElementObj();
- tempElement = cc.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, rect, counterclockwise);
- var tempTexture = new cc.Texture2D();
- tempTexture.initWithElement(tempElement);
- tempTexture.handleLoadedTexture();
- texture = tempTexture;
- rect.x = rect.y = 0;
- this._node._rect = cc.rect(0, 0, rect.width, rect.height);
- }
- return texture;
- };
- proto._checkTextureBoundary = function (texture, rect, rotated) {
- if (texture && texture.url) {
- var _x = rect.x + rect.width, _y = rect.y + rect.height;
- if (_x > texture.width)
- cc.error(cc._LogInfos.RectWidth, texture.url);
- if (_y > texture.height)
- cc.error(cc._LogInfos.RectHeight, texture.url);
- }
- };
- proto.rendering = function (ctx, scaleX, scaleY) {
- var node = this._node;
- var locTextureCoord = this._textureCoord, alpha = (this._displayedOpacity / 255);
- var texture = this._textureToRender || node._texture;
- if ((texture && (locTextureCoord.width === 0 || locTextureCoord.height === 0|| !texture._textureLoaded)) || alpha === 0)
- return;
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
- var locX = node._offsetPosition.x, locHeight = node._rect.height, locWidth = node._rect.width,
- locY = -node._offsetPosition.y - locHeight, image;
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- wrapper.setCompositeOperation(this._blendFuncStr);
- wrapper.setGlobalAlpha(alpha);
- if(node._flippedX || node._flippedY)
- wrapper.save();
- if (node._flippedX) {
- locX = -locX - locWidth;
- context.scale(-1, 1);
- }
- if (node._flippedY) {
- locY = node._offsetPosition.y;
- context.scale(1, -1);
- }
- var sx, sy, sw, sh, x, y, w, h;
- if (this._colorized) {
- sx = 0;
- sy = 0;
- }else{
- sx = locTextureCoord.renderX;
- sy = locTextureCoord.renderY;
- }
- sw = locTextureCoord.width;
- sh = locTextureCoord.height;
- x = locX;
- y = locY;
- w = locWidth;
- h = locHeight;
- if (texture && texture._htmlElementObj) {
- image = texture._htmlElementObj;
- if (texture._pattern !== "") {
- wrapper.setFillStyle(context.createPattern(image, texture._pattern));
- context.fillRect(x, y, w, h);
- } else {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
- } else {
- var contentSize = node._contentSize;
- if (locTextureCoord.validRect) {
- var curColor = this._displayedColor;
- wrapper.setFillStyle("rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + ",1)");
- context.fillRect(x, y, contentSize.width * scaleX, contentSize.height * scaleY);
- }
- }
- if(node._flippedX || node._flippedY)
- wrapper.restore();
- cc.g_NumberOfDraws++;
- };
- proto._updateColor = function(){
- var node = this._node;
- var texture = node._texture, rect = this._textureCoord;
- var dColor = this._displayedColor;
- if(texture){
- if(dColor.r !== 255 || dColor.g !== 255 || dColor.b !== 255){
- this._textureToRender = texture._generateColorTexture(dColor.r, dColor.g, dColor.b, rect);
- this._colorized = true;
- }else if(texture){
- this._textureToRender = texture;
- this._colorized = false;
- }
- }
- };
- proto._textureLoadedCallback = function (sender) {
- var node = this;
- if (node._textureLoaded)
- return;
- node._textureLoaded = true;
- var locRect = node._rect, locRenderCmd = this._renderCmd;
- if (!locRect) {
- locRect = cc.rect(0, 0, sender.width, sender.height);
- } else if (cc._rectEqualToZero(locRect)) {
- locRect.width = sender.width;
- locRect.height = sender.height;
- }
- node.texture = sender;
- node.setTextureRect(locRect, node._rectRotated);
- var locColor = locRenderCmd._displayedColor;
- if (locColor.r !== 255 || locColor.g !== 255 || locColor.b !== 255)
- locRenderCmd._updateColor();
- node.setBatchNode(node._batchNode);
- node.dispatchEvent("load");
- };
- proto._setTextureCoords = function (rect, needConvert) {
- if (needConvert === undefined)
- needConvert = true;
- var locTextureRect = this._textureCoord,
- scaleFactor = needConvert ? cc.contentScaleFactor() : 1;
- locTextureRect.renderX = locTextureRect.x = 0 | (rect.x * scaleFactor);
- locTextureRect.renderY = locTextureRect.y = 0 | (rect.y * scaleFactor);
- locTextureRect.width = 0 | (rect.width * scaleFactor);
- locTextureRect.height = 0 | (rect.height * scaleFactor);
- locTextureRect.validRect = !(locTextureRect.width === 0 || locTextureRect.height === 0 || locTextureRect.x < 0 || locTextureRect.y < 0);
- };
- cc.Sprite.CanvasRenderCmd._cutRotateImageToCanvas = function (texture, rect, counterclockwise) {
- if (!texture)
- return null;
- if (!rect)
- return texture;
- counterclockwise = counterclockwise == null? true: counterclockwise;
- var nCanvas = document.createElement("canvas");
- nCanvas.width = rect.width;
- nCanvas.height = rect.height;
- var ctx = nCanvas.getContext("2d");
- ctx.translate(nCanvas.width / 2, nCanvas.height / 2);
- if(counterclockwise)
- ctx.rotate(-1.5707963267948966);
- else
- ctx.rotate(1.5707963267948966);
- ctx.drawImage(texture, rect.x, rect.y, rect.height, rect.width, -rect.height / 2, -rect.width / 2, rect.height, rect.width);
- return nCanvas;
- };
- })();
- cc.BakeSprite = cc.Sprite.extend({
- _cacheCanvas: null,
- _cacheContext: null,
- ctor: function(){
- cc.Sprite.prototype.ctor.call(this);
- var canvasElement = document.createElement("canvas");
- canvasElement.width = canvasElement.height = 10;
- this._cacheCanvas = canvasElement;
- this._cacheContext = new cc.CanvasContextWrapper(canvasElement.getContext("2d"));
- var texture = new cc.Texture2D();
- texture.initWithElement(canvasElement);
- texture.handleLoadedTexture();
- this.setTexture(texture);
- },
- getCacheContext: function(){
- return this._cacheContext;
- },
- getCacheCanvas: function(){
- return this._cacheCanvas;
- },
- resetCanvasSize: function(sizeOrWidth, height){
- var locCanvas = this._cacheCanvas,
- locContext = this._cacheContext,
- strokeStyle = locContext._context.strokeStyle,
- fillStyle = locContext._context.fillStyle;
- if(height === undefined){
- height = sizeOrWidth.height;
- sizeOrWidth = sizeOrWidth.width;
- }
- locCanvas.width = sizeOrWidth;
- locCanvas.height = height;
- if(strokeStyle !== locContext._context.strokeStyle)
- locContext._context.strokeStyle = strokeStyle;
- if(fillStyle !== locContext._context.fillStyle)
- locContext._context.fillStyle = fillStyle;
- this.getTexture().handleLoadedTexture();
- this.setTextureRect(cc.rect(0,0, sizeOrWidth, height), false, null, false);
- }
- });
- cc.AnimationFrame = cc.Class.extend({
- _spriteFrame:null,
- _delayPerUnit:0,
- _userInfo:null,
- ctor:function (spriteFrame, delayUnits, userInfo) {
- this._spriteFrame = spriteFrame || null;
- this._delayPerUnit = delayUnits || 0;
- this._userInfo = userInfo || null;
- },
- clone: function(){
- var frame = new cc.AnimationFrame();
- frame.initWithSpriteFrame(this._spriteFrame.clone(), this._delayPerUnit, this._userInfo);
- return frame;
- },
- copyWithZone:function (pZone) {
- return cc.clone(this);
- },
- copy:function (pZone) {
- var newFrame = new cc.AnimationFrame();
- newFrame.initWithSpriteFrame(this._spriteFrame.clone(), this._delayPerUnit, this._userInfo);
- return newFrame;
- },
- initWithSpriteFrame:function (spriteFrame, delayUnits, userInfo) {
- this._spriteFrame = spriteFrame;
- this._delayPerUnit = delayUnits;
- this._userInfo = userInfo;
- return true;
- },
- getSpriteFrame:function () {
- return this._spriteFrame;
- },
- setSpriteFrame:function (spriteFrame) {
- this._spriteFrame = spriteFrame;
- },
- getDelayUnits:function () {
- return this._delayPerUnit;
- },
- setDelayUnits:function (delayUnits) {
- this._delayPerUnit = delayUnits;
- },
- getUserInfo:function () {
- return this._userInfo;
- },
- setUserInfo:function (userInfo) {
- this._userInfo = userInfo;
- }
- });
- cc.AnimationFrame.create = function(spriteFrame,delayUnits,userInfo){
- return new cc.AnimationFrame(spriteFrame,delayUnits,userInfo);
- };
- cc.Animation = cc.Class.extend({
- _frames:null,
- _loops:0,
- _restoreOriginalFrame:false,
- _duration:0,
- _delayPerUnit:0,
- _totalDelayUnits:0,
- ctor:function (frames, delay, loops) {
- this._frames = [];
- if (frames === undefined) {
- this.initWithSpriteFrames(null, 0);
- } else {
- var frame0 = frames[0];
- if(frame0){
- if (frame0 instanceof cc.SpriteFrame) {
- this.initWithSpriteFrames(frames, delay, loops);
- }else if(frame0 instanceof cc.AnimationFrame) {
- this.initWithAnimationFrames(frames, delay, loops);
- }
- }
- }
- },
- getFrames:function () {
- return this._frames;
- },
- setFrames:function (frames) {
- this._frames = frames;
- },
- addSpriteFrame:function (frame) {
- var animFrame = new cc.AnimationFrame();
- animFrame.initWithSpriteFrame(frame, 1, null);
- this._frames.push(animFrame);
- this._totalDelayUnits++;
- },
- addSpriteFrameWithFile:function (fileName) {
- var texture = cc.textureCache.addImage(fileName);
- var rect = cc.rect(0, 0, 0, 0);
- rect.width = texture.width;
- rect.height = texture.height;
- var frame = new cc.SpriteFrame(texture, rect);
- this.addSpriteFrame(frame);
- },
- addSpriteFrameWithTexture:function (texture, rect) {
- var pFrame = new cc.SpriteFrame(texture, rect);
- this.addSpriteFrame(pFrame);
- },
- initWithAnimationFrames:function (arrayOfAnimationFrames, delayPerUnit, loops) {
- cc.arrayVerifyType(arrayOfAnimationFrames, cc.AnimationFrame);
- this._delayPerUnit = delayPerUnit;
- this._loops = loops === undefined ? 1 : loops;
- this._totalDelayUnits = 0;
- var locFrames = this._frames;
- locFrames.length = 0;
- for (var i = 0; i < arrayOfAnimationFrames.length; i++) {
- var animFrame = arrayOfAnimationFrames[i];
- locFrames.push(animFrame);
- this._totalDelayUnits += animFrame.getDelayUnits();
- }
- return true;
- },
- clone: function(){
- var animation = new cc.Animation();
- animation.initWithAnimationFrames(this._copyFrames(), this._delayPerUnit, this._loops);
- animation.setRestoreOriginalFrame(this._restoreOriginalFrame);
- return animation;
- },
- copyWithZone:function (pZone) {
- var pCopy = new cc.Animation();
- pCopy.initWithAnimationFrames(this._copyFrames(), this._delayPerUnit, this._loops);
- pCopy.setRestoreOriginalFrame(this._restoreOriginalFrame);
- return pCopy;
- },
- _copyFrames:function(){
- var copyFrames = [];
- for(var i = 0; i< this._frames.length;i++)
- copyFrames.push(this._frames[i].clone());
- return copyFrames;
- },
- copy:function (pZone) {
- return this.copyWithZone(null);
- },
- getLoops:function () {
- return this._loops;
- },
- setLoops:function (value) {
- this._loops = value;
- },
- setRestoreOriginalFrame:function (restOrigFrame) {
- this._restoreOriginalFrame = restOrigFrame;
- },
- getRestoreOriginalFrame:function () {
- return this._restoreOriginalFrame;
- },
- getDuration:function () {
- return this._totalDelayUnits * this._delayPerUnit;
- },
- getDelayPerUnit:function () {
- return this._delayPerUnit;
- },
- setDelayPerUnit:function (delayPerUnit) {
- this._delayPerUnit = delayPerUnit;
- },
- getTotalDelayUnits:function () {
- return this._totalDelayUnits;
- },
- initWithSpriteFrames:function (frames, delay, loops) {
- cc.arrayVerifyType(frames, cc.SpriteFrame);
- this._loops = loops === undefined ? 1 : loops;
- this._delayPerUnit = delay || 0;
- this._totalDelayUnits = 0;
- var locFrames = this._frames;
- locFrames.length = 0;
- if (frames) {
- for (var i = 0; i < frames.length; i++) {
- var frame = frames[i];
- var animFrame = new cc.AnimationFrame();
- animFrame.initWithSpriteFrame(frame, 1, null);
- locFrames.push(animFrame);
- }
- this._totalDelayUnits += frames.length;
- }
- return true;
- },
- retain:function () {
- },
- release:function () {
- }
- });
- cc.Animation.create = function (frames, delay, loops) {
- return new cc.Animation(frames, delay, loops);
- };
- cc.Animation.createWithAnimationFrames = cc.Animation.create;
- cc.animationCache = {
- _animations: {},
- addAnimation:function (animation, name) {
- this._animations[name] = animation;
- },
- removeAnimation:function (name) {
- if (!name) {
- return;
- }
- if (this._animations[name]) {
- delete this._animations[name];
- }
- },
- getAnimation:function (name) {
- if (this._animations[name])
- return this._animations[name];
- return null;
- },
- _addAnimationsWithDictionary:function (dictionary,plist) {
- var animations = dictionary["animations"];
- if (!animations) {
- cc.log(cc._LogInfos.animationCache__addAnimationsWithDictionary);
- return;
- }
- var version = 1;
- var properties = dictionary["properties"];
- if (properties) {
- version = (properties["format"] != null) ? parseInt(properties["format"]) : version;
- var spritesheets = properties["spritesheets"];
- var spriteFrameCache = cc.spriteFrameCache;
- var path = cc.path;
- for (var i = 0; i < spritesheets.length; i++) {
- spriteFrameCache.addSpriteFrames(path.changeBasename(plist, spritesheets[i]));
- }
- }
- switch (version) {
- case 1:
- this._parseVersion1(animations);
- break;
- case 2:
- this._parseVersion2(animations);
- break;
- default :
- cc.log(cc._LogInfos.animationCache__addAnimationsWithDictionary_2);
- break;
- }
- },
- addAnimations:function (plist) {
- cc.assert(plist, cc._LogInfos.animationCache_addAnimations_2);
- var dict = cc.loader.getRes(plist);
- if(!dict){
- cc.log(cc._LogInfos.animationCache_addAnimations);
- return;
- }
- this._addAnimationsWithDictionary(dict,plist);
- },
- _parseVersion1:function (animations) {
- var frameCache = cc.spriteFrameCache;
- for (var key in animations) {
- var animationDict = animations[key];
- var frameNames = animationDict["frames"];
- var delay = parseFloat(animationDict["delay"]) || 0;
- var animation = null;
- if (!frameNames) {
- cc.log(cc._LogInfos.animationCache__parseVersion1, key);
- continue;
- }
- var frames = [];
- for (var i = 0; i < frameNames.length; i++) {
- var spriteFrame = frameCache.getSpriteFrame(frameNames[i]);
- if (!spriteFrame) {
- cc.log(cc._LogInfos.animationCache__parseVersion1_2, key, frameNames[i]);
- continue;
- }
- var animFrame = new cc.AnimationFrame();
- animFrame.initWithSpriteFrame(spriteFrame, 1, null);
- frames.push(animFrame);
- }
- if (frames.length === 0) {
- cc.log(cc._LogInfos.animationCache__parseVersion1_3, key);
- continue;
- } else if (frames.length !== frameNames.length) {
- cc.log(cc._LogInfos.animationCache__parseVersion1_4, key);
- }
- animation = new cc.Animation(frames, delay, 1);
- cc.animationCache.addAnimation(animation, key);
- }
- },
- _parseVersion2:function (animations) {
- var frameCache = cc.spriteFrameCache;
- for (var key in animations) {
- var animationDict = animations[key];
- var isLoop = animationDict["loop"];
- var loopsTemp = parseInt(animationDict["loops"]);
- var loops = isLoop ? cc.REPEAT_FOREVER : ((isNaN(loopsTemp)) ? 1 : loopsTemp);
- var restoreOriginalFrame = (animationDict["restoreOriginalFrame"] && animationDict["restoreOriginalFrame"] == true) ? true : false;
- var frameArray = animationDict["frames"];
- if (!frameArray) {
- cc.log(cc._LogInfos.animationCache__parseVersion2, key);
- continue;
- }
- var arr = [];
- for (var i = 0; i < frameArray.length; i++) {
- var entry = frameArray[i];
- var spriteFrameName = entry["spriteframe"];
- var spriteFrame = frameCache.getSpriteFrame(spriteFrameName);
- if (!spriteFrame) {
- cc.log(cc._LogInfos.animationCache__parseVersion2_2, key, spriteFrameName);
- continue;
- }
- var delayUnits = parseFloat(entry["delayUnits"]) || 0;
- var userInfo = entry["notification"];
- var animFrame = new cc.AnimationFrame();
- animFrame.initWithSpriteFrame(spriteFrame, delayUnits, userInfo);
- arr.push(animFrame);
- }
- var delayPerUnit = parseFloat(animationDict["delayPerUnit"]) || 0;
- var animation = new cc.Animation();
- animation.initWithAnimationFrames(arr, delayPerUnit, loops);
- animation.setRestoreOriginalFrame(restoreOriginalFrame);
- cc.animationCache.addAnimation(animation, key);
- }
- },
- _clear: function () {
- this._animations = {};
- }
- };
- cc.SpriteFrame = cc.Class.extend({
- _offset:null,
- _originalSize:null,
- _rectInPixels:null,
- _rotated:false,
- _rect:null,
- _offsetInPixels:null,
- _originalSizeInPixels:null,
- _texture:null,
- _textureFilename:"",
- _textureLoaded:false,
- ctor:function (filename, rect, rotated, offset, originalSize) {
- this._offset = cc.p(0, 0);
- this._offsetInPixels = cc.p(0, 0);
- this._originalSize = cc.size(0, 0);
- this._rotated = false;
- this._originalSizeInPixels = cc.size(0, 0);
- this._textureFilename = "";
- this._texture = null;
- this._textureLoaded = false;
- if(filename !== undefined && rect !== undefined ){
- if(rotated === undefined || offset === undefined || originalSize === undefined)
- this.initWithTexture(filename, rect);
- else
- this.initWithTexture(filename, rect, rotated, offset, originalSize)
- }
- },
- textureLoaded:function(){
- return this._textureLoaded;
- },
- addLoadedEventListener:function(callback, target){
- this.addEventListener("load", callback, target);
- },
- getRectInPixels:function () {
- var locRectInPixels = this._rectInPixels;
- return cc.rect(locRectInPixels.x, locRectInPixels.y, locRectInPixels.width, locRectInPixels.height);
- },
- setRectInPixels:function (rectInPixels) {
- if (!this._rectInPixels){
- this._rectInPixels = cc.rect(0,0,0,0);
- }
- this._rectInPixels.x = rectInPixels.x;
- this._rectInPixels.y = rectInPixels.y;
- this._rectInPixels.width = rectInPixels.width;
- this._rectInPixels.height = rectInPixels.height;
- this._rect = cc.rectPixelsToPoints(rectInPixels);
- },
- isRotated:function () {
- return this._rotated;
- },
- setRotated:function (bRotated) {
- this._rotated = bRotated;
- },
- getRect:function () {
- var locRect = this._rect;
- return cc.rect(locRect.x, locRect.y, locRect.width, locRect.height);
- },
- setRect:function (rect) {
- if (!this._rect){
- this._rect = cc.rect(0,0,0,0);
- }
- this._rect.x = rect.x;
- this._rect.y = rect.y;
- this._rect.width = rect.width;
- this._rect.height = rect.height;
- this._rectInPixels = cc.rectPointsToPixels(this._rect);
- },
- getOffsetInPixels:function () {
- return cc.p(this._offsetInPixels);
- },
- setOffsetInPixels:function (offsetInPixels) {
- this._offsetInPixels.x = offsetInPixels.x;
- this._offsetInPixels.y = offsetInPixels.y;
- cc._pointPixelsToPointsOut(this._offsetInPixels, this._offset);
- },
- getOriginalSizeInPixels:function () {
- return cc.size(this._originalSizeInPixels);
- },
- setOriginalSizeInPixels:function (sizeInPixels) {
- this._originalSizeInPixels.width = sizeInPixels.width;
- this._originalSizeInPixels.height = sizeInPixels.height;
- },
- getOriginalSize:function () {
- return cc.size(this._originalSize);
- },
- setOriginalSize:function (sizeInPixels) {
- this._originalSize.width = sizeInPixels.width;
- this._originalSize.height = sizeInPixels.height;
- },
- getTexture:function () {
- if (this._texture)
- return this._texture;
- if (this._textureFilename !== "") {
- var locTexture = cc.textureCache.addImage(this._textureFilename);
- if (locTexture)
- this._textureLoaded = locTexture.isLoaded();
- return locTexture;
- }
- return null;
- },
- setTexture:function (texture) {
- if (this._texture !== texture) {
- var locLoaded = texture.isLoaded();
- this._textureLoaded = locLoaded;
- this._texture = texture;
- if(!locLoaded){
- texture.addEventListener("load", function(sender){
- this._textureLoaded = true;
- if(this._rotated && cc._renderType === cc.game.RENDER_TYPE_CANVAS){
- var tempElement = sender.getHtmlElementObj();
- tempElement = cc.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, this.getRect());
- var tempTexture = new cc.Texture2D();
- tempTexture.initWithElement(tempElement);
- tempTexture.handleLoadedTexture();
- this.setTexture(tempTexture);
- var rect = this.getRect();
- this.setRect(cc.rect(0, 0, rect.width, rect.height));
- }
- var locRect = this._rect;
- if(locRect.width === 0 && locRect.height === 0){
- var w = sender.width, h = sender.height;
- this._rect.width = w;
- this._rect.height = h;
- this._rectInPixels = cc.rectPointsToPixels(this._rect);
- this._originalSizeInPixels.width = this._rectInPixels.width;
- this._originalSizeInPixels.height = this._rectInPixels.height;
- this._originalSize.width = w;
- this._originalSize.height = h;
- }
- this.dispatchEvent("load");
- }, this);
- }
- }
- },
- getOffset:function () {
- return cc.p(this._offset);
- },
- setOffset:function (offsets) {
- this._offset.x = offsets.x;
- this._offset.y = offsets.y;
- },
- clone: function(){
- var frame = new cc.SpriteFrame();
- frame.initWithTexture(this._textureFilename, this._rectInPixels, this._rotated, this._offsetInPixels, this._originalSizeInPixels);
- frame.setTexture(this._texture);
- return frame;
- },
- copyWithZone:function () {
- var copy = new cc.SpriteFrame();
- copy.initWithTexture(this._textureFilename, this._rectInPixels, this._rotated, this._offsetInPixels, this._originalSizeInPixels);
- copy.setTexture(this._texture);
- return copy;
- },
- copy:function () {
- return this.copyWithZone();
- },
- initWithTexture:function (texture, rect, rotated, offset, originalSize) {
- if(arguments.length === 2)
- rect = cc.rectPointsToPixels(rect);
- offset = offset || cc.p(0, 0);
- originalSize = originalSize || rect;
- rotated = rotated || false;
- if (cc.isString(texture)){
- this._texture = null;
- this._textureFilename = texture;
- } else if (texture instanceof cc.Texture2D){
- this.setTexture(texture);
- }
- texture = this.getTexture();
- this._rectInPixels = rect;
- this._rect = cc.rectPixelsToPoints(rect);
- if(texture && texture.url && texture.isLoaded()) {
- var _x, _y;
- if(rotated){
- _x = rect.x + rect.height;
- _y = rect.y + rect.width;
- }else{
- _x = rect.x + rect.width;
- _y = rect.y + rect.height;
- }
- if(_x > texture.getPixelsWide()){
- cc.error(cc._LogInfos.RectWidth, texture.url);
- }
- if(_y > texture.getPixelsHigh()){
- cc.error(cc._LogInfos.RectHeight, texture.url);
- }
- }
- this._offsetInPixels.x = offset.x;
- this._offsetInPixels.y = offset.y;
- cc._pointPixelsToPointsOut(offset, this._offset);
- this._originalSizeInPixels.width = originalSize.width;
- this._originalSizeInPixels.height = originalSize.height;
- cc._sizePixelsToPointsOut(originalSize, this._originalSize);
- this._rotated = rotated;
- return true;
- }
- });
- cc.EventHelper.prototype.apply(cc.SpriteFrame.prototype);
- cc.SpriteFrame.create = function (filename, rect, rotated, offset, originalSize) {
- return new cc.SpriteFrame(filename,rect,rotated,offset,originalSize);
- };
- cc.SpriteFrame.createWithTexture = cc.SpriteFrame.create;
- cc.SpriteFrame._frameWithTextureForCanvas = function (texture, rect, rotated, offset, originalSize) {
- var spriteFrame = new cc.SpriteFrame();
- spriteFrame._texture = texture;
- spriteFrame._rectInPixels = rect;
- spriteFrame._rect = cc.rectPixelsToPoints(rect);
- spriteFrame._offsetInPixels.x = offset.x;
- spriteFrame._offsetInPixels.y = offset.y;
- cc._pointPixelsToPointsOut(spriteFrame._offsetInPixels, spriteFrame._offset);
- spriteFrame._originalSizeInPixels.width = originalSize.width;
- spriteFrame._originalSizeInPixels.height = originalSize.height;
- cc._sizePixelsToPointsOut(spriteFrame._originalSizeInPixels, spriteFrame._originalSize);
- spriteFrame._rotated = rotated;
- return spriteFrame;
- };
- cc.spriteFrameCache = {
- _CCNS_REG1 : /^\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*$/,
- _CCNS_REG2 : /^\s*\{\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*,\s*\{\s*([\-]?\d+[.]?\d*)\s*,\s*([\-]?\d+[.]?\d*)\s*\}\s*\}\s*$/,
- _spriteFrames: {},
- _spriteFramesAliases: {},
- _frameConfigCache : {},
- _rectFromString : function (content) {
- var result = this._CCNS_REG2.exec(content);
- if(!result) return cc.rect(0, 0, 0, 0);
- return cc.rect(parseFloat(result[1]), parseFloat(result[2]), parseFloat(result[3]), parseFloat(result[4]));
- },
- _pointFromString : function (content) {
- var result = this._CCNS_REG1.exec(content);
- if(!result) return cc.p(0,0);
- return cc.p(parseFloat(result[1]), parseFloat(result[2]));
- },
- _sizeFromString : function (content) {
- var result = this._CCNS_REG1.exec(content);
- if(!result) return cc.size(0, 0);
- return cc.size(parseFloat(result[1]), parseFloat(result[2]));
- },
- _getFrameConfig : function(url){
- var dict = cc.loader.getRes(url);
- cc.assert(dict, cc._LogInfos.spriteFrameCache__getFrameConfig_2, url);
- cc.loader.release(url);//release it in loader
- if(dict._inited){
- this._frameConfigCache[url] = dict;
- return dict;
- }
- this._frameConfigCache[url] = this._parseFrameConfig(dict);
- return this._frameConfigCache[url];
- },
- _getFrameConfigByJsonObject: function(url, jsonObject) {
- cc.assert(jsonObject, cc._LogInfos.spriteFrameCache__getFrameConfig_2, url);
- this._frameConfigCache[url] = this._parseFrameConfig(jsonObject);
- return this._frameConfigCache[url];
- },
- _parseFrameConfig: function(dict) {
- var tempFrames = dict["frames"], tempMeta = dict["metadata"] || dict["meta"];
- var frames = {}, meta = {};
- var format = 0;
- if(tempMeta){//init meta
- var tmpFormat = tempMeta["format"];
- format = (tmpFormat.length <= 1) ? parseInt(tmpFormat) : tmpFormat;
- meta.image = tempMeta["textureFileName"] || tempMeta["textureFileName"] || tempMeta["image"];
- }
- for (var key in tempFrames) {
- var frameDict = tempFrames[key];
- if(!frameDict) continue;
- var tempFrame = {};
- if (format == 0) {
- tempFrame.rect = cc.rect(frameDict["x"], frameDict["y"], frameDict["width"], frameDict["height"]);
- tempFrame.rotated = false;
- tempFrame.offset = cc.p(frameDict["offsetX"], frameDict["offsetY"]);
- var ow = frameDict["originalWidth"];
- var oh = frameDict["originalHeight"];
- if (!ow || !oh) {
- cc.log(cc._LogInfos.spriteFrameCache__getFrameConfig);
- }
- ow = Math.abs(ow);
- oh = Math.abs(oh);
- tempFrame.size = cc.size(ow, oh);
- } else if (format == 1 || format == 2) {
- tempFrame.rect = this._rectFromString(frameDict["frame"]);
- tempFrame.rotated = frameDict["rotated"] || false;
- tempFrame.offset = this._pointFromString(frameDict["offset"]);
- tempFrame.size = this._sizeFromString(frameDict["sourceSize"]);
- } else if (format == 3) {
- var spriteSize = this._sizeFromString(frameDict["spriteSize"]);
- var textureRect = this._rectFromString(frameDict["textureRect"]);
- if (spriteSize) {
- textureRect = cc.rect(textureRect.x, textureRect.y, spriteSize.width, spriteSize.height);
- }
- tempFrame.rect = textureRect;
- tempFrame.rotated = frameDict["textureRotated"] || false;
- tempFrame.offset = this._pointFromString(frameDict["spriteOffset"]);
- tempFrame.size = this._sizeFromString(frameDict["spriteSourceSize"]);
- tempFrame.aliases = frameDict["aliases"];
- } else {
- var tmpFrame = frameDict["frame"], tmpSourceSize = frameDict["sourceSize"];
- key = frameDict["filename"] || key;
- tempFrame.rect = cc.rect(tmpFrame["x"], tmpFrame["y"], tmpFrame["w"], tmpFrame["h"]);
- tempFrame.rotated = frameDict["rotated"] || false;
- tempFrame.offset = cc.p(0, 0);
- tempFrame.size = cc.size(tmpSourceSize["w"], tmpSourceSize["h"]);
- }
- frames[key] = tempFrame;
- }
- return {_inited: true, frames: frames, meta: meta};
- },
- _addSpriteFramesByObject: function(url, jsonObject, texture) {
- cc.assert(url, cc._LogInfos.spriteFrameCache_addSpriteFrames_2);
- if(!jsonObject || !jsonObject["frames"])
- return;
- var frameConfig = this._frameConfigCache[url] || this._getFrameConfigByJsonObject(url, jsonObject);
- this._createSpriteFrames(url, frameConfig, texture);
- },
- _createSpriteFrames: function(url, frameConfig, texture) {
- var frames = frameConfig.frames, meta = frameConfig.meta;
- if(!texture){
- var texturePath = cc.path.changeBasename(url, meta.image || ".png");
- texture = cc.textureCache.addImage(texturePath);
- }else if(texture instanceof cc.Texture2D){
- }else if(cc.isString(texture)){//string
- texture = cc.textureCache.addImage(texture);
- }else{
- cc.assert(0, cc._LogInfos.spriteFrameCache_addSpriteFrames_3);
- }
- var spAliases = this._spriteFramesAliases, spriteFrames = this._spriteFrames;
- for (var key in frames) {
- var frame = frames[key];
- var spriteFrame = spriteFrames[key];
- if (!spriteFrame) {
- spriteFrame = new cc.SpriteFrame(texture, frame.rect, frame.rotated, frame.offset, frame.size);
- var aliases = frame.aliases;
- if(aliases){//set aliases
- for(var i = 0, li = aliases.length; i < li; i++){
- var alias = aliases[i];
- if (spAliases[alias])
- cc.log(cc._LogInfos.spriteFrameCache_addSpriteFrames, alias);
- spAliases[alias] = key;
- }
- }
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS && spriteFrame.isRotated()) {
- var locTexture = spriteFrame.getTexture();
- if (locTexture.isLoaded()) {
- var tempElement = spriteFrame.getTexture().getHtmlElementObj();
- tempElement = cc.Sprite.CanvasRenderCmd._cutRotateImageToCanvas(tempElement, spriteFrame.getRectInPixels());
- var tempTexture = new cc.Texture2D();
- tempTexture.initWithElement(tempElement);
- tempTexture.handleLoadedTexture();
- spriteFrame.setTexture(tempTexture);
- var rect = spriteFrame._rect;
- spriteFrame.setRect(cc.rect(0, 0, rect.width, rect.height));
- }
- }
- spriteFrames[key] = spriteFrame;
- }
- }
- },
- addSpriteFrames: function (url, texture) {
- cc.assert(url, cc._LogInfos.spriteFrameCache_addSpriteFrames_2);
- var dict = this._frameConfigCache[url] || cc.loader.getRes(url);
- if(!dict || !dict["frames"])
- return;
- var frameConfig = this._frameConfigCache[url] || this._getFrameConfig(url);
- this._createSpriteFrames(url, frameConfig, texture);
- },
- _checkConflict: function (dictionary) {
- var framesDict = dictionary["frames"];
- for (var key in framesDict) {
- if (this._spriteFrames[key]) {
- cc.log(cc._LogInfos.spriteFrameCache__checkConflict, key);
- }
- }
- },
- addSpriteFrame: function (frame, frameName) {
- this._spriteFrames[frameName] = frame;
- },
- removeSpriteFrames: function () {
- this._spriteFrames = {};
- this._spriteFramesAliases = {};
- },
- removeSpriteFrameByName: function (name) {
- if (!name) {
- return;
- }
- if (this._spriteFramesAliases[name]) {
- delete(this._spriteFramesAliases[name]);
- }
- if (this._spriteFrames[name]) {
- delete(this._spriteFrames[name]);
- }
- },
- removeSpriteFramesFromFile: function (url) {
- var self = this, spriteFrames = self._spriteFrames,
- aliases = self._spriteFramesAliases, cfg = self._frameConfigCache[url];
- if(!cfg) return;
- var frames = cfg.frames;
- for (var key in frames) {
- if (spriteFrames[key]) {
- delete(spriteFrames[key]);
- for (var alias in aliases) {//remove alias
- if(aliases[alias] === key) delete aliases[alias];
- }
- }
- }
- },
- removeSpriteFramesFromTexture: function (texture) {
- var self = this, spriteFrames = self._spriteFrames, aliases = self._spriteFramesAliases;
- for (var key in spriteFrames) {
- var frame = spriteFrames[key];
- if (frame && (frame.getTexture() === texture)) {
- delete(spriteFrames[key]);
- for (var alias in aliases) {//remove alias
- if(aliases[alias] === key) delete aliases[alias];
- }
- }
- }
- },
- getSpriteFrame: function (name) {
- var self = this, frame = self._spriteFrames[name];
- if (!frame) {
- var key = self._spriteFramesAliases[name];
- if (key) {
- frame = self._spriteFrames[key.toString()];
- if(!frame) delete self._spriteFramesAliases[name];
- }
- }
- return frame;
- },
- _clear: function () {
- this._spriteFrames = {};
- this._spriteFramesAliases = {};
- this._frameConfigCache = {};
- }
- };
- cc.g_NumberOfDraws = 0;
- cc.Director = cc.Class.extend({
- _landscape: false,
- _nextDeltaTimeZero: false,
- _paused: false,
- _purgeDirectorInNextLoop: false,
- _sendCleanupToScene: false,
- _animationInterval: 0.0,
- _oldAnimationInterval: 0.0,
- _projection: 0,
- _contentScaleFactor: 1.0,
- _deltaTime: 0.0,
- _winSizeInPoints: null,
- _lastUpdate: null,
- _nextScene: null,
- _notificationNode: null,
- _openGLView: null,
- _scenesStack: null,
- _projectionDelegate: null,
- _runningScene: null,
- _totalFrames: 0,
- _secondsPerFrame: 0,
- _dirtyRegion: null,
- _scheduler: null,
- _actionManager: null,
- _eventProjectionChanged: null,
- _eventAfterUpdate: null,
- _eventAfterVisit: null,
- _eventAfterDraw: null,
- ctor: function () {
- var self = this;
- self._lastUpdate = Date.now();
- cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function () {
- self._lastUpdate = Date.now();
- });
- },
- init: function () {
- this._oldAnimationInterval = this._animationInterval = 1.0 / cc.defaultFPS;
- this._scenesStack = [];
- this._projection = cc.Director.PROJECTION_DEFAULT;
- this._projectionDelegate = null;
- this._totalFrames = 0;
- this._lastUpdate = Date.now();
- this._paused = false;
- this._purgeDirectorInNextLoop = false;
- this._winSizeInPoints = cc.size(0, 0);
- this._openGLView = null;
- this._contentScaleFactor = 1.0;
- this._scheduler = new cc.Scheduler();
- if(cc.ActionManager){
- this._actionManager = new cc.ActionManager();
- this._scheduler.scheduleUpdate(this._actionManager, cc.Scheduler.PRIORITY_SYSTEM, false);
- }else{
- this._actionManager = null;
- }
- this._eventAfterUpdate = new cc.EventCustom(cc.Director.EVENT_AFTER_UPDATE);
- this._eventAfterUpdate.setUserData(this);
- this._eventAfterVisit = new cc.EventCustom(cc.Director.EVENT_AFTER_VISIT);
- this._eventAfterVisit.setUserData(this);
- this._eventAfterDraw = new cc.EventCustom(cc.Director.EVENT_AFTER_DRAW);
- this._eventAfterDraw.setUserData(this);
- this._eventProjectionChanged = new cc.EventCustom(cc.Director.EVENT_PROJECTION_CHANGED);
- this._eventProjectionChanged.setUserData(this);
- return true;
- },
- calculateDeltaTime: function () {
- var now = Date.now();
- if (this._nextDeltaTimeZero) {
- this._deltaTime = 0;
- this._nextDeltaTimeZero = false;
- } else {
- this._deltaTime = (now - this._lastUpdate) / 1000;
- }
- if ((cc.game.config[cc.game.CONFIG_KEY.debugMode] > 0) && (this._deltaTime > 0.2))
- this._deltaTime = 1 / 60.0;
- this._lastUpdate = now;
- },
- convertToGL: function (uiPoint) {
- var docElem = document.documentElement;
- var view = cc.view;
- var box = element.getBoundingClientRect();
- box.left += window.pageXOffset - docElem.clientLeft;
- box.top += window.pageYOffset - docElem.clientTop;
- var x = view._devicePixelRatio * (uiPoint.x - box.left);
- var y = view._devicePixelRatio * (box.top + box.height - uiPoint.y);
- return view._isRotated ? {x: view._viewPortRect.width - y, y: x} : {x: x, y: y};
- },
- convertToUI: function (glPoint) {
- var docElem = document.documentElement;
- var view = cc.view;
- var box = element.getBoundingClientRect();
- box.left += window.pageXOffset - docElem.clientLeft;
- box.top += window.pageYOffset - docElem.clientTop;
- var uiPoint = {x: 0, y: 0};
- if (view._isRotated) {
- uiPoint.x = box.left + glPoint.y / view._devicePixelRatio;
- uiPoint.y = box.top + box.height - (view._viewPortRect.width - glPoint.x) / view._devicePixelRatio;
- }
- else {
- uiPoint.x = box.left + glPoint.x / view._devicePixelRatio;
- uiPoint.y = box.top + box.height - glPoint.y / view._devicePixelRatio;
- }
- return uiPoint;
- },
- drawScene: function () {
- var renderer = cc.renderer;
- this.calculateDeltaTime();
- if (!this._paused) {
- this._scheduler.update(this._deltaTime);
- cc.eventManager.dispatchEvent(this._eventAfterUpdate);
- }
- if (this._nextScene) {
- this.setNextScene();
- }
- if (this._beforeVisitScene)
- this._beforeVisitScene();
- if (this._runningScene) {
- if (renderer.childrenOrderDirty) {
- cc.renderer.clearRenderCommands();
- cc.renderer.assignedZ = 0;
- this._runningScene._renderCmd._curLevel = 0;
- this._runningScene.visit();
- renderer.resetFlag();
- }
- else if (renderer.transformDirty()) {
- renderer.transform();
- }
- }
- renderer.clear();
- if (this._notificationNode)
- this._notificationNode.visit();
- cc.eventManager.dispatchEvent(this._eventAfterVisit);
- cc.g_NumberOfDraws = 0;
- if (this._afterVisitScene)
- this._afterVisitScene();
- renderer.rendering(cc._renderContext);
- this._totalFrames++;
- cc.eventManager.dispatchEvent(this._eventAfterDraw);
- this._calculateMPF();
- },
- _beforeVisitScene: null,
- _afterVisitScene: null,
- end: function () {
- this._purgeDirectorInNextLoop = true;
- },
- getContentScaleFactor: function () {
- return this._contentScaleFactor;
- },
- getNotificationNode: function () {
- return this._notificationNode;
- },
- getWinSize: function () {
- return cc.size(this._winSizeInPoints);
- },
- getWinSizeInPixels: function () {
- return cc.size(this._winSizeInPoints.width * this._contentScaleFactor, this._winSizeInPoints.height * this._contentScaleFactor);
- },
- getVisibleSize: null,
- getVisibleOrigin: null,
- getZEye: null,
- pause: function () {
- if (this._paused)
- return;
- this._oldAnimationInterval = this._animationInterval;
- this.setAnimationInterval(1 / 4.0);
- this._paused = true;
- },
- popScene: function () {
- cc.assert(this._runningScene, cc._LogInfos.Director_popScene);
- this._scenesStack.pop();
- var c = this._scenesStack.length;
- if (c === 0)
- this.end();
- else {
- this._sendCleanupToScene = true;
- this._nextScene = this._scenesStack[c - 1];
- }
- },
- purgeCachedData: function () {
- cc.animationCache._clear();
- cc.spriteFrameCache._clear();
- cc.textureCache._clear();
- },
- purgeDirector: function () {
- this.getScheduler().unscheduleAll();
- if (cc.eventManager)
- cc.eventManager.setEnabled(false);
- if (this._runningScene) {
- this._runningScene.onExitTransitionDidStart();
- this._runningScene.onExit();
- this._runningScene.cleanup();
- }
- this._runningScene = null;
- this._nextScene = null;
- this._scenesStack.length = 0;
- this.stopAnimation();
- this.purgeCachedData();
- cc.checkGLErrorDebug();
- },
- pushScene: function (scene) {
- cc.assert(scene, cc._LogInfos.Director_pushScene);
- this._sendCleanupToScene = false;
- this._scenesStack.push(scene);
- this._nextScene = scene;
- },
- runScene: function (scene) {
- cc.assert(scene, cc._LogInfos.Director_pushScene);
- if (!this._runningScene) {
- this.pushScene(scene);
- this.startAnimation();
- } else {
- var i = this._scenesStack.length;
- if (i === 0) {
- this._sendCleanupToScene = true;
- this._scenesStack[i] = scene;
- this._nextScene = scene;
- } else {
- this._sendCleanupToScene = true;
- this._scenesStack[i - 1] = scene;
- this._nextScene = scene;
- }
- }
- },
- resume: function () {
- if (!this._paused) {
- return;
- }
- this.setAnimationInterval(this._oldAnimationInterval);
- this._lastUpdate = Date.now();
- if (!this._lastUpdate) {
- cc.log(cc._LogInfos.Director_resume);
- }
- this._paused = false;
- this._deltaTime = 0;
- },
- setContentScaleFactor: function (scaleFactor) {
- if (scaleFactor !== this._contentScaleFactor) {
- this._contentScaleFactor = scaleFactor;
- }
- },
- setDepthTest: null,
- setClearColor: null,
- setDefaultValues: function () {
- },
- setNextDeltaTimeZero: function (nextDeltaTimeZero) {
- this._nextDeltaTimeZero = nextDeltaTimeZero;
- },
- setNextScene: function () {
- var runningIsTransition = false, newIsTransition = false;
- if (cc.TransitionScene) {
- runningIsTransition = this._runningScene ? this._runningScene instanceof cc.TransitionScene : false;
- newIsTransition = this._nextScene ? this._nextScene instanceof cc.TransitionScene : false;
- }
- if (!newIsTransition) {
- var locRunningScene = this._runningScene;
- if (locRunningScene) {
- locRunningScene.onExitTransitionDidStart();
- locRunningScene.onExit();
- }
- if (this._sendCleanupToScene && locRunningScene)
- locRunningScene.cleanup();
- }
- this._runningScene = this._nextScene;
- cc.renderer.childrenOrderDirty = true;
- this._nextScene = null;
- if ((!runningIsTransition) && (this._runningScene !== null)) {
- this._runningScene.onEnter();
- this._runningScene.onEnterTransitionDidFinish();
- }
- },
- setNotificationNode: function (node) {
- cc.renderer.childrenOrderDirty = true;
- if(this._notificationNode){
- this._notificationNode.onExitTransitionDidStart();
- this._notificationNode.onExit();
- this._notificationNode.cleanup();
- }
- this._notificationNode = node;
- if(!node)
- return;
- this._notificationNode.onEnter();
- this._notificationNode.onEnterTransitionDidFinish();
- },
- getDelegate: function () {
- return this._projectionDelegate;
- },
- setDelegate: function (delegate) {
- this._projectionDelegate = delegate;
- },
- setOpenGLView: null,
- setProjection: null,
- setViewport: null,
- getOpenGLView: null,
- getProjection: null,
- setAlphaBlending: null,
- isSendCleanupToScene: function () {
- return this._sendCleanupToScene;
- },
- getRunningScene: function () {
- return this._runningScene;
- },
- getAnimationInterval: function () {
- return this._animationInterval;
- },
- isDisplayStats: function () {
- return cc.profiler ? cc.profiler.isShowingStats() : false;
- },
- setDisplayStats: function (displayStats) {
- if (cc.profiler) {
- displayStats ? cc.profiler.showStats() : cc.profiler.hideStats();
- }
- },
- getSecondsPerFrame: function () {
- return this._secondsPerFrame;
- },
- isNextDeltaTimeZero: function () {
- return this._nextDeltaTimeZero;
- },
- isPaused: function () {
- return this._paused;
- },
- getTotalFrames: function () {
- return this._totalFrames;
- },
- popToRootScene: function () {
- this.popToSceneStackLevel(1);
- },
- popToSceneStackLevel: function (level) {
- cc.assert(this._runningScene, cc._LogInfos.Director_popToSceneStackLevel_2);
- var locScenesStack = this._scenesStack;
- var c = locScenesStack.length;
- if (level === 0) {
- this.end();
- return;
- }
- if (level >= c)
- return;
- while (c > level) {
- var current = locScenesStack.pop();
- if (current.running) {
- current.onExitTransitionDidStart();
- current.onExit();
- }
- current.cleanup();
- c--;
- }
- this._nextScene = locScenesStack[locScenesStack.length - 1];
- this._sendCleanupToScene = true;
- },
- getScheduler: function () {
- return this._scheduler;
- },
- setScheduler: function (scheduler) {
- if (this._scheduler !== scheduler) {
- this._scheduler = scheduler;
- }
- },
- getActionManager: function () {
- return this._actionManager;
- },
- setActionManager: function (actionManager) {
- if (this._actionManager !== actionManager) {
- this._actionManager = actionManager;
- }
- },
- getDeltaTime: function () {
- return this._deltaTime;
- },
- _calculateMPF: function () {
- var now = Date.now();
- this._secondsPerFrame = (now - this._lastUpdate) / 1000;
- }
- });
- cc.Director.EVENT_PROJECTION_CHANGED = "director_projection_changed";
- cc.Director.EVENT_AFTER_UPDATE = "director_after_update";
- cc.Director.EVENT_AFTER_VISIT = "director_after_visit";
- cc.Director.EVENT_AFTER_DRAW = "director_after_draw";
- cc.DisplayLinkDirector = cc.Director.extend({
- invalid: false,
- startAnimation: function () {
- this._nextDeltaTimeZero = true;
- this.invalid = false;
- },
- mainLoop: function () {
- if (this._purgeDirectorInNextLoop) {
- this._purgeDirectorInNextLoop = false;
- this.purgeDirector();
- }
- else if (!this.invalid) {
- this.drawScene();
- }
- },
- stopAnimation: function () {
- this.invalid = true;
- },
- setAnimationInterval: function (value) {
- this._animationInterval = value;
- if (!this.invalid) {
- this.stopAnimation();
- this.startAnimation();
- }
- }
- });
- cc.Director.sharedDirector = null;
- cc.Director.firstUseDirector = true;
- cc.Director._getInstance = function () {
- if (cc.Director.firstUseDirector) {
- cc.Director.firstUseDirector = false;
- cc.Director.sharedDirector = new cc.DisplayLinkDirector();
- cc.Director.sharedDirector.init();
- }
- return cc.Director.sharedDirector;
- };
- cc.defaultFPS = 60;
- cc.Director.PROJECTION_2D = 0;
- cc.Director.PROJECTION_3D = 1;
- cc.Director.PROJECTION_CUSTOM = 3;
- cc.Director.PROJECTION_DEFAULT = cc.Director.PROJECTION_2D;
- cc.game.addEventListener(cc.game.EVENT_RENDERER_INITED, function () {
- if (cc._renderType === cc.game.RENDER_TYPE_CANVAS) {
- var _p = cc.Director.prototype;
- _p.getProjection = function (projection) {
- return this._projection;
- };
- _p.setProjection = function (projection) {
- this._projection = projection;
- cc.eventManager.dispatchEvent(this._eventProjectionChanged);
- };
- _p.setDepthTest = function () {
- };
- _p.setClearColor = function (clearColor) {
- cc.renderer._clearColor = clearColor;
- cc.renderer._clearFillStyle = 'rgb(' + clearColor.r + ',' + clearColor.g + ',' + clearColor.b +')' ;
- };
- _p.setOpenGLView = function (openGLView) {
- this._winSizeInPoints.width = cc._canvas.width;
- this._winSizeInPoints.height = cc._canvas.height;
- this._openGLView = openGLView || cc.view;
- if (cc.eventManager)
- cc.eventManager.setEnabled(true);
- };
- _p.getVisibleSize = function () {
- return this.getWinSize();
- };
- _p.getVisibleOrigin = function () {
- return cc.p(0, 0);
- };
- } else {
- cc.Director._fpsImage = new Image();
- cc.Director._fpsImage.addEventListener("load", function () {
- cc.Director._fpsImageLoaded = true;
- });
- if (cc._fpsImage) {
- cc.Director._fpsImage.src = cc._fpsImage;
- }
- }
- });
- cc.PRIORITY_NON_SYSTEM = cc.PRIORITY_SYSTEM + 1;
- cc.ListEntry = function (prev, next, callback, target, priority, paused, markedForDeletion) {
- this.prev = prev;
- this.next = next;
- this.callback = callback;
- this.target = target;
- this.priority = priority;
- this.paused = paused;
- this.markedForDeletion = markedForDeletion;
- };
- cc.HashUpdateEntry = function (list, entry, target, callback, hh) {
- this.list = list;
- this.entry = entry;
- this.target = target;
- this.callback = callback;
- this.hh = hh;
- };
- cc.HashTimerEntry = cc.hashSelectorEntry = function (timers, target, timerIndex, currentTimer, currentTimerSalvaged, paused, hh) {
- var _t = this;
- _t.timers = timers;
- _t.target = target;
- _t.timerIndex = timerIndex;
- _t.currentTimer = currentTimer;
- _t.currentTimerSalvaged = currentTimerSalvaged;
- _t.paused = paused;
- _t.hh = hh;
- };
- cc.Timer = cc.Class.extend({
- _scheduler: null,
- _elapsed:0.0,
- _runForever:false,
- _useDelay:false,
- _timesExecuted:0,
- _repeat:0,
- _delay:0,
- _interval:0.0,
- getInterval : function(){return this._interval;},
- setInterval : function(interval){this._interval = interval;},
- setupTimerWithInterval: function(seconds, repeat, delay){
- this._elapsed = -1;
- this._interval = seconds;
- this._delay = delay;
- this._useDelay = (this._delay > 0);
- this._repeat = repeat;
- this._runForever = (this._repeat === cc.REPEAT_FOREVER);
- },
- trigger: function(){
- return 0;
- },
- cancel: function(){
- return 0;
- },
- ctor:function () {
- this._scheduler = null;
- this._elapsed = -1;
- this._runForever = false;
- this._useDelay = false;
- this._timesExecuted = 0;
- this._repeat = 0;
- this._delay = 0;
- this._interval = 0;
- },
- update:function (dt) {
- if (this._elapsed === -1) {
- this._elapsed = 0;
- this._timesExecuted = 0;
- } else {
- this._elapsed += dt;
- if (this._runForever && !this._useDelay) {//standard timer usage
- if (this._elapsed >= this._interval) {
- this.trigger();
- this._elapsed = 0;
- }
- } else {//advanced usage
- if (this._useDelay) {
- if (this._elapsed >= this._delay) {
- this.trigger();
- this._elapsed -= this._delay;
- this._timesExecuted += 1;
- this._useDelay = false;
- }
- } else {
- if (this._elapsed >= this._interval) {
- this.trigger();
- this._elapsed = 0;
- this._timesExecuted += 1;
- }
- }
- if (!this._runForever && this._timesExecuted > this._repeat)
- this.cancel();
- }
- }
- }
- });
- cc.TimerTargetSelector = cc.Timer.extend({
- _target: null,
- _selector: null,
- ctor: function(){
- this._target = null;
- this._selector = null;
- },
- initWithSelector: function(scheduler, selector, target, seconds, repeat, delay){
- this._scheduler = scheduler;
- this._target = target;
- this._selector = selector;
- this.setupTimerWithInterval(seconds, repeat, delay);
- return true;
- },
- getSelector: function(){
- return this._selector;
- },
- trigger: function(){
- if (this._target && this._selector){
- this._target.call(this._selector, this._elapsed);
- }
- },
- cancel: function(){
- this._scheduler.unschedule(this._selector, this._target);
- }
- });
- cc.TimerTargetCallback = cc.Timer.extend({
- _target: null,
- _callback: null,
- _key: null,
- ctor: function(){
- this._target = null;
- this._callback = null;
- },
- initWithCallback: function(scheduler, callback, target, key, seconds, repeat, delay){
- this._scheduler = scheduler;
- this._target = target;
- this._callback = callback;
- this._key = key;
- this.setupTimerWithInterval(seconds, repeat, delay);
- return true;
- },
- getCallback: function(){
- return this._callback;
- },
- getKey: function(){
- return this._key;
- },
- trigger: function(){
- if(this._callback)
- this._callback.call(this._target, this._elapsed);
- },
- cancel: function(){
- this._scheduler.unschedule(this._callback, this._target);
- }
- });
- cc.Scheduler = cc.Class.extend({
- _timeScale:1.0,
- _updatesNegList: null,
- _updates0List: null,
- _updatesPosList: null,
- _hashForTimers:null,
- _arrayForTimers:null,
- _hashForUpdates:null,
- _currentTarget:null,
- _currentTargetSalvaged:false,
- _updateHashLocked:false,
- ctor:function () {
- this._timeScale = 1.0;
- this._updatesNegList = [];
- this._updates0List = [];
- this._updatesPosList = [];
- this._hashForUpdates = {};
- this._hashForTimers = {};
- this._currentTarget = null;
- this._currentTargetSalvaged = false;
- this._updateHashLocked = false;
- this._arrayForTimers = [];
- },
- _schedulePerFrame: function(callback, target, priority, paused){
- var hashElement = this._hashForUpdates[target.__instanceId];
- if (hashElement && hashElement.entry){
- if (hashElement.entry.priority !== priority){
- if (this._updateHashLocked){
- cc.log("warning: you CANNOT change update priority in scheduled function");
- hashElement.entry.markedForDeletion = false;
- hashElement.entry.paused = paused;
- return;
- }else{
- this.unscheduleUpdate(target);
- }
- }else{
- hashElement.entry.markedForDeletion = false;
- hashElement.entry.paused = paused;
- return;
- }
- }
- if (priority === 0){
- this._appendIn(this._updates0List, callback, target, paused);
- }else if (priority < 0){
- this._priorityIn(this._updatesNegList, callback, target, priority, paused);
- }else{
- this._priorityIn(this._updatesPosList, callback, target, priority, paused);
- }
- },
- _removeHashElement:function (element) {
- delete this._hashForTimers[element.target.__instanceId];
- cc.arrayRemoveObject(this._arrayForTimers, element);
- element.Timer = null;
- element.target = null;
- element = null;
- },
- _removeUpdateFromHash:function (entry) {
- var self = this, element = self._hashForUpdates[entry.target.__instanceId];
- if (element) {
- cc.arrayRemoveObject(element.list, element.entry);
- delete self._hashForUpdates[element.target.__instanceId];
- element.entry = null;
- element.target = null;
- }
- },
- _priorityIn:function (ppList, callback, target, priority, paused) {
- var self = this,
- listElement = new cc.ListEntry(null, null, callback, target, priority, paused, false);
- if (!ppList) {
- ppList = [];
- ppList.push(listElement);
- } else {
- var index2Insert = ppList.length - 1;
- for(var i = 0; i <= index2Insert; i++){
- if (priority < ppList[i].priority) {
- index2Insert = i;
- break;
- }
- }
- ppList.splice(i, 0, listElement);
- }
- self._hashForUpdates[target.__instanceId] = new cc.HashUpdateEntry(ppList, listElement, target, null);
- return ppList;
- },
- _appendIn:function (ppList, callback, target, paused) {
- var self = this, listElement = new cc.ListEntry(null, null, callback, target, 0, paused, false);
- ppList.push(listElement);
- self._hashForUpdates[target.__instanceId] = new cc.HashUpdateEntry(ppList, listElement, target, null, null);
- },
- setTimeScale:function (timeScale) {
- this._timeScale = timeScale;
- },
- getTimeScale:function () {
- return this._timeScale;
- },
- update:function (dt) {
- this._updateHashLocked = true;
- if(this._timeScale !== 1)
- dt *= this._timeScale;
- var i, list, len, entry;
- for(i=0,list=this._updatesNegList, len = list.length; i<len; i++){
- entry = list[i];
- if(!entry.paused && !entry.markedForDeletion)
- entry.callback(dt);
- }
- for(i=0, list=this._updates0List, len=list.length; i<len; i++){
- entry = list[i];
- if (!entry.paused && !entry.markedForDeletion)
- entry.callback(dt);
- }
- for(i=0, list=this._updatesPosList, len=list.length; i<len; i++){
- entry = list[i];
- if (!entry.paused && !entry.markedForDeletion)
- entry.callback(dt);
- }
- var elt, arr = this._arrayForTimers;
- for(i=0; i<arr.length; i++){
- elt = arr[i];
- this._currentTarget = elt;
- this._currentTargetSalvaged = false;
- if (!elt.paused){
- for (elt.timerIndex = 0; elt.timerIndex < elt.timers.length; ++(elt.timerIndex)){
- elt.currentTimer = elt.timers[elt.timerIndex];
- elt.currentTimerSalvaged = false;
- elt.currentTimer.update(dt);
- elt.currentTimer = null;
- }
- }
- if (this._currentTargetSalvaged && this._currentTarget.timers.length === 0)
- this._removeHashElement(this._currentTarget);
- }
- for(i=0,list=this._updatesNegList; i<list.length; ){
- entry = list[i];
- if(entry.markedForDeletion)
- this._removeUpdateFromHash(entry);
- else
- i++;
- }
- for(i=0, list=this._updates0List; i<list.length; ){
- entry = list[i];
- if (entry.markedForDeletion)
- this._removeUpdateFromHash(entry);
- else
- i++;
- }
- for(i=0, list=this._updatesPosList; i<list.length; ){
- entry = list[i];
- if (entry.markedForDeletion)
- this._removeUpdateFromHash(entry);
- else
- i++;
- }
- this._updateHashLocked = false;
- this._currentTarget = null;
- },
- scheduleCallbackForTarget: function(target, callback_fn, interval, repeat, delay, paused){
- this.schedule(callback_fn, target, interval, repeat, delay, paused, target.__instanceId + "");
- },
- schedule: function(callback, target, interval, repeat, delay, paused, key){
- var isSelector = false;
- if(typeof callback !== "function"){
- var selector = callback;
- isSelector = true;
- }
- if(isSelector === false){
- if(arguments.length === 4 || arguments.length === 5){
- key = delay;
- paused = repeat;
- delay = 0;
- repeat = cc.REPEAT_FOREVER;
- }
- }else{
- if(arguments.length === 4){
- paused = repeat;
- repeat = cc.REPEAT_FOREVER;
- delay = 0;
- }
- }
- if (key === undefined) {
- key = target.__instanceId + "";
- }
- cc.assert(target, cc._LogInfos.Scheduler_scheduleCallbackForTarget_3);
- var element = this._hashForTimers[target.__instanceId];
- if(!element){
- element = new cc.HashTimerEntry(null, target, 0, null, null, paused, null);
- this._arrayForTimers.push(element);
- this._hashForTimers[target.__instanceId] = element;
- }else{
- cc.assert(element.paused === paused, "");
- }
- var timer, i;
- if (element.timers == null) {
- element.timers = [];
- } else if(isSelector === false) {
- for (i = 0; i < element.timers.length; i++) {
- timer = element.timers[i];
- if (callback === timer._callback) {
- cc.log(cc._LogInfos.Scheduler_scheduleCallbackForTarget, timer.getInterval().toFixed(4), interval.toFixed(4));
- timer._interval = interval;
- return;
- }
- }
- }else{
- for (i = 0; i < element.timers.length; ++i){
- timer =element.timers[i];
- if (timer && selector === timer.getSelector()){
- cc.log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: %.4f to %.4f", timer.getInterval(), interval);
- timer.setInterval(interval);
- return;
- }
- }
- }
- if(isSelector === false){
- timer = new cc.TimerTargetCallback();
- timer.initWithCallback(this, callback, target, key, interval, repeat, delay);
- element.timers.push(timer);
- }else{
- timer = new cc.TimerTargetSelector();
- timer.initWithSelector(this, selector, target, interval, repeat, delay);
- element.timers.push(timer);
- }
- },
- scheduleUpdate: function(target, priority, paused){
- this._schedulePerFrame(function(dt){
- target.update(dt);
- }, target, priority, paused);
- },
- _getUnscheduleMark: function(key, timer){
- switch (typeof key){
- case "number":
- case "string":
- return key === timer.getKey();
- case "function":
- return key === timer._callback;
- default:
- return key === timer.getSelector();
- }
- },
- unschedule: function(key, target){
- if (!target || !key)
- return;
- var self = this, element = self._hashForTimers[target.__instanceId];
- if (element) {
- var timers = element.timers;
- for(var i = 0, li = timers.length; i < li; i++){
- var timer = timers[i];
- if (this._getUnscheduleMark(key, timer)) {
- if ((timer === element.currentTimer) && (!element.currentTimerSalvaged)) {
- element.currentTimerSalvaged = true;
- }
- timers.splice(i, 1);
- if (element.timerIndex >= i) {
- element.timerIndex--;
- }
- if (timers.length === 0) {
- if (self._currentTarget === element) {
- self._currentTargetSalvaged = true;
- } else {
- self._removeHashElement(element);
- }
- }
- return;
- }
- }
- }
- },
- unscheduleUpdate: function(target){
- if (target == null)
- return;
- var element = this._hashForUpdates[target.__instanceId];
- if (element){
- if (this._updateHashLocked){
- element.entry.markedForDeletion = true;
- }else{
- this._removeUpdateFromHash(element.entry);
- }
- }
- },
- unscheduleAllForTarget: function(target){
- if (target == null){
- return;
- }
- var element = this._hashForTimers[target.__instanceId];
- if (element){
- if (element.timers.indexOf(element.currentTimer) > -1
- && (! element.currentTimerSalvaged)){
- element.currentTimerSalvaged = true;
- }
- element.timers.length = 0;
- if (this._currentTarget === element){
- this._currentTargetSalvaged = true;
- }else{
- this._removeHashElement(element);
- }
- }
- this.unscheduleUpdate(target);
- },
- unscheduleAll: function(){
- this.unscheduleAllWithMinPriority(cc.Scheduler.PRIORITY_SYSTEM);
- },
- unscheduleAllWithMinPriority: function(minPriority){
- var i, element, arr = this._arrayForTimers;
- for(i=arr.length-1; i>=0; i--){
- element = arr[i];
- this.unscheduleAllForTarget(element.target);
- }
- var entry;
- var temp_length = 0;
- if(minPriority < 0){
- for(i=0; i<this._updatesNegList.length; ){
- temp_length = this._updatesNegList.length;
- entry = this._updatesNegList[i];
- if(entry && entry.priority >= minPriority)
- this.unscheduleUpdate(entry.target);
- if (temp_length == this._updatesNegList.length)
- i++;
- }
- }
- if(minPriority <= 0){
- for(i=0; i<this._updates0List.length; ){
- temp_length = this._updates0List.length;
- entry = this._updates0List[i];
- if (entry)
- this.unscheduleUpdate(entry.target);
- if (temp_length == this._updates0List.length)
- i++;
- }
- }
- for(i=0; i<this._updatesPosList.length; ){
- temp_length = this._updatesPosList.length;
- entry = this._updatesPosList[i];
- if(entry && entry.priority >= minPriority)
- this.unscheduleUpdate(entry.target);
- if (temp_length == this._updatesPosList.length)
- i++;
- }
- },
- isScheduled: function(key, target){
- cc.assert(key, "Argument key must not be empty");
- cc.assert(target, "Argument target must be non-nullptr");
- var element = this._hashForUpdates[target.__instanceId];
- if (!element){
- return false;
- }
- if (element.timers == null){
- return false;
- }else{
- var timers = element.timers;
- for (var i = 0; i < timers.length; ++i){
- var timer = timers[i];
- if (key === timer.getKey()){
- return true;
- }
- }
- return false;
- }
- },
- pauseAllTargets:function () {
- return this.pauseAllTargetsWithMinPriority(cc.Scheduler.PRIORITY_SYSTEM);
- },
- pauseAllTargetsWithMinPriority:function (minPriority) {
- var idsWithSelectors = [];
- var self = this, element, locArrayForTimers = self._arrayForTimers;
- var i, li;
- for(i = 0, li = locArrayForTimers.length; i < li; i++){
- element = locArrayForTimers[i];
- if (element) {
- element.paused = true;
- idsWithSelectors.push(element.target);
- }
- }
- var entry;
- if(minPriority < 0){
- for(i=0; i<this._updatesNegList.length; i++){
- entry = this._updatesNegList[i];
- if (entry) {
- if(entry.priority >= minPriority){
- entry.paused = true;
- idsWithSelectors.push(entry.target);
- }
- }
- }
- }
- if(minPriority <= 0){
- for(i=0; i<this._updates0List.length; i++){
- entry = this._updates0List[i];
- if (entry) {
- entry.paused = true;
- idsWithSelectors.push(entry.target);
- }
- }
- }
- for(i=0; i<this._updatesPosList.length; i++){
- entry = this._updatesPosList[i];
- if (entry) {
- if(entry.priority >= minPriority){
- entry.paused = true;
- idsWithSelectors.push(entry.target);
- }
- }
- }
- return idsWithSelectors;
- },
- resumeTargets:function (targetsToResume) {
- if (!targetsToResume)
- return;
- for (var i = 0; i < targetsToResume.length; i++) {
- this.resumeTarget(targetsToResume[i]);
- }
- },
- pauseTarget:function (target) {
- cc.assert(target, cc._LogInfos.Scheduler_pauseTarget);
- var self = this, element = self._hashForTimers[target.__instanceId];
- if (element) {
- element.paused = true;
- }
- var elementUpdate = self._hashForUpdates[target.__instanceId];
- if (elementUpdate) {
- elementUpdate.entry.paused = true;
- }
- },
- resumeTarget:function (target) {
- cc.assert(target, cc._LogInfos.Scheduler_resumeTarget);
- var self = this, element = self._hashForTimers[target.__instanceId];
- if (element) {
- element.paused = false;
- }
- var elementUpdate = self._hashForUpdates[target.__instanceId];
- if (elementUpdate) {
- elementUpdate.entry.paused = false;
- }
- },
- isTargetPaused:function (target) {
- cc.assert(target, cc._LogInfos.Scheduler_isTargetPaused);
- var element = this._hashForTimers[target.__instanceId];
- if (element) {
- return element.paused;
- }
- var elementUpdate = this._hashForUpdates[target.__instanceId];
- if (elementUpdate) {
- return elementUpdate.entry.paused;
- }
- return false;
- },
- scheduleUpdateForTarget: function(target, priority, paused){
- this.scheduleUpdate(target, priority, paused);
- },
- unscheduleCallbackForTarget:function (target, callback) {
- this.unschedule(callback, target);
- },
- unscheduleUpdateForTarget:function (target) {
- this.unscheduleUpdate(target);
- },
- unscheduleAllCallbacksForTarget: function(target){
- this.unschedule(target.__instanceId + "", target);
- },
- unscheduleAllCallbacks: function(){
- this.unscheduleAllWithMinPriority(cc.Scheduler.PRIORITY_SYSTEM);
- },
- unscheduleAllCallbacksWithMinPriority:function (minPriority) {
- this.unscheduleAllWithMinPriority(minPriority);
- }
- });
- cc.Scheduler.PRIORITY_SYSTEM = (-2147483647 - 1);
- cc._tmp.PrototypeLabelTTF = function () {
- var _p = cc.LabelTTF.prototype;
- cc.defineGetterSetter(_p, "color", _p.getColor, _p.setColor);
- cc.defineGetterSetter(_p, "opacity", _p.getOpacity, _p.setOpacity);
- _p.string;
- cc.defineGetterSetter(_p, "string", _p.getString, _p.setString);
- _p.textAlign;
- cc.defineGetterSetter(_p, "textAlign", _p.getHorizontalAlignment, _p.setHorizontalAlignment);
- _p.verticalAlign;
- cc.defineGetterSetter(_p, "verticalAlign", _p.getVerticalAlignment, _p.setVerticalAlignment);
- _p.fontSize;
- cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize);
- _p.fontName;
- cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
- _p.font;
- cc.defineGetterSetter(_p, "font", _p._getFont, _p._setFont);
- _p.boundingSize;
- _p.boundingWidth;
- cc.defineGetterSetter(_p, "boundingWidth", _p._getBoundingWidth, _p._setBoundingWidth);
- _p.boundingHeight;
- cc.defineGetterSetter(_p, "boundingHeight", _p._getBoundingHeight, _p._setBoundingHeight);
- _p.fillStyle;
- cc.defineGetterSetter(_p, "fillStyle", _p._getFillStyle, _p.setFontFillColor);
- _p.strokeStyle;
- cc.defineGetterSetter(_p, "strokeStyle", _p._getStrokeStyle, _p._setStrokeStyle);
- _p.lineWidth;
- cc.defineGetterSetter(_p, "lineWidth", _p._getLineWidth, _p._setLineWidth);
- _p.shadowOffset;
- _p.shadowOffsetX;
- cc.defineGetterSetter(_p, "shadowOffsetX", _p._getShadowOffsetX, _p._setShadowOffsetX);
- _p.shadowOffsetY;
- cc.defineGetterSetter(_p, "shadowOffsetY", _p._getShadowOffsetY, _p._setShadowOffsetY);
- _p.shadowOpacity;
- cc.defineGetterSetter(_p, "shadowOpacity", _p._getShadowOpacity, _p._setShadowOpacity);
- _p.shadowBlur;
- cc.defineGetterSetter(_p, "shadowBlur", _p._getShadowBlur, _p._setShadowBlur);
- };
- cc.LabelTTF = cc.Sprite.extend({
- _dimensions: null,
- _hAlignment: cc.TEXT_ALIGNMENT_CENTER,
- _vAlignment: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
- _fontName: null,
- _fontSize: 0.0,
- _string: "",
- _originalText: null,
- _onCacheCanvasMode: true,
- _shadowEnabled: false,
- _shadowOffset: null,
- _shadowOpacity: 0,
- _shadowBlur: 0,
- _shadowColor: null,
- _strokeEnabled: false,
- _strokeColor: null,
- _strokeSize: 0,
- _textFillColor: null,
- _strokeShadowOffsetX: 0,
- _strokeShadowOffsetY: 0,
- _needUpdateTexture: false,
- _lineWidths: null,
- _className: "LabelTTF",
- _fontStyle: "normal",
- _fontWeight: "normal",
- _lineHeight: "normal",
- initWithString: function (label, fontName, fontSize, dimensions, hAlignment, vAlignment) {
- var strInfo;
- if (label)
- strInfo = label + "";
- else
- strInfo = "";
- fontSize = fontSize || 16;
- dimensions = dimensions || cc.size(0, 0);
- hAlignment = hAlignment || cc.TEXT_ALIGNMENT_LEFT;
- vAlignment = vAlignment || cc.VERTICAL_TEXT_ALIGNMENT_TOP;
- this._opacityModifyRGB = false;
- this._dimensions = cc.size(dimensions.width, dimensions.height);
- this._fontName = fontName || "Arial";
- this._hAlignment = hAlignment;
- this._vAlignment = vAlignment;
- this._fontSize = fontSize;
- this._renderCmd._setFontStyle(this._fontName, fontSize, this._fontStyle, this._fontWeight);
- this.string = strInfo;
- this._renderCmd._setColorsString();
- this._renderCmd._updateTexture();
- this._setUpdateTextureDirty();
- this._scaleX = this._scaleY = 1 / cc.view.getDevicePixelRatio();
- return true;
- },
- _setUpdateTextureDirty: function () {
- this._needUpdateTexture = true;
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.textDirty);
- },
- ctor: function (text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
- cc.Sprite.prototype.ctor.call(this);
- this._dimensions = cc.size(0, 0);
- this._hAlignment = cc.TEXT_ALIGNMENT_LEFT;
- this._vAlignment = cc.VERTICAL_TEXT_ALIGNMENT_TOP;
- this._opacityModifyRGB = false;
- this._fontName = "Arial";
- this._shadowEnabled = false;
- this._shadowOffset = cc.p(0, 0);
- this._shadowOpacity = 0;
- this._shadowBlur = 0;
- this._strokeEnabled = false;
- this._strokeColor = cc.color(255, 255, 255, 255);
- this._strokeSize = 0;
- this._textFillColor = cc.color(255, 255, 255, 255);
- this._strokeShadowOffsetX = 0;
- this._strokeShadowOffsetY = 0;
- this._needUpdateTexture = false;
- this._lineWidths = [];
- this._renderCmd._setColorsString();
- this._textureLoaded = true;
- if (fontName && fontName instanceof cc.FontDefinition) {
- this.initWithStringAndTextDefinition(text, fontName);
- } else {
- cc.LabelTTF.prototype.initWithString.call(this, text, fontName, fontSize, dimensions, hAlignment, vAlignment);
- }
- },
- init: function () {
- return this.initWithString(" ", this._fontName, this._fontSize);
- },
- description: function () {
- return "<cc.LabelTTF | FontName =" + this._fontName + " FontSize = " + this._fontSize.toFixed(1) + ">";
- },
- getLineHeight: function () {
- return !this._lineHeight || this._lineHeight.charAt ?
- this._renderCmd._getFontClientHeight() :
- this._lineHeight || this._renderCmd._getFontClientHeight();
- },
- setLineHeight: function (lineHeight) {
- this._lineHeight = lineHeight;
- },
- getString: function () {
- return this._string;
- },
- getHorizontalAlignment: function () {
- return this._hAlignment;
- },
- getVerticalAlignment: function () {
- return this._vAlignment;
- },
- getDimensions: function () {
- return cc.size(this._dimensions);
- },
- getFontSize: function () {
- return this._fontSize;
- },
- getFontName: function () {
- return this._fontName;
- },
- initWithStringAndTextDefinition: function (text, textDefinition) {
- this._updateWithTextDefinition(textDefinition, false);
- this.string = text;
- return true;
- },
- setTextDefinition: function (theDefinition) {
- if (theDefinition)
- this._updateWithTextDefinition(theDefinition, true);
- },
- getTextDefinition: function () {
- return this._prepareTextDefinition(false);
- },
- enableShadow: function (a, b, c, d) {
- if (a.r != null && a.g != null && a.b != null && a.a != null) {
- this._enableShadow(a, b, c);
- } else {
- this._enableShadowNoneColor(a, b, c, d);
- }
- },
- _enableShadowNoneColor: function (shadowOffsetX, shadowOffsetY, shadowOpacity, shadowBlur) {
- shadowOpacity = shadowOpacity || 0.5;
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- var locShadowOffset = this._shadowOffset;
- if (locShadowOffset && (locShadowOffset.x !== shadowOffsetX) || (locShadowOffset._y !== shadowOffsetY)) {
- locShadowOffset.x = shadowOffsetX;
- locShadowOffset.y = shadowOffsetY;
- }
- if (this._shadowOpacity !== shadowOpacity) {
- this._shadowOpacity = shadowOpacity;
- }
- this._renderCmd._setColorsString();
- if (this._shadowBlur !== shadowBlur)
- this._shadowBlur = shadowBlur;
- this._setUpdateTextureDirty();
- },
- _enableShadow: function (shadowColor, offset, blurRadius) {
- if (!this._shadowColor) {
- this._shadowColor = cc.color(255, 255, 255, 128);
- }
- this._shadowColor.r = shadowColor.r;
- this._shadowColor.g = shadowColor.g;
- this._shadowColor.b = shadowColor.b;
- var x, y, a, b;
- x = offset.width || offset.x || 0;
- y = offset.height || offset.y || 0;
- a = (shadowColor.a != null) ? (shadowColor.a / 255) : 0.5;
- b = blurRadius;
- this._enableShadowNoneColor(x, y, a, b);
- },
- _getShadowOffsetX: function () {
- return this._shadowOffset.x;
- },
- _setShadowOffsetX: function (x) {
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- if (this._shadowOffset.x !== x) {
- this._shadowOffset.x = x;
- this._setUpdateTextureDirty();
- }
- },
- _getShadowOffsetY: function () {
- return this._shadowOffset._y;
- },
- _setShadowOffsetY: function (y) {
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- if (this._shadowOffset._y !== y) {
- this._shadowOffset._y = y;
- this._setUpdateTextureDirty();
- }
- },
- _getShadowOffset: function () {
- return cc.p(this._shadowOffset.x, this._shadowOffset.y);
- },
- _setShadowOffset: function (offset) {
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- if (this._shadowOffset.x !== offset.x || this._shadowOffset.y !== offset.y) {
- this._shadowOffset.x = offset.x;
- this._shadowOffset.y = offset.y;
- this._setUpdateTextureDirty();
- }
- },
- _getShadowOpacity: function () {
- return this._shadowOpacity;
- },
- _setShadowOpacity: function (shadowOpacity) {
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- if (this._shadowOpacity !== shadowOpacity) {
- this._shadowOpacity = shadowOpacity;
- this._renderCmd._setColorsString();
- this._setUpdateTextureDirty();
- }
- },
- _getShadowBlur: function () {
- return this._shadowBlur;
- },
- _setShadowBlur: function (shadowBlur) {
- if (false === this._shadowEnabled)
- this._shadowEnabled = true;
- if (this._shadowBlur !== shadowBlur) {
- this._shadowBlur = shadowBlur;
- this._setUpdateTextureDirty();
- }
- },
- disableShadow: function () {
- if (this._shadowEnabled) {
- this._shadowEnabled = false;
- this._setUpdateTextureDirty();
- }
- },
- enableStroke: function (strokeColor, strokeSize) {
- if (this._strokeEnabled === false)
- this._strokeEnabled = true;
- var locStrokeColor = this._strokeColor;
- if ((locStrokeColor.r !== strokeColor.r) || (locStrokeColor.g !== strokeColor.g) || (locStrokeColor.b !== strokeColor.b)) {
- locStrokeColor.r = strokeColor.r;
- locStrokeColor.g = strokeColor.g;
- locStrokeColor.b = strokeColor.b;
- this._renderCmd._setColorsString();
- }
- if (this._strokeSize !== strokeSize)
- this._strokeSize = strokeSize || 0;
- this._setUpdateTextureDirty();
- },
- _getStrokeStyle: function () {
- return this._strokeColor;
- },
- _setStrokeStyle: function (strokeStyle) {
- if (this._strokeEnabled === false)
- this._strokeEnabled = true;
- var locStrokeColor = this._strokeColor;
- if ((locStrokeColor.r !== strokeStyle.r) || (locStrokeColor.g !== strokeStyle.g) || (locStrokeColor.b !== strokeStyle.b)) {
- locStrokeColor.r = strokeStyle.r;
- locStrokeColor.g = strokeStyle.g;
- locStrokeColor.b = strokeStyle.b;
- this._renderCmd._setColorsString();
- this._setUpdateTextureDirty();
- }
- },
- _getLineWidth: function () {
- return this._strokeSize;
- },
- _setLineWidth: function (lineWidth) {
- if (this._strokeEnabled === false)
- this._strokeEnabled = true;
- if (this._strokeSize !== lineWidth) {
- this._strokeSize = lineWidth || 0;
- this._setUpdateTextureDirty();
- }
- },
- disableStroke: function () {
- if (this._strokeEnabled) {
- this._strokeEnabled = false;
- this._setUpdateTextureDirty();
- }
- },
- setFontFillColor: function (fillColor) {
- var locTextFillColor = this._textFillColor;
- if (locTextFillColor.r !== fillColor.r || locTextFillColor.g !== fillColor.g || locTextFillColor.b !== fillColor.b) {
- locTextFillColor.r = fillColor.r;
- locTextFillColor.g = fillColor.g;
- locTextFillColor.b = fillColor.b;
- this._renderCmd._setColorsString();
- this._needUpdateTexture = true;
- }
- },
- _getFillStyle: function () {
- return this._textFillColor;
- },
- _updateWithTextDefinition: function (textDefinition, mustUpdateTexture) {
- if (textDefinition.fontDimensions) {
- this._dimensions.width = textDefinition.boundingWidth;
- this._dimensions.height = textDefinition.boundingHeight;
- } else {
- this._dimensions.width = 0;
- this._dimensions.height = 0;
- }
- this._hAlignment = textDefinition.textAlign;
- this._vAlignment = textDefinition.verticalAlign;
- this._fontName = textDefinition.fontName;
- this._fontSize = textDefinition.fontSize || 12;
- if(textDefinition.lineHeight)
- this._lineHeight = textDefinition.lineHeight
- else
- this._lineHeight = this._fontSize;
- this._renderCmd._setFontStyle(textDefinition);
- if (textDefinition.shadowEnabled)
- this.enableShadow(textDefinition.shadowOffsetX,
- textDefinition.shadowOffsetY,
- textDefinition.shadowOpacity,
- textDefinition.shadowBlur);
- if (textDefinition.strokeEnabled)
- this.enableStroke(textDefinition.strokeStyle, textDefinition.lineWidth);
- this.setFontFillColor(textDefinition.fillStyle);
- if (mustUpdateTexture)
- this._renderCmd._updateTexture();
- var flags = cc.Node._dirtyFlags;
- this._renderCmd.setDirtyFlag(flags.colorDirty|flags.opacityDirty|flags.textDirty);
- },
- _prepareTextDefinition: function (adjustForResolution) {
- var texDef = new cc.FontDefinition();
- if (adjustForResolution) {
- texDef.fontSize = this._fontSize;
- texDef.boundingWidth = cc.contentScaleFactor() * this._dimensions.width;
- texDef.boundingHeight = cc.contentScaleFactor() * this._dimensions.height;
- } else {
- texDef.fontSize = this._fontSize;
- texDef.boundingWidth = this._dimensions.width;
- texDef.boundingHeight = this._dimensions.height;
- }
- texDef.fontName = this._fontName;
- texDef.textAlign = this._hAlignment;
- texDef.verticalAlign = this._vAlignment;
- if (this._strokeEnabled) {
- texDef.strokeEnabled = true;
- var locStrokeColor = this._strokeColor;
- texDef.strokeStyle = cc.color(locStrokeColor.r, locStrokeColor.g, locStrokeColor.b);
- texDef.lineWidth = this._strokeSize;
- } else
- texDef.strokeEnabled = false;
- if (this._shadowEnabled) {
- texDef.shadowEnabled = true;
- texDef.shadowBlur = this._shadowBlur;
- texDef.shadowOpacity = this._shadowOpacity;
- texDef.shadowOffsetX = (adjustForResolution ? cc.contentScaleFactor() : 1) * this._shadowOffset.x;
- texDef.shadowOffsetY = (adjustForResolution ? cc.contentScaleFactor() : 1) * this._shadowOffset.y;
- } else
- texDef._shadowEnabled = false;
- var locTextFillColor = this._textFillColor;
- texDef.fillStyle = cc.color(locTextFillColor.r, locTextFillColor.g, locTextFillColor.b);
- return texDef;
- },
- getScale: function () {
- if (this._scaleX !== this._scaleY)
- cc.log(cc._LogInfos.Node_getScale);
- return this._scaleX * cc.view.getDevicePixelRatio();
- },
- setScale: function (scale, scaleY) {
- this._scaleX = scale / cc.view.getDevicePixelRatio();
- this._scaleY = ((scaleY || scaleY === 0) ? scaleY : scale) /
- cc.view.getDevicePixelRatio();
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getScaleX: function () {
- return this._scaleX * cc.view.getDevicePixelRatio();
- },
- setScaleX: function (newScaleX) {
- this._scaleX = newScaleX / cc.view.getDevicePixelRatio();
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- getScaleY: function () {
- return this._scaleY * cc.view.getDevicePixelRatio();
- },
- setScaleY: function (newScaleY) {
- this._scaleY = newScaleY / cc.view.getDevicePixelRatio();
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- },
- setString: function (text) {
- text = String(text);
- if (this._originalText !== text) {
- this._originalText = text + "";
- this._updateString();
- this._setUpdateTextureDirty();
- this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
- }
- },
- _updateString: function () {
- if ((!this._string || this._string === "") && this._string !== this._originalText)
- cc.renderer.childrenOrderDirty = true;
- this._string = this._originalText;
- },
- setHorizontalAlignment: function (alignment) {
- if (alignment !== this._hAlignment) {
- this._hAlignment = alignment;
- this._setUpdateTextureDirty();
- }
- },
- setVerticalAlignment: function (verticalAlignment) {
- if (verticalAlignment !== this._vAlignment) {
- this._vAlignment = verticalAlignment;
- this._setUpdateTextureDirty();
- }
- },
- setDimensions: function (dim, height) {
- var width;
- if (height === undefined) {
- width = dim.width;
- height = dim.height;
- } else
- width = dim;
- if (width !== this._dimensions.width || height !== this._dimensions.height) {
- this._dimensions.width = width;
- this._dimensions.height = height;
- this._updateString();
- this._setUpdateTextureDirty();
- }
- },
- _getBoundingWidth: function () {
- return this._dimensions.width;
- },
- _setBoundingWidth: function (width) {
- if (width !== this._dimensions.width) {
- this._dimensions.width = width;
- this._updateString();
- this._setUpdateTextureDirty();
- }
- },
- _getBoundingHeight: function () {
- return this._dimensions.height;
- },
- _setBoundingHeight: function (height) {
- if (height !== this._dimensions.height) {
- this._dimensions.height = height;
- this._updateString();
- this._setUpdateTextureDirty();
- }
- },
- setFontSize: function (fontSize) {
- if (this._fontSize !== fontSize) {
- this._fontSize = fontSize;
- this._renderCmd._setFontStyle(this._fontName, this._fontSize, this._fontStyle, this._fontWeight);
- this._setUpdateTextureDirty();
- }
- },
- setFontName: function (fontName) {
- if (this._fontName && this._fontName !== fontName) {
- this._fontName = fontName;
- this._renderCmd._setFontStyle(this._fontName, this._fontSize, this._fontStyle, this._fontWeight);
- this._setUpdateTextureDirty();
- }
- },
- _getFont: function () {
- return this._renderCmd._getFontStyle();
- },
- _setFont: function (fontStyle) {
- var res = cc.LabelTTF._fontStyleRE.exec(fontStyle);
- if (res) {
- this._fontSize = parseInt(res[1]);
- this._fontName = res[2];
- this._renderCmd._setFontStyle(this._fontName, this._fontSize, this._fontStyle, this._fontWeight);
- this._setUpdateTextureDirty();
- }
- },
- getContentSize: function () {
- if (this._needUpdateTexture)
- this._renderCmd._updateTTF();
- return cc.size(this._contentSize);
- },
- _getWidth: function () {
- if (this._needUpdateTexture)
- this._renderCmd._updateTTF();
- return this._contentSize.width;
- },
- _getHeight: function () {
- if (this._needUpdateTexture)
- this._renderCmd._updateTTF();
- return this._contentSize.height;
- },
- setTextureRect: function (rect, rotated, untrimmedSize) {
- cc.Sprite.prototype.setTextureRect.call(this, rect, rotated, untrimmedSize, false);
- },
- setDrawMode: function (onCacheMode) {
- this._onCacheCanvasMode = onCacheMode;
- },
- _createRenderCmd: function () {
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL)
- return new cc.LabelTTF.WebGLRenderCmd(this);
- else if (this._onCacheCanvasMode)
- return new cc.LabelTTF.CacheCanvasRenderCmd(this);
- else
- return new cc.LabelTTF.CanvasRenderCmd(this);
- },
- _setFontStyle: function(fontStyle){
- if (this._fontStyle !== fontStyle) {
- this._fontStyle = fontStyle;
- this._renderCmd._setFontStyle(this._fontName, this._fontSize, this._fontStyle, this._fontWeight);
- this._setUpdateTextureDirty();
- }
- },
- _getFontStyle: function(){
- return this._fontStyle;
- },
- _setFontWeight: function(fontWeight){
- if (this._fontWeight !== fontWeight) {
- this._fontWeight = fontWeight;
- this._renderCmd._setFontStyle(this._fontName, this._fontSize, this._fontStyle, this._fontWeight);
- this._setUpdateTextureDirty();
- }
- },
- _getFontWeight: function(){
- return this._fontWeight;
- }
- });
- cc.assert(cc.isFunction(cc._tmp.PrototypeLabelTTF), cc._LogInfos.MissingFile, "LabelTTFPropertyDefine.js");
- cc._tmp.PrototypeLabelTTF();
- delete cc._tmp.PrototypeLabelTTF;
- cc.LabelTTF._fontStyleRE = /^(\d+)px\s+['"]?([\w\s\d]+)['"]?$/;
- cc.LabelTTF.create = function (text, fontName, fontSize, dimensions, hAlignment, vAlignment) {
- return new cc.LabelTTF(text, fontName, fontSize, dimensions, hAlignment, vAlignment);
- };
- cc.LabelTTF.createWithFontDefinition = cc.LabelTTF.create;
- cc.LabelTTF.__labelHeightDiv = document.createElement("div");
- cc.LabelTTF.__labelHeightDiv.style.fontFamily = "Arial";
- cc.LabelTTF.__labelHeightDiv.style.position = "absolute";
- cc.LabelTTF.__labelHeightDiv.style.left = "-100px";
- cc.LabelTTF.__labelHeightDiv.style.top = "-100px";
- cc.LabelTTF.__labelHeightDiv.style.lineHeight = "normal";
- document.body ?
- document.body.appendChild(cc.LabelTTF.__labelHeightDiv) :
- window.addEventListener('load', function () {
- this.removeEventListener('load', arguments.callee, false);
- document.body.appendChild(cc.LabelTTF.__labelHeightDiv);
- }, false);
- cc.LabelTTF.__getFontHeightByDiv = function (fontName, fontSize) {
- var clientHeight, labelDiv = cc.LabelTTF.__labelHeightDiv;
- if(fontName instanceof cc.FontDefinition){
- var fontDef = fontName;
- clientHeight = cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()];
- if (clientHeight > 0) return clientHeight;
- labelDiv.innerHTML = "ajghl~!";
- labelDiv.style.fontFamily = fontDef.fontName;
- labelDiv.style.fontSize = fontDef.fontSize + "px";
- labelDiv.style.fontStyle = fontDef.fontStyle;
- labelDiv.style.fontWeight = fontDef.fontWeight;
- clientHeight = labelDiv.clientHeight;
- cc.LabelTTF.__fontHeightCache[fontDef._getCanvasFontStr()] = clientHeight;
- labelDiv.innerHTML = "";
- }
- else {
- clientHeight = cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize];
- if (clientHeight > 0) return clientHeight;
- labelDiv.innerHTML = "ajghl~!";
- labelDiv.style.fontFamily = fontName;
- labelDiv.style.fontSize = fontSize + "px";
- clientHeight = labelDiv.clientHeight;
- cc.LabelTTF.__fontHeightCache[fontName + "." + fontSize] = clientHeight;
- labelDiv.innerHTML = "";
- }
- return clientHeight;
- };
- cc.LabelTTF.__fontHeightCache = {};
- cc.LabelTTF._textAlign = ["left", "center", "right"];
- cc.LabelTTF._textBaseline = ["top", "middle", "bottom"];
- cc.LabelTTF.wrapInspection = true;
- cc.LabelTTF._wordRex = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]+|\S)/;
- cc.LabelTTF._symbolRex = /^[!,.:;}\]%\?>、‘“》?。,!]/;
- cc.LabelTTF._lastWordRex = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]+|\S)$/;
- cc.LabelTTF._lastEnglish = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]+$/;
- cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
- (function() {
- cc.LabelTTF.RenderCmd = function () {
- this._fontClientHeight = 18;
- this._fontStyleStr = "";
- this._shadowColorStr = "rgba(128, 128, 128, 0.5)";
- this._strokeColorStr = "";
- this._fillColorStr = "rgba(255,255,255,1)";
- this._labelCanvas = null;
- this._labelContext = null;
- this._lineWidths = [];
- this._strings = [];
- this._isMultiLine = false;
- this._status = [];
- this._renderingIndex = 0;
- this._texRect = cc.rect();
- this._canUseDirtyRegion = true;
- };
- var proto = cc.LabelTTF.RenderCmd.prototype;
- proto.constructor = cc.LabelTTF.RenderCmd;
- proto._setFontStyle = function (fontNameOrFontDef, fontSize, fontStyle, fontWeight) {
- if(fontNameOrFontDef instanceof cc.FontDefinition){
- this._fontStyleStr = fontNameOrFontDef._getCanvasFontStr();
- this._fontClientHeight = cc.LabelTTF.__getFontHeightByDiv(fontNameOrFontDef);
- }else {
- var deviceFontSize = fontSize * cc.view.getDevicePixelRatio();
- this._fontStyleStr = fontStyle + " " + fontWeight + " " + deviceFontSize + "px '" + fontNameOrFontDef + "'";
- this._fontClientHeight = cc.LabelTTF.__getFontHeightByDiv(fontNameOrFontDef, fontSize);
- }
- };
- proto._getFontStyle = function () {
- return this._fontStyleStr;
- };
- proto._getFontClientHeight = function () {
- return this._fontClientHeight;
- };
- proto._updateColor = function(){
- this._setColorsString();
- this._updateTexture();
- };
- proto._setColorsString = function () {
- var locDisplayColor = this._displayedColor, node = this._node,
- locShadowColor = node._shadowColor || this._displayedColor;
- var locStrokeColor = node._strokeColor, locFontFillColor = node._textFillColor;
- var dr = locDisplayColor.r / 255, dg = locDisplayColor.g / 255, db = locDisplayColor.b / 255;
- this._shadowColorStr = "rgba(" + (0 | (dr * locShadowColor.r)) + "," + (0 | ( dg * locShadowColor.g)) + ","
- + (0 | (db * locShadowColor.b)) + "," + node._shadowOpacity + ")";
- this._fillColorStr = "rgba(" + (0 | (dr * locFontFillColor.r)) + "," + (0 | (dg * locFontFillColor.g)) + ","
- + (0 | (db * locFontFillColor.b)) + ", 1)";
- this._strokeColorStr = "rgba(" + (0 | (dr * locStrokeColor.r)) + "," + (0 | (dg * locStrokeColor.g)) + ","
- + (0 | (db * locStrokeColor.b)) + ", 1)";
- };
- var localBB = new cc.Rect();
- proto.getLocalBB = function () {
- var node = this._node;
- localBB.x = localBB.y = 0;
- var pixelRatio = cc.view.getDevicePixelRatio();
- localBB.width = node._getWidth() * pixelRatio;
- localBB.height = node._getHeight() * pixelRatio;
- return localBB;
- };
- proto._updateTTF = function () {
- var node = this._node;
- var pixelRatio = cc.view.getDevicePixelRatio();
- var locDimensionsWidth = node._dimensions.width * pixelRatio, i, strLength;
- var locLineWidth = this._lineWidths;
- locLineWidth.length = 0;
- this._isMultiLine = false;
- this._measureConfig();
- if (locDimensionsWidth !== 0) {
- this._strings = node._string.split('\n');
- for (i = 0; i < this._strings.length; i++) {
- this._checkWarp(this._strings, i, locDimensionsWidth);
- }
- } else {
- this._strings = node._string.split('\n');
- for (i = 0, strLength = this._strings.length; i < strLength; i++) {
- locLineWidth.push(this._measure(this._strings[i]));
- }
- }
- if (this._strings.length > 1)
- this._isMultiLine = true;
- var locSize, locStrokeShadowOffsetX = 0, locStrokeShadowOffsetY = 0;
- if (node._strokeEnabled)
- locStrokeShadowOffsetX = locStrokeShadowOffsetY = node._strokeSize * 2;
- if (node._shadowEnabled) {
- var locOffsetSize = node._shadowOffset;
- locStrokeShadowOffsetX += Math.abs(locOffsetSize.x) * 2;
- locStrokeShadowOffsetY += Math.abs(locOffsetSize.y) * 2;
- }
- if (locDimensionsWidth === 0) {
- if (this._isMultiLine)
- locSize = cc.size(
- Math.ceil(Math.max.apply(Math, locLineWidth) + locStrokeShadowOffsetX),
- Math.ceil((this._fontClientHeight * pixelRatio * this._strings.length) + locStrokeShadowOffsetY));
- else
- locSize = cc.size(
- Math.ceil(this._measure(node._string) + locStrokeShadowOffsetX),
- Math.ceil(this._fontClientHeight * pixelRatio + locStrokeShadowOffsetY));
- } else {
- if (node._dimensions.height === 0) {
- if (this._isMultiLine)
- locSize = cc.size(
- Math.ceil(locDimensionsWidth + locStrokeShadowOffsetX),
- Math.ceil((node.getLineHeight() * pixelRatio * this._strings.length) + locStrokeShadowOffsetY));
- else
- locSize = cc.size(
- Math.ceil(locDimensionsWidth + locStrokeShadowOffsetX),
- Math.ceil(node.getLineHeight() * pixelRatio + locStrokeShadowOffsetY));
- } else {
- locSize = cc.size(
- Math.ceil(locDimensionsWidth + locStrokeShadowOffsetX),
- Math.ceil(node._dimensions.height * pixelRatio + locStrokeShadowOffsetY));
- }
- }
- if (node._getFontStyle() !== "normal") {
- locSize.width = Math.ceil(locSize.width + node._fontSize * 0.3);
- }
- if (this._strings.length === 0) {
- this._texRect.width = 1;
- this._texRect.height = locSize.height || 1;
- }
- else {
- this._texRect.width = locSize.width;
- this._texRect.height = locSize.height;
- }
- var nodeW = locSize.width / pixelRatio, nodeH = locSize.height / pixelRatio;
- node.setContentSize(nodeW, nodeH);
- node._strokeShadowOffsetX = locStrokeShadowOffsetX;
- node._strokeShadowOffsetY = locStrokeShadowOffsetY;
- var locAP = node._anchorPoint;
- this._anchorPointInPoints.x = (locStrokeShadowOffsetX * 0.5) + ((locSize.width - locStrokeShadowOffsetX) * locAP.x);
- this._anchorPointInPoints.y = (locStrokeShadowOffsetY * 0.5) + ((locSize.height - locStrokeShadowOffsetY) * locAP.y);
- };
- proto._saveStatus = function () {
- var node = this._node;
- var scale = cc.view.getDevicePixelRatio();
- var locStrokeShadowOffsetX = node._strokeShadowOffsetX, locStrokeShadowOffsetY = node._strokeShadowOffsetY;
- var locContentSizeHeight = node._contentSize.height * scale - locStrokeShadowOffsetY, locVAlignment = node._vAlignment,
- locHAlignment = node._hAlignment;
- var dx = locStrokeShadowOffsetX * 0.5,
- dy = locContentSizeHeight + locStrokeShadowOffsetY * 0.5;
- var xOffset = 0, yOffset = 0, OffsetYArray = [];
- var locContentWidth = node._contentSize.width * scale - locStrokeShadowOffsetX;
- var lineHeight = node.getLineHeight() * scale;
- var transformTop = (lineHeight - this._fontClientHeight * scale) / 2;
- if (locHAlignment === cc.TEXT_ALIGNMENT_RIGHT)
- xOffset += locContentWidth;
- else if (locHAlignment === cc.TEXT_ALIGNMENT_CENTER)
- xOffset += locContentWidth / 2;
- else
- xOffset += 0;
- if (this._isMultiLine) {
- var locStrLen = this._strings.length;
- if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM)
- yOffset = lineHeight - transformTop * 2 + locContentSizeHeight - lineHeight * locStrLen;
- else if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_CENTER)
- yOffset = (lineHeight - transformTop * 2) / 2 + (locContentSizeHeight - lineHeight * locStrLen) / 2;
- for (var i = 0; i < locStrLen; i++) {
- var tmpOffsetY = -locContentSizeHeight + (lineHeight * i + transformTop) + yOffset;
- OffsetYArray.push(tmpOffsetY);
- }
- } else {
- if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM) {
- } else if (locVAlignment === cc.VERTICAL_TEXT_ALIGNMENT_TOP) {
- yOffset -= locContentSizeHeight;
- } else {
- yOffset -= locContentSizeHeight * 0.5;
- }
- OffsetYArray.push(yOffset);
- }
- var tmpStatus = {
- contextTransform:cc.p(dx,dy),
- xOffset:xOffset,
- OffsetYArray:OffsetYArray
- };
- this._status.push(tmpStatus);
- };
- proto._drawTTFInCanvas = function (context) {
- if (!context)
- return;
- var locStatus = this._status.pop();
- context.setTransform(1, 0, 0, 1, locStatus.contextTransform.x, locStatus.contextTransform.y);
- var xOffset = locStatus.xOffset;
- var yOffsetArray = locStatus.OffsetYArray;
- this.drawLabels(context, xOffset, yOffsetArray);
- };
- proto._checkWarp = function (strArr, i, maxWidth) {
- var text = strArr[i];
- var allWidth = this._measure(text);
- if (allWidth > maxWidth && text.length > 1) {
- var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0;
- var tmpText = text.substr(fuzzyLen);
- var width = allWidth - this._measure(tmpText);
- var sLine;
- var pushNum = 0;
- var checkWhile = 0;
- while (width > maxWidth && checkWhile++ < 100) {
- fuzzyLen *= maxWidth / width;
- fuzzyLen = fuzzyLen | 0;
- tmpText = text.substr(fuzzyLen);
- width = allWidth - this._measure(tmpText);
- }
- checkWhile = 0;
- while (width < maxWidth && checkWhile++ < 100) {
- if (tmpText) {
- var exec = cc.LabelTTF._wordRex.exec(tmpText);
- pushNum = exec ? exec[0].length : 1;
- sLine = tmpText;
- }
- fuzzyLen = fuzzyLen + pushNum;
- tmpText = text.substr(fuzzyLen);
- width = allWidth - this._measure(tmpText);
- }
- fuzzyLen -= pushNum;
- if (fuzzyLen === 0) {
- fuzzyLen = 1;
- sLine = sLine.substr(1);
- }
- var sText = text.substr(0, fuzzyLen), result;
- if (cc.LabelTTF.wrapInspection) {
- if (cc.LabelTTF._symbolRex.test(sLine || tmpText)) {
- result = cc.LabelTTF._lastWordRex.exec(sText);
- fuzzyLen -= result ? result[0].length : 0;
- if (fuzzyLen === 0) fuzzyLen = 1;
- sLine = text.substr(fuzzyLen);
- sText = text.substr(0, fuzzyLen);
- }
- }
- if (cc.LabelTTF._firsrEnglish.test(sLine)) {
- result = cc.LabelTTF._lastEnglish.exec(sText);
- if (result && sText !== result[0]) {
- fuzzyLen -= result[0].length;
- sLine = text.substr(fuzzyLen);
- sText = text.substr(0, fuzzyLen);
- }
- }
- strArr[i] = sLine || tmpText;
- strArr.splice(i, 0, sText);
- }
- };
- proto.updateStatus = function () {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.textDirty)
- this._updateTexture();
- cc.Node.RenderCmd.prototype.updateStatus.call(this);
- if (this._dirtyFlag & flags.transformDirty){
- this.transform(this.getParentRenderCmd(), true);
- this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.transformDirty ^ this._dirtyFlag;
- }
- };
- proto._syncStatus = function (parentCmd) {
- var flags = cc.Node._dirtyFlags, locFlag = this._dirtyFlag;
- if (locFlag & flags.textDirty)
- this._updateTexture();
- cc.Node.RenderCmd.prototype._syncStatus.call(this, parentCmd);
- if (cc._renderType === cc.game.RENDER_TYPE_WEBGL || locFlag & flags.transformDirty)
- this.transform(parentCmd);
- };
- proto.drawLabels = function (context, xOffset, yOffsetArray) {
- var node = this._node;
- if (node._shadowEnabled) {
- var locShadowOffset = node._shadowOffset;
- context.shadowColor = this._shadowColorStr;
- context.shadowOffsetX = locShadowOffset.x;
- context.shadowOffsetY = -locShadowOffset.y;
- context.shadowBlur = node._shadowBlur;
- }
- var locHAlignment = node._hAlignment,
- locVAlignment = node._vAlignment,
- locStrokeSize = node._strokeSize;
- if (context.font !== this._fontStyleStr)
- context.font = this._fontStyleStr;
- context.fillStyle = this._fillColorStr;
- var locStrokeEnabled = node._strokeEnabled;
- if (locStrokeEnabled) {
- context.lineWidth = locStrokeSize * 2;
- context.strokeStyle = this._strokeColorStr;
- }
- context.textBaseline = cc.LabelTTF._textBaseline[locVAlignment];
- context.textAlign = cc.LabelTTF._textAlign[locHAlignment];
- var locStrLen = this._strings.length;
- for (var i = 0; i < locStrLen; i++) {
- var line = this._strings[i];
- if (locStrokeEnabled)
- context.strokeText(line, xOffset, yOffsetArray[i]);
- context.fillText(line, xOffset, yOffsetArray[i]);
- }
- cc.g_NumberOfDraws++;
- };
- })();
- (function(){
- cc.LabelTTF.CacheRenderCmd = function (renderable) {
- cc.LabelTTF.RenderCmd.call(this,renderable);
- var locCanvas = this._labelCanvas = document.createElement("canvas");
- locCanvas.width = 1;
- locCanvas.height = 1;
- this._labelContext = locCanvas.getContext("2d");
- this._texRect = cc.rect();
- };
- cc.LabelTTF.CacheRenderCmd.prototype = Object.create( cc.LabelTTF.RenderCmd.prototype);
- cc.inject(cc.LabelTTF.RenderCmd.prototype, cc.LabelTTF.CacheRenderCmd.prototype);
- var proto = cc.LabelTTF.CacheRenderCmd.prototype;
- proto.constructor = cc.LabelTTF.CacheRenderCmd;
- proto._updateTexture = function () {
- this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
- var node = this._node;
- this._updateTTF();
- var width = this._texRect.width, height = this._texRect.height;
- var locContext = this._labelContext, locLabelCanvas = this._labelCanvas;
- if(!node._texture){
- var labelTexture = new cc.Texture2D();
- labelTexture.initWithElement(this._labelCanvas);
- node.setTexture(labelTexture);
- }
- if (node._string.length === 0) {
- locLabelCanvas.width = width;
- locLabelCanvas.height = height;
- node._texture && node._texture.handleLoadedTexture();
- node.setTextureRect(this._texRect);
- return true;
- }
- locContext.font = this._fontStyleStr;
- var flag = locLabelCanvas.width === width && locLabelCanvas.height === height;
- locLabelCanvas.width = this._texRect.width;
- locLabelCanvas.height = this._texRect.height;
- if (flag) locContext.clearRect(0, 0, width, height);
- this._saveStatus();
- this._drawTTFInCanvas(locContext);
- node._texture && node._texture.handleLoadedTexture();
- node.setTextureRect(this._texRect);
- return true;
- };
- proto._measureConfig = function () {
- this._labelContext.font = this._fontStyleStr;
- };
- proto._measure = function (text) {
- return this._labelContext.measureText(text).width;
- };
- })();
- (function(){
- cc.LabelTTF.CacheCanvasRenderCmd = function (renderable) {
- cc.Sprite.CanvasRenderCmd.call(this, renderable);
- cc.LabelTTF.CacheRenderCmd.call(this);
- };
- var proto = cc.LabelTTF.CacheCanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);
- cc.inject(cc.LabelTTF.CacheRenderCmd.prototype, proto);
- proto.constructor = cc.LabelTTF.CacheCanvasRenderCmd;
- })();
- (function(){
- cc.LabelTTF.CanvasRenderCmd = function (renderable) {
- cc.Sprite.CanvasRenderCmd.call(this, renderable);
- cc.LabelTTF.RenderCmd.call(this);
- };
- cc.LabelTTF.CanvasRenderCmd.prototype = Object.create(cc.Sprite.CanvasRenderCmd.prototype);
- cc.inject(cc.LabelTTF.RenderCmd.prototype, cc.LabelTTF.CanvasRenderCmd.prototype);
- var proto = cc.LabelTTF.CanvasRenderCmd.prototype;
- proto.constructor = cc.LabelTTF.CanvasRenderCmd;
- proto._measureConfig = function () {};
- proto._measure = function (text) {
- var context = cc._renderContext.getContext();
- context.font = this._fontStyleStr;
- return context.measureText(text).width;
- };
- proto._updateTexture = function () {
- this._dirtyFlag = this._dirtyFlag & cc.Node._dirtyFlags.textDirty ^ this._dirtyFlag;
- var node = this._node;
- var scale = cc.view.getDevicePixelRatio();
- this._updateTTF();
- if (node._string.length === 0) {
- node.setTextureRect(this._texRect);
- return true;
- }
- this._saveStatus();
- node.setTextureRect(this._texRect);
- return true;
- };
- proto.rendering = function(ctx) {
- var scaleX = cc.view.getScaleX(),
- scaleY = cc.view.getScaleY();
- var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
- if (!context)
- return;
- var node = this._node;
- wrapper.computeRealOffsetY();
- if(this._status.length <= 0)
- return;
- var locIndex = (this._renderingIndex >= this._status.length)? this._renderingIndex-this._status.length:this._renderingIndex;
- var status = this._status[locIndex];
- this._renderingIndex = locIndex+1;
- var locHeight = node._rect.height,
- locX = node._offsetPosition.x,
- locY = -node._offsetPosition.y - locHeight;
- var alpha = (this._displayedOpacity / 255);
- wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- wrapper.setCompositeOperation(this._blendFuncStr);
- wrapper.setGlobalAlpha(alpha);
- wrapper.save();
- if (node._flippedX) {
- locX = -locX - node._rect.width;
- context.scale(-1, 1);
- }
- if (node._flippedY) {
- locY = node._offsetPosition.y;
- context.scale(1, -1);
- }
- var xOffset = status.xOffset + status.contextTransform.x + locX * scaleX;
- var yOffsetArray = [];
- var locStrLen = this._strings.length;
- for (var i = 0; i < locStrLen; i++)
- yOffsetArray.push(status.OffsetYArray[i] + status.contextTransform.y + locY * scaleY);
- this.drawLabels(context, xOffset, yOffsetArray);
- wrapper.restore();
- };
- })();
- var cc = cc || {};
- cc._tmp = cc._tmp || {};
- cc.associateWithNative = function (jsObj, superclass) {
- };
- cc.KEY = {
- none:0,
- back:6,
- menu:18,
- backspace:8,
- tab:9,
- enter:13,
- shift:16,
- ctrl:17,
- alt:18,
- pause:19,
- capslock:20,
- escape:27,
- space:32,
- pageup:33,
- pagedown:34,
- end:35,
- home:36,
- left:37,
- up:38,
- right:39,
- down:40,
- select:41,
- insert:45,
- Delete:46,
- 0:48,
- 1:49,
- 2:50,
- 3:51,
- 4:52,
- 5:53,
- 6:54,
- 7:55,
- 8:56,
- 9:57,
- a:65,
- b:66,
- c:67,
- d:68,
- e:69,
- f:70,
- g:71,
- h:72,
- i:73,
- j:74,
- k:75,
- l:76,
- m:77,
- n:78,
- o:79,
- p:80,
- q:81,
- r:82,
- s:83,
- t:84,
- u:85,
- v:86,
- w:87,
- x:88,
- y:89,
- z:90,
- num0:96,
- num1:97,
- num2:98,
- num3:99,
- num4:100,
- num5:101,
- num6:102,
- num7:103,
- num8:104,
- num9:105,
- '*':106,
- '+':107,
- '-':109,
- 'numdel':110,
- '/':111,
- f1:112,
- f2:113,
- f3:114,
- f4:115,
- f5:116,
- f6:117,
- f7:118,
- f8:119,
- f9:120,
- f10:121,
- f11:122,
- f12:123,
- numlock:144,
- scrolllock:145,
- ';':186,
- semicolon:186,
- equal:187,
- '=':187,
- ',':188,
- comma:188,
- dash:189,
- '.':190,
- period:190,
- forwardslash:191,
- grave:192,
- '[':219,
- openbracket:219,
- backslash:220,
- ']':221,
- closebracket:221,
- quote:222,
- dpadLeft:1000,
- dpadRight:1001,
- dpadUp:1003,
- dpadDown:1004,
- dpadCenter:1005
- };
- cc.FMT_JPG = 0;
- cc.FMT_PNG = 1;
- cc.FMT_TIFF = 2;
- cc.FMT_RAWDATA = 3;
- cc.FMT_WEBP = 4;
- cc.FMT_UNKNOWN = 5;
- cc.getImageFormatByData = function (imgData) {
- if (imgData.length > 8 && imgData[0] === 0x89
- && imgData[1] === 0x50
- && imgData[2] === 0x4E
- && imgData[3] === 0x47
- && imgData[4] === 0x0D
- && imgData[5] === 0x0A
- && imgData[6] === 0x1A
- && imgData[7] === 0x0A) {
- return cc.FMT_PNG;
- }
- if (imgData.length > 2 && ((imgData[0] === 0x49 && imgData[1] === 0x49)
- || (imgData[0] === 0x4d && imgData[1] === 0x4d)
- || (imgData[0] === 0xff && imgData[1] === 0xd8))) {
- return cc.FMT_TIFF;
- }
- return cc.FMT_UNKNOWN;
- };
- cc.inherits = function (childCtor, parentCtor) {
- function tempCtor() {}
- tempCtor.prototype = parentCtor.prototype;
- childCtor.superClass_ = parentCtor.prototype;
- childCtor.prototype = new tempCtor();
- childCtor.prototype.constructor = childCtor;
- };
- cc.base = function(me, opt_methodName, var_args) {
- var caller = arguments.callee.caller;
- if (caller.superClass_) {
- ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1));
- return ret;
- }
- var args = Array.prototype.slice.call(arguments, 2);
- var foundCaller = false;
- for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
- if (ctor.prototype[opt_methodName] === caller) {
- foundCaller = true;
- } else if (foundCaller) {
- return ctor.prototype[opt_methodName].apply(me, args);
- }
- }
- if (me[opt_methodName] === caller) {
- return me.constructor.prototype[opt_methodName].apply(me, args);
- } else {
- throw Error(
- 'cc.base called from a method of one name ' +
- 'to a method of a different name');
- }
- };
- var GlobalVertexBuffer = (function () {
- var VERTICES_SIZE = 888;
- var GlobalVertexBuffer = function (gl) {
- this.gl = gl;
- this.vertexBuffer = gl.createBuffer();
- this.size = VERTICES_SIZE;
- this.byteLength = VERTICES_SIZE * 4 * cc.V3F_C4B_T2F_Quad.BYTES_PER_ELEMENT;
- this.data = new ArrayBuffer(this.byteLength);
- this.dataArray = new Float32Array(this.data);
- gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
- gl.bufferData(gl.ARRAY_BUFFER, this.dataArray, gl.DYNAMIC_DRAW);
- this._dirty = false;
- this._spaces = {
- 0: this.byteLength
- };
- };
- GlobalVertexBuffer.prototype = {
- constructor: GlobalVertexBuffer,
- allocBuffer: function (offset, size) {
- var space = this._spaces[offset];
- if (space && space >= size) {
- delete this._spaces[offset];
- if (space > size) {
- var newOffset = offset + size;
- this._spaces[newOffset] = space - size;
- }
- return true;
- }
- else {
- return false;
- }
- },
- requestBuffer: function (size) {
- var key, offset, available;
- for (key in this._spaces) {
- offset = parseInt(key);
- available = this._spaces[key];
- if (available >= size && this.allocBuffer(offset, size)) {
- return {
- buffer: this,
- offset: offset,
- size: size
- };
- }
- }
- return null;
- },
- freeBuffer: function (offset, size) {
- var spaces = this._spaces;
- var i, key, end;
- for (key in spaces) {
- i = parseInt(key);
- if (i > offset) {
- break;
- }
- if (i + spaces[key] >= offset) {
- size = size + offset - i;
- offset = i;
- break;
- }
- }
- end = offset + size;
- if (this._spaces[end]) {
- size += this._spaces[end];
- delete this._spaces[end];
- }
- this._spaces[offset] = size;
- },
- setDirty: function () {
- this._dirty = true;
- },
- update: function () {
- if (this._dirty) {
- this.gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
- this.gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.dataArray);
- this._dirty = false;
- }
- },
- destroy: function () {
- this.gl.deleteBuffer(this.vertexBuffer);
- this.data = null;
- this.positions = null;
- this.colors = null;
- this.texCoords = null;
- this.vertexBuffer = null;
- }
- };
- return GlobalVertexBuffer;
- })();
- cc.rendererCanvas = {
- childrenOrderDirty: true,
- assignedZ: 0,
- assignedZStep: 1 / 10000,
- _transformNodePool: [],
- _renderCmds: [],
- _isCacheToCanvasOn: false,
- _cacheToCanvasCmds: {},
- _cacheInstanceIds: [],
- _currentID: 0,
- _clearColor: cc.color(),
- _clearFillStyle: "rgb(0, 0, 0)",
- _dirtyRegion: null,
- _allNeedDraw: true,
- _enableDirtyRegion: false,
- _debugDirtyRegion: false,
- _canUseDirtyRegion: false,
- _dirtyRegionCountThreshold: 10,
- getRenderCmd: function (renderableObject) {
- return renderableObject._createRenderCmd();
- },
- enableDirtyRegion: function (enabled) {
- this._enableDirtyRegion = enabled;
- },
- isDirtyRegionEnabled: function () {
- return this._enableDirtyRegion;
- },
- setDirtyRegionCountThreshold: function(threshold) {
- this._dirtyRegionCountThreshold = threshold;
- },
- _collectDirtyRegion: function () {
- var locCmds = this._renderCmds, i, len;
- var dirtyRegion = this._dirtyRegion;
- var dirtryRegionCount = 0;
- var result = true;
- var localStatus = cc.Node.CanvasRenderCmd.RegionStatus;
- for (i = 0, len = locCmds.length; i < len; i++) {
- var cmd = locCmds[i];
- var regionFlag = cmd._regionFlag;
- var oldRegion = cmd._oldRegion;
- var currentRegion = cmd._currentRegion;
- if (regionFlag > localStatus.NotDirty) {
- ++dirtryRegionCount;
- if(dirtryRegionCount > this._dirtyRegionCountThreshold)
- result = false;
- if(result) {
- (!currentRegion.isEmpty()) && dirtyRegion.addRegion(currentRegion);
- if (cmd._regionFlag > localStatus.Dirty) {
- (!oldRegion.isEmpty()) && dirtyRegion.addRegion(oldRegion);
- }
- }
- cmd._regionFlag = localStatus.NotDirty;
- }
- }
- return result;
- },
- _beginDrawDirtyRegion: function (ctxWrapper) {
- var ctx = ctxWrapper.getContext();
- var dirtyList = this._dirtyRegion.getDirtyRegions();
- ctx.save();
- var scaleX = ctxWrapper._scaleX;
- var scaleY = ctxWrapper._scaleY;
- ctxWrapper.setTransform({a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0}, scaleX, scaleY);
- ctx.beginPath();
- for (var index = 0, count = dirtyList.length; index < count; ++index) {
- var region = dirtyList[index];
- ctx.rect(region._minX , -region._maxY , region._width , region._height );
- }
- ctx.clip();
- },
- _endDrawDirtyRegion: function (ctx) {
- ctx.restore();
- },
- _debugDrawDirtyRegion: function (ctxWrapper) {
- if (!this._debugDirtyRegion) return;
- var ctx = ctxWrapper.getContext();
- var dirtyList = this._dirtyRegion.getDirtyRegions();
- var scaleX = ctxWrapper._scaleX;
- var scaleY = ctxWrapper._scaleY;
- ctxWrapper.setTransform({a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0}, scaleX, scaleY);
- ctx.beginPath();
- for (var index = 0, count = dirtyList.length; index < count; ++index) {
- var region = dirtyList[index];
- ctx.rect(region._minX, -region._maxY , region._width , region._height );
- }
- var oldstyle = ctx.fillStyle;
- ctx.fillStyle = 'green';
- ctx.fill();
- ctx.fillStyle = oldstyle;
- },
- rendering: function (ctxWrapper) {
- var dirtyRegion = this._dirtyRegion = this._dirtyRegion || new cc.DirtyRegion();
- var viewport = cc._canvas;
- var wrapper = ctxWrapper || cc._renderContext;
- var ctx = wrapper.getContext();
- var scaleX = cc.view.getScaleX(),
- scaleY = cc.view.getScaleY();
- wrapper.setViewScale(scaleX, scaleY);
- wrapper.computeRealOffsetY();
- var dirtyList = this._dirtyRegion.getDirtyRegions();
- var locCmds = this._renderCmds, i, len;
- var allNeedDraw = this._allNeedDraw || !this._enableDirtyRegion || !this._canUseDirtyRegion;
- var collectResult = true;
- if (!allNeedDraw) {
- collectResult = this._collectDirtyRegion();
- }
- allNeedDraw = allNeedDraw || (!collectResult);
- if(!allNeedDraw) {
- this._beginDrawDirtyRegion(wrapper);
- }
- ctx.setTransform(1, 0, 0, 1, 0, 0);
- ctx.clearRect(0, 0, viewport.width, viewport.height);
- if (this._clearColor.r !== 0 ||
- this._clearColor.g !== 0 ||
- this._clearColor.b !== 0) {
- wrapper.setFillStyle(this._clearFillStyle);
- wrapper.setGlobalAlpha(this._clearColor.a);
- ctx.fillRect(0, 0, viewport.width, viewport.height);
- }
- for (i = 0, len = locCmds.length; i < len; i++) {
- var cmd = locCmds[i];
- var needRendering = false;
- var cmdRegion = cmd._currentRegion;
- if (!cmdRegion || allNeedDraw) {
- needRendering = true;
- } else {
- for (var index = 0, count = dirtyList.length; index < count; ++index) {
- if (dirtyList[index].intersects(cmdRegion)) {
- needRendering = true;
- break;
- }
- }
- }
- if (needRendering) {
- cmd.rendering(wrapper, scaleX, scaleY);
- }
- }
- if (!allNeedDraw) {
- this._debugDrawDirtyRegion(wrapper);
- this._endDrawDirtyRegion(ctx);
- }
- dirtyRegion.clear();
- this._allNeedDraw = false;
- },
- _renderingToCacheCanvas: function (ctx, instanceID, scaleX, scaleY) {
- if (!ctx)
- cc.log("The context of RenderTexture is invalid.");
- scaleX = cc.isUndefined(scaleX) ? 1 : scaleX;
- scaleY = cc.isUndefined(scaleY) ? 1 : scaleY;
- instanceID = instanceID || this._currentID;
- var locCmds = this._cacheToCanvasCmds[instanceID], i, len;
- ctx.computeRealOffsetY();
- for (i = 0, len = locCmds.length; i < len; i++) {
- locCmds[i].rendering(ctx, scaleX, scaleY);
- }
- this._removeCache(instanceID);
- var locIDs = this._cacheInstanceIds;
- if (locIDs.length === 0)
- this._isCacheToCanvasOn = false;
- else
- this._currentID = locIDs[locIDs.length - 1];
- },
- _turnToCacheMode: function (renderTextureID) {
- this._isCacheToCanvasOn = true;
- renderTextureID = renderTextureID || 0;
- this._cacheToCanvasCmds[renderTextureID] = [];
- if (this._cacheInstanceIds.indexOf(renderTextureID) === -1)
- this._cacheInstanceIds.push(renderTextureID);
- this._currentID = renderTextureID;
- },
- _turnToNormalMode: function () {
- this._isCacheToCanvasOn = false;
- },
- _removeCache: function (instanceID) {
- instanceID = instanceID || this._currentID;
- var cmds = this._cacheToCanvasCmds[instanceID];
- if (cmds) {
- cmds.length = 0;
- delete this._cacheToCanvasCmds[instanceID];
- }
- var locIDs = this._cacheInstanceIds;
- cc.arrayRemoveObject(locIDs, instanceID);
- },
- resetFlag: function () {
- this.childrenOrderDirty = false;
- this._transformNodePool.length = 0;
- },
- transform: function () {
- var locPool = this._transformNodePool;
- locPool.sort(this._sortNodeByLevelAsc);
- for (var i = 0, len = locPool.length; i < len; i++) {
- if (locPool[i]._dirtyFlag !== 0)
- locPool[i].updateStatus();
- }
- locPool.length = 0;
- },
- transformDirty: function () {
- return this._transformNodePool.length > 0;
- },
- _sortNodeByLevelAsc: function (n1, n2) {
- return n1._curLevel - n2._curLevel;
- },
- pushDirtyNode: function (node) {
- this._transformNodePool.push(node);
- },
- clear: function () {
- },
- clearRenderCommands: function () {
- this._renderCmds.length = 0;
- this._cacheInstanceIds.length = 0;
- this._isCacheToCanvasOn = false;
- this._allNeedDraw = true;
- this._canUseDirtyRegion = true;
- },
- pushRenderCommand: function (cmd) {
- if (!cmd.needDraw())
- return;
- if (!cmd._canUseDirtyRegion) {
- this._canUseDirtyRegion = false;
- }
- if (this._isCacheToCanvasOn) {
- var currentId = this._currentID, locCmdBuffer = this._cacheToCanvasCmds;
- var cmdList = locCmdBuffer[currentId];
- if (cmdList.indexOf(cmd) === -1)
- cmdList.push(cmd);
- } else {
- if (this._renderCmds.indexOf(cmd) === -1)
- this._renderCmds.push(cmd);
- }
- }
- };
- (function () {
- cc.CanvasContextWrapper = function (context) {
- this._context = context;
- this._saveCount = 0;
- this._currentAlpha = context.globalAlpha;
- this._currentCompositeOperation = context.globalCompositeOperation;
- this._currentFillStyle = context.fillStyle;
- this._currentStrokeStyle = context.strokeStyle;
- this._offsetX = 0;
- this._offsetY = 0;
- this._realOffsetY = this.height;
- this._armatureMode = 0;
- };
- var proto = cc.CanvasContextWrapper.prototype;
- proto.resetCache = function () {
- var context = this._context;
- this._currentAlpha = context.globalAlpha;
- this._currentCompositeOperation = context.globalCompositeOperation;
- this._currentFillStyle = context.fillStyle;
- this._currentStrokeStyle = context.strokeStyle;
- this._realOffsetY = this._context.canvas.height + this._offsetY;
- };
- proto.setOffset = function (x, y) {
- this._offsetX = x;
- this._offsetY = y;
- this._realOffsetY = this._context.canvas.height + this._offsetY;
- };
- proto.computeRealOffsetY = function () {
- this._realOffsetY = this._context.canvas.height + this._offsetY;
- };
- proto.setViewScale = function (scaleX, scaleY) {
- this._scaleX = scaleX;
- this._scaleY = scaleY;
- };
- proto.getContext = function () {
- return this._context;
- };
- proto.save = function () {
- this._context.save();
- this._saveCount++;
- };
- proto.restore = function () {
- this._context.restore();
- this._saveCount--;
- };
- proto.setGlobalAlpha = function (alpha) {
- if (this._saveCount > 0) {
- this._context.globalAlpha = alpha;
- } else {
- if (this._currentAlpha !== alpha) {
- this._currentAlpha = alpha;
- this._context.globalAlpha = alpha;
- }
- }
- };
- proto.setCompositeOperation = function (compositionOperation) {
- if (this._saveCount > 0) {
- this._context.globalCompositeOperation = compositionOperation;
- } else {
- if (this._currentCompositeOperation !== compositionOperation) {
- this._currentCompositeOperation = compositionOperation;
- this._context.globalCompositeOperation = compositionOperation;
- }
- }
- };
- proto.setFillStyle = function (fillStyle) {
- if (this._saveCount > 0) {
- this._context.fillStyle = fillStyle;
- } else {
- if (this._currentFillStyle !== fillStyle) {
- this._currentFillStyle = fillStyle;
- this._context.fillStyle = fillStyle;
- }
- }
- };
- proto.setStrokeStyle = function (strokeStyle) {
- if (this._saveCount > 0) {
- this._context.strokeStyle = strokeStyle;
- } else {
- if (this._currentStrokeStyle !== strokeStyle) {
- this._currentStrokeStyle = strokeStyle;
- this._context.strokeStyle = strokeStyle;
- }
- }
- };
- proto.setTransform = function (t, scaleX, scaleY) {
- if (this._armatureMode > 0) {
- this.restore();
- this.save();
- this._context.transform(t.a * scaleX, -t.b * scaleY, -t.c * scaleX, t.d * scaleY, t.tx * scaleX, -(t.ty * scaleY));
- } else {
- this._context.setTransform(t.a * scaleX, -t.b * scaleY, -t.c * scaleX, t.d * scaleY, this._offsetX + t.tx * scaleX, this._realOffsetY - (t.ty * scaleY));
- }
- };
- proto._switchToArmatureMode = function (enable, t, scaleX, scaleY) {
- if (enable) {
- this._armatureMode++;
- this._context.setTransform(t.a, t.c, t.b, t.d, this._offsetX + t.tx * scaleX, this._realOffsetY - (t.ty * scaleY));
- this.save();
- } else {
- this._armatureMode--;
- this.restore();
- }
- };
- })();
- var Region = function () {
- this._minX = 0;
- this._minY = 0;
- this._maxX = 0;
- this._maxY = 0;
- this._width = 0;
- this._height = 0;
- this._area = 0;
- };
- var regionProto = Region.prototype;
- var regionPool = [];
- function regionCreate() {
- var region = regionPool.pop();
- if (!region) {
- region = new Region();
- }
- return region;
- }
- function regionRelease(region) {
- regionPool.push(region);
- }
- regionProto.setTo = function (minX, minY, maxX, maxY) {
- this._minX = minX;
- this._minY = minY;
- this._maxX = maxX;
- this._maxY = maxY;
- this.updateArea();
- return this;
- };
- regionProto.intValues = function () {
- this._minX = Math.floor(this._minX);
- this._minY = Math.floor(this._minY);
- this._maxX = Math.ceil(this._maxX);
- this._maxY = Math.ceil(this._maxY);
- this.updateArea();
- };
- regionProto.updateArea = function () {
- this._width = this._maxX - this._minX;
- this._height = this._maxY - this._minY;
- this._area = this._width * this._height;
- };
- regionProto.union = function (target) {
- if(this._width <= 0 || this._height <= 0) {
- this.setTo(target._minX, target._minY, target._maxX, target._maxY);
- return;
- }
- if (this._minX > target._minX) {
- this._minX = target._minX;
- }
- if (this._minY > target._minY) {
- this._minY = target._minY;
- }
- if (this._maxX < target._maxX) {
- this._maxX = target._maxX;
- }
- if (this._maxY < target._maxY) {
- this._maxY = target._maxY;
- }
- this.updateArea();
- };
- regionProto.setEmpty = function () {
- this._minX = 0;
- this._minY = 0;
- this._maxX = 0;
- this._maxY = 0;
- this._width = 0;
- this._height = 0;
- this._area = 0;
- };
- regionProto.isEmpty = function () {
- return this._width <= 0 || this._height <= 0;
- };
- regionProto.intersects = function (target) {
- if (this._width <= 0 || this._height <= 0 || target._width <= 0 || target._height <= 0) {
- return false;
- }
- var max = this._minX > target._minX ? this._minX : target._minX;
- var min = this._maxX < target._maxX ? this._maxX : target._maxX;
- if (max > min) {
- return false;
- }
- max = this._minY > target._minY ? this._minY : target._minY;
- min = this._maxY < target._maxY ? this._maxY : target._maxY;
- return max <= min;
- };
- regionProto.updateRegion = function (bounds, matrix) {
- if (bounds.width == 0 || bounds.height == 0) {
- this.setEmpty();
- return;
- }
- var m = matrix;
- var a = m.a;
- var b = m.b;
- var c = m.c;
- var d = m.d;
- var tx = m.tx;
- var ty = m.ty;
- var x = bounds.x;
- var y = bounds.y;
- var xMax = x + bounds.width;
- var yMax = y + bounds.height;
- var minX, minY, maxX, maxY;
- if (a == 1.0 && b == 0.0 && c == 0.0 && d == 1.0) {
- minX = x + tx - 1;
- minY = y + ty - 1;
- maxX = xMax + tx + 1;
- maxY = yMax + ty + 1;
- }
- else {
- var x0 = a * x + c * y + tx;
- var y0 = b * x + d * y + ty;
- var x1 = a * xMax + c * y + tx;
- var y1 = b * xMax + d * y + ty;
- var x2 = a * xMax + c * yMax + tx;
- var y2 = b * xMax + d * yMax + ty;
- var x3 = a * x + c * yMax + tx;
- var y3 = b * x + d * yMax + ty;
- var tmp = 0;
- if (x0 > x1) {
- tmp = x0;
- x0 = x1;
- x1 = tmp;
- }
- if (x2 > x3) {
- tmp = x2;
- x2 = x3;
- x3 = tmp;
- }
- minX = (x0 < x2 ? x0 : x2) - 1;
- maxX = (x1 > x3 ? x1 : x3) + 1;
- if (y0 > y1) {
- tmp = y0;
- y0 = y1;
- y1 = tmp;
- }
- if (y2 > y3) {
- tmp = y2;
- y2 = y3;
- y3 = tmp;
- }
- minY = (y0 < y2 ? y0 : y2) - 1;
- maxY = (y1 > y3 ? y1 : y3) + 1;
- }
- this._minX = minX;
- this._minY = minY;
- this._maxX = maxX;
- this._maxY = maxY;
- this._width = maxX - minX;
- this._height = maxY - minY;
- this._area = this._width * this._height;
- };
- function unionArea(r1, r2) {
- var minX = r1._minX < r2._minX ? r1._minX : r2._minX;
- var minY = r1._minY < r2._minY ? r1._minY : r2._minY;
- var maxX = r1._maxX > r2._maxX ? r1._maxX : r2._maxX;
- var maxY = r1._maxY > r2._maxY ? r1._maxY : r2._maxY;
- return (maxX - minX) * (maxY - minY);
- }
- var DirtyRegion = function() {
- this.dirtyList = [];
- this.hasClipRect = false;
- this.clipWidth = 0;
- this.clipHeight = 0;
- this.clipArea = 0;
- this.clipRectChanged = false;
- };
- var dirtyRegionProto = DirtyRegion.prototype;
- dirtyRegionProto.setClipRect = function(width, height) {
- this.hasClipRect = true;
- this.clipRectChanged = true;
- this.clipWidth = Math.ceil(width);
- this.clipHeight = Math.ceil(height);
- this.clipArea = this.clipWidth * this.clipHeight;
- };
- dirtyRegionProto.addRegion = function(target) {
- var minX = target._minX, minY = target._minY, maxX = target._maxX, maxY = target._maxY;
- if (this.hasClipRect) {
- if (minX < 0) {
- minX = 0;
- }
- if (minY < 0) {
- minY = 0;
- }
- if (maxX > this.clipWidth) {
- maxX = this.clipWidth;
- }
- if (maxY > this.clipHeight) {
- maxY = this.clipHeight;
- }
- }
- if (minX >= maxX || minY >= maxY) {
- return false;
- }
- if (this.clipRectChanged) {
- return true;
- }
- var dirtyList = this.dirtyList;
- var region = regionCreate();
- dirtyList.push(region.setTo(minX, minY, maxX, maxY));
- this.mergeDirtyList(dirtyList);
- return true;
- };
- dirtyRegionProto.clear = function() {
- var dirtyList = this.dirtyList;
- var length = dirtyList.length;
- for (var i = 0; i < length; i++) {
- regionRelease(dirtyList[i]);
- }
- dirtyList.length = 0;
- };
- dirtyRegionProto.getDirtyRegions = function() {
- var dirtyList = this.dirtyList;
- if (this.clipRectChanged) {
- this.clipRectChanged = false;
- this.clear();
- var region = regionCreate();
- dirtyList.push(region.setTo(0, 0, this.clipWidth, this.clipHeight));
- }
- else {
- while (this.mergeDirtyList(dirtyList)) {
- }
- }
- var numDirty = this.dirtyList.length;
- if (numDirty > 0) {
- for (var i = 0; i < numDirty; i++) {
- this.dirtyList[i].intValues();
- }
- }
- return this.dirtyList;
- };
- dirtyRegionProto.mergeDirtyList = function(dirtyList) {
- var length = dirtyList.length;
- if (length < 2) {
- return false;
- }
- var hasClipRect = this.hasClipRect;
- var bestDelta = length > 3 ? Number.POSITIVE_INFINITY : 0;
- var mergeA = 0;
- var mergeB = 0;
- var totalArea = 0;
- for (var i = 0; i < length - 1; i++) {
- var regionA = dirtyList[i];
- hasClipRect && (totalArea += regionA.area);
- for (var j = i + 1; j < length; j++) {
- var regionB = dirtyList[j];
- var delta = unionArea(regionA, regionB) - regionA.area - regionB.area;
- if (bestDelta > delta) {
- mergeA = i;
- mergeB = j;
- bestDelta = delta;
- }
- }
- }
- if (hasClipRect && (totalArea / this.clipArea) > 0.95) {
- this.clipRectChanged = true;
- }
- if (mergeA != mergeB) {
- var region = dirtyList[mergeB];
- dirtyList[mergeA].union(region);
- regionRelease(region);
- dirtyList.splice(mergeB, 1);
- return true;
- }
- return false;
- };
- cc.Region = Region;
- cc.DirtyRegion = DirtyRegion;
- cc.profiler = (function () {
- var _showFPS = false;
- var _inited = false;
- var _frames = 0, _frameRate = 0, _lastSPF = 0, _accumDt = 0;
- var _afterVisitListener = null,
- _FPSLabel = document.createElement('div'),
- _SPFLabel = document.createElement('div'),
- _drawsLabel = document.createElement('div'),
- _fps = document.createElement('div');
- var LEVEL_DET_FACTOR = 0.6, _levelDetCycle = 10;
- var LEVELS = [0, 10, 20, 30];
- var _fpsCount = [0, 0, 0, 0];
- var _currLevel = 3, _analyseCount = 0, _totalFPS = 0;
- _fps.id = 'fps';
- _fps.style.position = 'absolute';
- _fps.style.padding = '3px';
- _fps.style.textAlign = 'left';
- _fps.style.backgroundColor = 'rgb(0, 0, 34)';
- _fps.style.bottom = cc.DIRECTOR_STATS_POSITION.y + '0px';
- _fps.style.left = cc.DIRECTOR_STATS_POSITION.x + 'px';
- _fps.style.width = '45px';
- _fps.style.height = '60px';
- var labels = [_drawsLabel, _SPFLabel, _FPSLabel];
- for (var i = 0; i < 3; ++i) {
- var style = labels[i].style;
- style.color = 'rgb(0, 255, 255)';
- style.font = 'bold 12px Helvetica, Arial';
- style.lineHeight = '20px';
- style.width = '100%';
- _fps.appendChild(labels[i]);
- }
- var analyseFPS = function (fps) {
- var lastId = LEVELS.length - 1, i = lastId, ratio, average = 0;
- _analyseCount++;
- _totalFPS += fps;
- for (; i >= 0; i--) {
- if (fps >= LEVELS[i]) {
- _fpsCount[i]++;
- break;
- }
- }
- if (_analyseCount >= _levelDetCycle) {
- average = _totalFPS / _levelDetCycle;
- for (i = lastId; i >0; i--) {
- ratio = _fpsCount[i] / _levelDetCycle;
- if (ratio >= LEVEL_DET_FACTOR && average >= LEVELS[i]) {
- if (i != _currLevel) {
- _currLevel = i;
- profiler.onFrameRateChange && profiler.onFrameRateChange(average.toFixed(2));
- }
- break;
- }
- }
- _changeCount = 0;
- _analyseCount = 0;
- _totalFPS = 0;
- for (i = lastId; i > 0; i--) {
- _fpsCount[i] = 0;
- }
- }
- };
- var afterVisit = function () {
- _lastSPF = cc.director.getSecondsPerFrame();
- _frames++;
- _accumDt += cc.director.getDeltaTime();
- if (_accumDt > cc.DIRECTOR_FPS_INTERVAL) {
- _frameRate = _frames / _accumDt;
- _frames = 0;
- _accumDt = 0;
- if (profiler.onFrameRateChange) {
- analyseFPS(_frameRate);
- }
- if (_showFPS) {
- _SPFLabel.innerText = _lastSPF.toFixed(3);
- _FPSLabel.innerText = _frameRate.toFixed(1);
- _drawsLabel.innerText = (0 | cc.g_NumberOfDraws).toString();
- }
- }
- };
- var profiler = {
- onFrameRateChange: null,
- getSecondsPerFrame: function () {
- return _lastSPF;
- },
- getFrameRate: function () {
- return _frameRate;
- },
- setProfileDuration: function (duration) {
- if (!isNaN(duration) && duration > 0) {
- _levelDetCycle = duration / cc.DIRECTOR_FPS_INTERVAL;
- }
- },
- resumeProfiling: function () {
- cc.eventManager.addListener(_afterVisitListener, 1);
- },
- stopProfiling: function () {
- cc.eventManager.removeListener(_afterVisitListener);
- },
- isShowingStats: function () {
- return _showFPS;
- },
- showStats: function () {
- if (!_inited) {
- this.init();
- }
- if (_fps.parentElement === null) {
- cc.container.appendChild(_fps);
- }
- _showFPS = true;
- },
- hideStats: function () {
- _showFPS = false;
- if (_fps.parentElement === cc.container) {
- cc.container.removeChild(_fps);
- }
- },
- init: function () {
- if (!_inited) {
- _afterVisitListener = cc.eventManager.addCustomListener(cc.Director.EVENT_AFTER_VISIT, afterVisit);
- _inited = true;
- }
- }
- };
- return profiler;
- })();
- cc._LogInfos = {
- ActionManager_addAction: "cc.ActionManager.addAction(): action must be non-null",
- ActionManager_removeAction: "cocos2d: removeAction: Target not found",
- ActionManager_removeActionByTag: "cc.ActionManager.removeActionByTag(): an invalid tag",
- ActionManager_removeActionByTag_2: "cc.ActionManager.removeActionByTag(): target must be non-null",
- ActionManager_getActionByTag: "cc.ActionManager.getActionByTag(): an invalid tag",
- ActionManager_getActionByTag_2: "cocos2d : getActionByTag(tag = %s): Action not found",
- configuration_dumpInfo: "cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.js)",
- configuration_loadConfigFile: "Expected 'data' dict, but not found. Config file: %s",
- configuration_loadConfigFile_2: "Please load the resource first : %s",
- Director_resume: "cocos2d: Director: Error in gettimeofday",
- Director_setProjection: "cocos2d: Director: unrecognized projection",
- Director_popToSceneStackLevel: "cocos2d: Director: unrecognized projection",
- Director_popToSceneStackLevel_2: "cocos2d: Director: Error in gettimeofday",
- Director_popScene: "running scene should not null",
- Director_pushScene: "the scene should not null",
- arrayVerifyType: "element type is wrong!",
- Scheduler_scheduleCallbackForTarget: "CCSheduler#scheduleCallback. Callback already scheduled. Updating interval from:%s to %s",
- Scheduler_scheduleCallbackForTarget_2: "cc.scheduler.scheduleCallbackForTarget(): callback_fn should be non-null.",
- Scheduler_scheduleCallbackForTarget_3: "cc.scheduler.scheduleCallbackForTarget(): target should be non-null.",
- Scheduler_pauseTarget: "cc.Scheduler.pauseTarget():target should be non-null",
- Scheduler_resumeTarget: "cc.Scheduler.resumeTarget():target should be non-null",
- Scheduler_isTargetPaused: "cc.Scheduler.isTargetPaused():target should be non-null",
- Node_getZOrder: "getZOrder is deprecated. Please use getLocalZOrder instead.",
- Node_setZOrder: "setZOrder is deprecated. Please use setLocalZOrder instead.",
- Node_getRotation: "RotationX != RotationY. Don't know which one to return",
- Node_getScale: "ScaleX != ScaleY. Don't know which one to return",
- Node_addChild: "An Node can't be added as a child of itself.",
- Node_addChild_2: "child already added. It can't be added again",
- Node_addChild_3: "child must be non-null",
- Node_removeFromParentAndCleanup: "removeFromParentAndCleanup is deprecated. Use removeFromParent instead",
- Node_boundingBox: "boundingBox is deprecated. Use getBoundingBox instead",
- Node_removeChildByTag: "argument tag is an invalid tag",
- Node_removeChildByTag_2: "cocos2d: removeChildByTag(tag = %s): child not found!",
- Node_removeAllChildrenWithCleanup: "removeAllChildrenWithCleanup is deprecated. Use removeAllChildren instead",
- Node_stopActionByTag: "cc.Node.stopActionBy(): argument tag an invalid tag",
- Node_getActionByTag: "cc.Node.getActionByTag(): argument tag is an invalid tag",
- Node_resumeSchedulerAndActions: "resumeSchedulerAndActions is deprecated, please use resume instead.",
- Node_pauseSchedulerAndActions: "pauseSchedulerAndActions is deprecated, please use pause instead.",
- Node__arrayMakeObjectsPerformSelector: "Unknown callback function",
- Node_reorderChild: "child must be non-null",
- Node_runAction: "cc.Node.runAction(): action must be non-null",
- Node_schedule: "callback function must be non-null",
- Node_schedule_2: "interval must be positive",
- Node_initWithTexture: "cocos2d: Could not initialize cc.AtlasNode. Invalid Texture.",
- AtlasNode_updateAtlasValues: "cc.AtlasNode.updateAtlasValues(): Shall be overridden in subclasses",
- AtlasNode_initWithTileFile: "",
- AtlasNode__initWithTexture: "cocos2d: Could not initialize cc.AtlasNode. Invalid Texture.",
- _EventListenerKeyboard_checkAvailable: "cc._EventListenerKeyboard.checkAvailable(): Invalid EventListenerKeyboard!",
- _EventListenerTouchOneByOne_checkAvailable: "cc._EventListenerTouchOneByOne.checkAvailable(): Invalid EventListenerTouchOneByOne!",
- _EventListenerTouchAllAtOnce_checkAvailable: "cc._EventListenerTouchAllAtOnce.checkAvailable(): Invalid EventListenerTouchAllAtOnce!",
- _EventListenerAcceleration_checkAvailable: "cc._EventListenerAcceleration.checkAvailable(): _onAccelerationEvent must be non-nil",
- EventListener_create: "Invalid parameter.",
- __getListenerID: "Don't call this method if the event is for touch.",
- eventManager__forceAddEventListener: "Invalid scene graph priority!",
- eventManager_addListener: "0 priority is forbidden for fixed priority since it's used for scene graph based priority.",
- eventManager_removeListeners: "Invalid listener type!",
- eventManager_setPriority: "Can't set fixed priority with scene graph based listener.",
- eventManager_addListener_2: "Invalid parameters.",
- eventManager_addListener_3: "listener must be a cc.EventListener object when adding a fixed priority listener",
- eventManager_addListener_4: "The listener has been registered, please don't register it again.",
- LayerMultiplex_initWithLayers: "parameters should not be ending with null in Javascript",
- LayerMultiplex_switchTo: "Invalid index in MultiplexLayer switchTo message",
- LayerMultiplex_switchToAndReleaseMe: "Invalid index in MultiplexLayer switchTo message",
- LayerMultiplex_addLayer: "cc.Layer.addLayer(): layer should be non-null",
- EGLView_setDesignResolutionSize: "Resolution not valid",
- EGLView_setDesignResolutionSize_2: "should set resolutionPolicy",
- inputManager_handleTouchesBegin: "The touches is more than MAX_TOUCHES, nUnusedIndex = %s",
- swap: "cc.swap is being modified from original macro, please check usage",
- checkGLErrorDebug: "WebGL error %s",
- animationCache__addAnimationsWithDictionary: "cocos2d: cc.AnimationCache: No animations were found in provided dictionary.",
- animationCache__addAnimationsWithDictionary_2: "cc.AnimationCache. Invalid animation format",
- animationCache_addAnimations: "cc.AnimationCache.addAnimations(): File could not be found",
- animationCache__parseVersion1: "cocos2d: cc.AnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.",
- animationCache__parseVersion1_2: "cocos2d: cc.AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the cc.SpriteFrameCache. This frame will not be added to the animation.",
- animationCache__parseVersion1_3: "cocos2d: cc.AnimationCache: None of the frames for animation '%s' were found in the cc.SpriteFrameCache. Animation is not being added to the Animation Cache.",
- animationCache__parseVersion1_4: "cocos2d: cc.AnimationCache: An animation in your dictionary refers to a frame which is not in the cc.SpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.",
- animationCache__parseVersion2: "cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.",
- animationCache__parseVersion2_2: "cocos2d: cc.AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the cc.SpriteFrameCache. This frame will not be added to the animation.",
- animationCache_addAnimations_2: "cc.AnimationCache.addAnimations(): Invalid texture file name",
- Sprite_reorderChild: "cc.Sprite.reorderChild(): this child is not in children list",
- Sprite_ignoreAnchorPointForPosition: "cc.Sprite.ignoreAnchorPointForPosition(): it is invalid in cc.Sprite when using SpriteBatchNode",
- Sprite_setDisplayFrameWithAnimationName: "cc.Sprite.setDisplayFrameWithAnimationName(): Frame not found",
- Sprite_setDisplayFrameWithAnimationName_2: "cc.Sprite.setDisplayFrameWithAnimationName(): Invalid frame index",
- Sprite_setDisplayFrame: "setDisplayFrame is deprecated, please use setSpriteFrame instead.",
- Sprite__updateBlendFunc: "cc.Sprite._updateBlendFunc(): _updateBlendFunc doesn't work when the sprite is rendered using a cc.CCSpriteBatchNode",
- Sprite_initWithSpriteFrame: "cc.Sprite.initWithSpriteFrame(): spriteFrame should be non-null",
- Sprite_initWithSpriteFrameName: "cc.Sprite.initWithSpriteFrameName(): spriteFrameName should be non-null",
- Sprite_initWithSpriteFrameName1: " is null, please check.",
- Sprite_initWithFile: "cc.Sprite.initWithFile(): filename should be non-null",
- Sprite_setDisplayFrameWithAnimationName_3: "cc.Sprite.setDisplayFrameWithAnimationName(): animationName must be non-null",
- Sprite_reorderChild_2: "cc.Sprite.reorderChild(): child should be non-null",
- Sprite_addChild: "cc.Sprite.addChild(): cc.Sprite only supports cc.Sprites as children when using cc.SpriteBatchNode",
- Sprite_addChild_2: "cc.Sprite.addChild(): cc.Sprite only supports a sprite using same texture as children when using cc.SpriteBatchNode",
- Sprite_addChild_3: "cc.Sprite.addChild(): child should be non-null",
- Sprite_setTexture: "cc.Sprite.texture setter: Batched sprites should use the same texture as the batchnode",
- Sprite_updateQuadFromSprite: "cc.SpriteBatchNode.updateQuadFromSprite(): cc.SpriteBatchNode only supports cc.Sprites as children",
- Sprite_insertQuadFromSprite: "cc.SpriteBatchNode.insertQuadFromSprite(): cc.SpriteBatchNode only supports cc.Sprites as children",
- Sprite_addChild_4: "cc.SpriteBatchNode.addChild(): cc.SpriteBatchNode only supports cc.Sprites as children",
- Sprite_addChild_5: "cc.SpriteBatchNode.addChild(): cc.Sprite is not using the same texture",
- Sprite_initWithTexture: "Sprite.initWithTexture(): Argument must be non-nil ",
- Sprite_setSpriteFrame: "Invalid spriteFrameName",
- Sprite_setTexture_2: "Invalid argument: cc.Sprite.texture setter expects a CCTexture2D.",
- Sprite_updateQuadFromSprite_2: "cc.SpriteBatchNode.updateQuadFromSprite(): sprite should be non-null",
- Sprite_insertQuadFromSprite_2: "cc.SpriteBatchNode.insertQuadFromSprite(): sprite should be non-null",
- SpriteBatchNode_addSpriteWithoutQuad: "cc.SpriteBatchNode.addQuadFromSprite(): SpriteBatchNode only supports cc.Sprites as children",
- SpriteBatchNode_increaseAtlasCapacity: "cocos2d: CCSpriteBatchNode: resizing TextureAtlas capacity from %s to %s.",
- SpriteBatchNode_increaseAtlasCapacity_2: "cocos2d: WARNING: Not enough memory to resize the atlas",
- SpriteBatchNode_reorderChild: "cc.SpriteBatchNode.addChild(): Child doesn't belong to Sprite",
- SpriteBatchNode_removeChild: "cc.SpriteBatchNode.addChild(): sprite batch node should contain the child",
- SpriteBatchNode_addSpriteWithoutQuad_2: "cc.SpriteBatchNode.addQuadFromSprite(): child should be non-null",
- SpriteBatchNode_reorderChild_2: "cc.SpriteBatchNode.addChild(): child should be non-null",
- spriteFrameCache__getFrameConfig: "cocos2d: WARNING: originalWidth/Height not found on the cc.SpriteFrame. AnchorPoint won't work as expected. Regenrate the .plist",
- spriteFrameCache_addSpriteFrames: "cocos2d: WARNING: an alias with name %s already exists",
- spriteFrameCache__checkConflict: "cocos2d: WARNING: Sprite frame: %s has already been added by another source, please fix name conflit",
- spriteFrameCache_getSpriteFrame: "cocos2d: cc.SpriteFrameCahce: Frame %s not found",
- spriteFrameCache__getFrameConfig_2: "Please load the resource first : %s",
- spriteFrameCache_addSpriteFrames_2: "cc.SpriteFrameCache.addSpriteFrames(): plist should be non-null",
- spriteFrameCache_addSpriteFrames_3: "Argument must be non-nil",
- CCSpriteBatchNode_updateQuadFromSprite: "cc.SpriteBatchNode.updateQuadFromSprite(): cc.SpriteBatchNode only supports cc.Sprites as children",
- CCSpriteBatchNode_insertQuadFromSprite: "cc.SpriteBatchNode.insertQuadFromSprite(): cc.SpriteBatchNode only supports cc.Sprites as children",
- CCSpriteBatchNode_addChild: "cc.SpriteBatchNode.addChild(): cc.SpriteBatchNode only supports cc.Sprites as children",
- CCSpriteBatchNode_initWithTexture: "Sprite.initWithTexture(): Argument must be non-nil ",
- CCSpriteBatchNode_addChild_2: "cc.Sprite.addChild(): child should be non-null",
- CCSpriteBatchNode_setSpriteFrame: "Invalid spriteFrameName",
- CCSpriteBatchNode_setTexture: "Invalid argument: cc.Sprite texture setter expects a CCTexture2D.",
- CCSpriteBatchNode_updateQuadFromSprite_2: "cc.SpriteBatchNode.updateQuadFromSprite(): sprite should be non-null",
- CCSpriteBatchNode_insertQuadFromSprite_2: "cc.SpriteBatchNode.insertQuadFromSprite(): sprite should be non-null",
- CCSpriteBatchNode_addChild_3: "cc.SpriteBatchNode.addChild(): child should be non-null",
- TextureAtlas_initWithFile: "cocos2d: Could not open file: %s",
- TextureAtlas_insertQuad: "cc.TextureAtlas.insertQuad(): invalid totalQuads",
- TextureAtlas_initWithTexture: "cc.TextureAtlas.initWithTexture():texture should be non-null",
- TextureAtlas_updateQuad: "cc.TextureAtlas.updateQuad(): quad should be non-null",
- TextureAtlas_updateQuad_2: "cc.TextureAtlas.updateQuad(): Invalid index",
- TextureAtlas_insertQuad_2: "cc.TextureAtlas.insertQuad(): Invalid index",
- TextureAtlas_insertQuads: "cc.TextureAtlas.insertQuad(): Invalid index + amount",
- TextureAtlas_insertQuadFromIndex: "cc.TextureAtlas.insertQuadFromIndex(): Invalid newIndex",
- TextureAtlas_insertQuadFromIndex_2: "cc.TextureAtlas.insertQuadFromIndex(): Invalid fromIndex",
- TextureAtlas_removeQuadAtIndex: "cc.TextureAtlas.removeQuadAtIndex(): Invalid index",
- TextureAtlas_removeQuadsAtIndex: "cc.TextureAtlas.removeQuadsAtIndex(): index + amount out of bounds",
- TextureAtlas_moveQuadsFromIndex: "cc.TextureAtlas.moveQuadsFromIndex(): move is out of bounds",
- TextureAtlas_moveQuadsFromIndex_2: "cc.TextureAtlas.moveQuadsFromIndex(): Invalid newIndex",
- TextureAtlas_moveQuadsFromIndex_3: "cc.TextureAtlas.moveQuadsFromIndex(): Invalid oldIndex",
- textureCache_addPVRTCImage: "TextureCache:addPVRTCImage does not support on HTML5",
- textureCache_addETCImage: "TextureCache:addPVRTCImage does not support on HTML5",
- textureCache_textureForKey: "textureForKey is deprecated. Please use getTextureForKey instead.",
- textureCache_addPVRImage: "addPVRImage does not support on HTML5",
- textureCache_addUIImage: "cocos2d: Couldn't add UIImage in TextureCache",
- textureCache_dumpCachedTextureInfo: "cocos2d: '%s' id=%s %s x %s",
- textureCache_dumpCachedTextureInfo_2: "cocos2d: '%s' id= HTMLCanvasElement %s x %s",
- textureCache_dumpCachedTextureInfo_3: "cocos2d: TextureCache dumpDebugInfo: %s textures, HTMLCanvasElement for %s KB (%s MB)",
- textureCache_addUIImage_2: "cc.Texture.addUIImage(): image should be non-null",
- Texture2D_initWithETCFile: "initWithETCFile does not support on HTML5",
- Texture2D_initWithPVRFile: "initWithPVRFile does not support on HTML5",
- Texture2D_initWithPVRTCData: "initWithPVRTCData does not support on HTML5",
- Texture2D_addImage: "cc.Texture.addImage(): path should be non-null",
- Texture2D_initWithImage: "cocos2d: cc.Texture2D. Can't create Texture. UIImage is nil",
- Texture2D_initWithImage_2: "cocos2d: WARNING: Image (%s x %s) is bigger than the supported %s x %s",
- Texture2D_initWithString: "initWithString isn't supported on cocos2d-html5",
- Texture2D_initWithETCFile_2: "initWithETCFile does not support on HTML5",
- Texture2D_initWithPVRFile_2: "initWithPVRFile does not support on HTML5",
- Texture2D_initWithPVRTCData_2: "initWithPVRTCData does not support on HTML5",
- Texture2D_bitsPerPixelForFormat: "bitsPerPixelForFormat: %s, cannot give useful result, it's a illegal pixel format",
- Texture2D__initPremultipliedATextureWithImage: "cocos2d: cc.Texture2D: Using RGB565 texture since image has no alpha",
- Texture2D_addImage_2: "cc.Texture.addImage(): path should be non-null",
- Texture2D_initWithData: "NSInternalInconsistencyException",
- MissingFile: "Missing file: %s",
- radiansToDegress: "cc.radiansToDegress() should be called cc.radiansToDegrees()",
- RectWidth: "Rect width exceeds maximum margin: %s",
- RectHeight: "Rect height exceeds maximum margin: %s",
- EventManager__updateListeners: "If program goes here, there should be event in dispatch.",
- EventManager__updateListeners_2: "_inDispatch should be 1 here."
- };
- cc._logToWebPage = function (msg) {
- if (!cc._canvas)
- return;
- var logList = cc._logList;
- var doc = document;
- if (!logList) {
- var logDiv = doc.createElement("Div");
- var logDivStyle = logDiv.style;
- logDiv.setAttribute("id", "logInfoDiv");
- cc._canvas.parentNode.appendChild(logDiv);
- logDiv.setAttribute("width", "200");
- logDiv.setAttribute("height", cc._canvas.height);
- logDivStyle.zIndex = "99999";
- logDivStyle.position = "absolute";
- logDivStyle.top = "0";
- logDivStyle.left = "0";
- logList = cc._logList = doc.createElement("textarea");
- var logListStyle = logList.style;
- logList.setAttribute("rows", "20");
- logList.setAttribute("cols", "30");
- logList.setAttribute("disabled", true);
- logDiv.appendChild(logList);
- logListStyle.backgroundColor = "transparent";
- logListStyle.borderBottom = "1px solid #cccccc";
- logListStyle.borderRightWidth = "0px";
- logListStyle.borderLeftWidth = "0px";
- logListStyle.borderTopWidth = "0px";
- logListStyle.borderTopStyle = "none";
- logListStyle.borderRightStyle = "none";
- logListStyle.borderLeftStyle = "none";
- logListStyle.padding = "0px";
- logListStyle.margin = 0;
- }
- logList.value = logList.value + msg + "\r\n";
- logList.scrollTop = logList.scrollHeight;
- };
- cc._formatString = function (arg) {
- if (cc.isObject(arg)) {
- try {
- return JSON.stringify(arg);
- } catch (err) {
- return "";
- }
- } else
- return arg;
- };
- cc._initDebugSetting = function (mode) {
- var ccGame = cc.game;
- if(mode === ccGame.DEBUG_MODE_NONE)
- return;
- var locLog;
- if(mode > ccGame.DEBUG_MODE_ERROR){
- locLog = cc._logToWebPage.bind(cc);
- cc.error = function(){
- locLog("ERROR : " + cc.formatStr.apply(cc, arguments));
- };
- cc.assert = function(cond, msg) {
- if (!cond && msg) {
- for (var i = 2; i < arguments.length; i++)
- msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i]));
- locLog("Assert: " + msg);
- }
- };
- if(mode !== ccGame.DEBUG_MODE_ERROR_FOR_WEB_PAGE){
- cc.warn = function(){
- locLog("WARN : " + cc.formatStr.apply(cc, arguments));
- };
- }
- if(mode === ccGame.DEBUG_MODE_INFO_FOR_WEB_PAGE){
- cc.log = function(){
- locLog(cc.formatStr.apply(cc, arguments));
- };
- }
- } else if(console && console.log.apply){//console is null when user doesn't open dev tool on IE9
- cc.error = Function.prototype.bind.call(console.error, console);
- if (console.assert) {
- cc.assert = Function.prototype.bind.call(console.assert, console);
- } else {
- cc.assert = function (cond, msg) {
- if (!cond && msg) {
- for (var i = 2; i < arguments.length; i++)
- msg = msg.replace(/(%s)|(%d)/, cc._formatString(arguments[i]));
- throw new Error(msg);
- }
- };
- }
- if (mode !== ccGame.DEBUG_MODE_ERROR)
- cc.warn = Function.prototype.bind.call(console.warn, console);
- if (mode === ccGame.DEBUG_MODE_INFO)
- cc.log = Function.prototype.bind.call(console.log, console);
- }
- };
- cc.HashElement = cc.Class.extend({
- actions:null,
- target:null,
- actionIndex:0,
- currentAction:null,
- currentActionSalvaged:false,
- paused:false,
- hh:null,
- ctor:function () {
- this.actions = [];
- this.target = null;
- this.actionIndex = 0;
- this.currentAction = null;
- this.currentActionSalvaged = false;
- this.paused = false;
- this.hh = null;
- }
- });
- cc.ActionManager = cc.Class.extend({
- _hashTargets:null,
- _arrayTargets:null,
- _currentTarget:null,
- _currentTargetSalvaged:false,
- _searchElementByTarget:function (arr, target) {
- for (var k = 0; k < arr.length; k++) {
- if (target === arr[k].target)
- return arr[k];
- }
- return null;
- },
- ctor:function () {
- this._hashTargets = {};
- this._arrayTargets = [];
- this._currentTarget = null;
- this._currentTargetSalvaged = false;
- },
- addAction:function (action, target, paused) {
- if(!action)
- throw new Error("cc.ActionManager.addAction(): action must be non-null");
- if(!target)
- throw new Error("cc.ActionManager.addAction(): action must be non-null");
- var element = this._hashTargets[target.__instanceId];
- if (!element) {
- element = new cc.HashElement();
- element.paused = paused;
- element.target = target;
- this._hashTargets[target.__instanceId] = element;
- this._arrayTargets.push(element);
- }
- this._actionAllocWithHashElement(element);
- element.actions.push(action);
- action.startWithTarget(target);
- },
- removeAllActions:function () {
- var locTargets = this._arrayTargets;
- for (var i = 0; i < locTargets.length; i++) {
- var element = locTargets[i];
- if (element)
- this.removeAllActionsFromTarget(element.target, true);
- }
- },
- removeAllActionsFromTarget:function (target, forceDelete) {
- if (target == null)
- return;
- var element = this._hashTargets[target.__instanceId];
- if (element) {
- if (element.actions.indexOf(element.currentAction) !== -1 && !(element.currentActionSalvaged))
- element.currentActionSalvaged = true;
- element.actions.length = 0;
- if (this._currentTarget === element && !forceDelete) {
- this._currentTargetSalvaged = true;
- } else {
- this._deleteHashElement(element);
- }
- }
- },
- removeAction:function (action) {
- if (action == null)
- return;
- var target = action.getOriginalTarget();
- var element = this._hashTargets[target.__instanceId];
- if (element) {
- for (var i = 0; i < element.actions.length; i++) {
- if (element.actions[i] === action) {
- element.actions.splice(i, 1);
- break;
- }
- }
- } else {
- cc.log(cc._LogInfos.ActionManager_removeAction);
- }
- },
- removeActionByTag:function (tag, target) {
- if(tag === cc.ACTION_TAG_INVALID)
- cc.log(cc._LogInfos.ActionManager_addAction);
- cc.assert(target, cc._LogInfos.ActionManager_addAction);
- var element = this._hashTargets[target.__instanceId];
- if (element) {
- var limit = element.actions.length;
- for (var i = 0; i < limit; ++i) {
- var action = element.actions[i];
- if (action && action.getTag() === tag && action.getOriginalTarget() === target) {
- this._removeActionAtIndex(i, element);
- break;
- }
- }
- }
- },
- getActionByTag:function (tag, target) {
- if(tag === cc.ACTION_TAG_INVALID)
- cc.log(cc._LogInfos.ActionManager_getActionByTag);
- var element = this._hashTargets[target.__instanceId];
- if (element) {
- if (element.actions != null) {
- for (var i = 0; i < element.actions.length; ++i) {
- var action = element.actions[i];
- if (action && action.getTag() === tag)
- return action;
- }
- }
- cc.log(cc._LogInfos.ActionManager_getActionByTag_2, tag);
- }
- return null;
- },
- numberOfRunningActionsInTarget:function (target) {
- var element = this._hashTargets[target.__instanceId];
- if (element)
- return (element.actions) ? element.actions.length : 0;
- return 0;
- },
- pauseTarget:function (target) {
- var element = this._hashTargets[target.__instanceId];
- if (element)
- element.paused = true;
- },
- resumeTarget:function (target) {
- var element = this._hashTargets[target.__instanceId];
- if (element)
- element.paused = false;
- },
- pauseAllRunningActions:function(){
- var idsWithActions = [];
- var locTargets = this._arrayTargets;
- for(var i = 0; i< locTargets.length; i++){
- var element = locTargets[i];
- if(element && !element.paused){
- element.paused = true;
- idsWithActions.push(element.target);
- }
- }
- return idsWithActions;
- },
- resumeTargets:function(targetsToResume){
- if(!targetsToResume)
- return;
- for(var i = 0 ; i< targetsToResume.length; i++){
- if(targetsToResume[i])
- this.resumeTarget(targetsToResume[i]);
- }
- },
- purgeSharedManager:function () {
- cc.director.getScheduler().unscheduleUpdate(this);
- },
- _removeActionAtIndex:function (index, element) {
- var action = element.actions[index];
- if ((action === element.currentAction) && (!element.currentActionSalvaged))
- element.currentActionSalvaged = true;
- element.actions.splice(index, 1);
- if (element.actionIndex >= index)
- element.actionIndex--;
- if (element.actions.length === 0) {
- if (this._currentTarget === element) {
- this._currentTargetSalvaged = true;
- } else {
- this._deleteHashElement(element);
- }
- }
- },
- _deleteHashElement:function (element) {
- var ret = false;
- if (element) {
- if(this._hashTargets[element.target.__instanceId]){
- delete this._hashTargets[element.target.__instanceId];
- cc.arrayRemoveObject(this._arrayTargets, element);
- ret = true;
- }
- element.actions = null;
- element.target = null;
- }
- return ret;
- },
- _actionAllocWithHashElement:function (element) {
- if (element.actions == null) {
- element.actions = [];
- }
- },
- update:function (dt) {
- var locTargets = this._arrayTargets , locCurrTarget;
- for (var elt = 0; elt < locTargets.length; elt++) {
- this._currentTarget = locTargets[elt];
- locCurrTarget = this._currentTarget;
- if (!locCurrTarget.paused) {
- for (locCurrTarget.actionIndex = 0;
- locCurrTarget.actionIndex < (locCurrTarget.actions ? locCurrTarget.actions.length : 0);
- locCurrTarget.actionIndex++) {
- locCurrTarget.currentAction = locCurrTarget.actions[locCurrTarget.actionIndex];
- if (!locCurrTarget.currentAction)
- continue;
- locCurrTarget.currentActionSalvaged = false;
- locCurrTarget.currentAction.step(dt * ( locCurrTarget.currentAction._speedMethod ? locCurrTarget.currentAction._speed : 1 ) );
- if (locCurrTarget.currentActionSalvaged) {
- locCurrTarget.currentAction = null;//release
- } else if (locCurrTarget.currentAction.isDone()) {
- locCurrTarget.currentAction.stop();
- var action = locCurrTarget.currentAction;
- locCurrTarget.currentAction = null;
- this.removeAction(action);
- }
- locCurrTarget.currentAction = null;
- }
- }
- if (this._currentTargetSalvaged && locCurrTarget.actions.length === 0) {
- this._deleteHashElement(locCurrTarget) && elt--;
- }
- }
- }
- });
- cc.ACTION_TAG_INVALID = -1;
- cc.Action = cc.Class.extend({
- originalTarget:null,
- target:null,
- tag:cc.ACTION_TAG_INVALID,
- ctor:function () {
- this.originalTarget = null;
- this.target = null;
- this.tag = cc.ACTION_TAG_INVALID;
- },
- copy:function () {
- cc.log("copy is deprecated. Please use clone instead.");
- return this.clone();
- },
- clone:function () {
- var action = new cc.Action();
- action.originalTarget = null;
- action.target = null;
- action.tag = this.tag;
- return action;
- },
- isDone:function () {
- return true;
- },
- startWithTarget:function (target) {
- this.originalTarget = target;
- this.target = target;
- },
- stop:function () {
- this.target = null;
- },
- step:function (dt) {
- cc.log("[Action step]. override me");
- },
- update:function (dt) {
- cc.log("[Action update]. override me");
- },
- getTarget:function () {
- return this.target;
- },
- setTarget:function (target) {
- this.target = target;
- },
- getOriginalTarget:function () {
- return this.originalTarget;
- },
- setOriginalTarget:function (originalTarget) {
- this.originalTarget = originalTarget;
- },
- getTag:function () {
- return this.tag;
- },
- setTag:function (tag) {
- this.tag = tag;
- },
- retain:function () {
- },
- release:function () {
- }
- });
- cc.action = function () {
- return new cc.Action();
- };
- cc.Action.create = cc.action;
- cc.FiniteTimeAction = cc.Action.extend({
- _duration:0,
- ctor:function () {
- cc.Action.prototype.ctor.call(this);
- this._duration = 0;
- },
- getDuration:function () {
- return this._duration * (this._timesForRepeat || 1);
- },
- setDuration:function (duration) {
- this._duration = duration;
- },
- reverse:function () {
- cc.log("cocos2d: FiniteTimeAction#reverse: Implement me");
- return null;
- },
- clone:function () {
- return new cc.FiniteTimeAction();
- }
- });
- cc.Speed = cc.Action.extend({
- _speed:0.0,
- _innerAction:null,
- ctor:function (action, speed) {
- cc.Action.prototype.ctor.call(this);
- this._speed = 0;
- this._innerAction = null;
- action && this.initWithAction(action, speed);
- },
- getSpeed:function () {
- return this._speed;
- },
- setSpeed:function (speed) {
- this._speed = speed;
- },
- initWithAction:function (action, speed) {
- if(!action)
- throw new Error("cc.Speed.initWithAction(): action must be non nil");
- this._innerAction = action;
- this._speed = speed;
- return true;
- },
- clone:function () {
- var action = new cc.Speed();
- action.initWithAction(this._innerAction.clone(), this._speed);
- return action;
- },
- startWithTarget:function (target) {
- cc.Action.prototype.startWithTarget.call(this, target);
- this._innerAction.startWithTarget(target);
- },
- stop:function () {
- this._innerAction.stop();
- cc.Action.prototype.stop.call(this);
- },
- step:function (dt) {
- this._innerAction.step(dt * this._speed);
- },
- isDone:function () {
- return this._innerAction.isDone();
- },
- reverse:function () {
- return new cc.Speed(this._innerAction.reverse(), this._speed);
- },
- setInnerAction:function (action) {
- if (this._innerAction !== action) {
- this._innerAction = action;
- }
- },
- getInnerAction:function () {
- return this._innerAction;
- }
- });
- cc.speed = function (action, speed) {
- return new cc.Speed(action, speed);
- };
- cc.Speed.create = cc.speed;
- cc.Follow = cc.Action.extend({
- _followedNode:null,
- _boundarySet:false,
- _boundaryFullyCovered:false,
- _halfScreenSize:null,
- _fullScreenSize:null,
- _worldRect:null,
- leftBoundary:0.0,
- rightBoundary:0.0,
- topBoundary:0.0,
- bottomBoundary:0.0,
- ctor:function (followedNode, rect) {
- cc.Action.prototype.ctor.call(this);
- this._followedNode = null;
- this._boundarySet = false;
- this._boundaryFullyCovered = false;
- this._halfScreenSize = null;
- this._fullScreenSize = null;
- this.leftBoundary = 0.0;
- this.rightBoundary = 0.0;
- this.topBoundary = 0.0;
- this.bottomBoundary = 0.0;
- this._worldRect = cc.rect(0, 0, 0, 0);
- if(followedNode)
- rect ? this.initWithTarget(followedNode, rect)
- : this.initWithTarget(followedNode);
- },
- clone:function () {
- var action = new cc.Follow();
- var locRect = this._worldRect;
- var rect = new cc.Rect(locRect.x, locRect.y, locRect.width, locRect.height);
- action.initWithTarget(this._followedNode, rect);
- return action;
- },
- isBoundarySet:function () {
- return this._boundarySet;
- },
- setBoudarySet:function (value) {
- this._boundarySet = value;
- },
- initWithTarget:function (followedNode, rect) {
- if(!followedNode)
- throw new Error("cc.Follow.initWithAction(): followedNode must be non nil");
- var _this = this;
- rect = rect || cc.rect(0, 0, 0, 0);
- _this._followedNode = followedNode;
- _this._worldRect = rect;
- _this._boundarySet = !cc._rectEqualToZero(rect);
- _this._boundaryFullyCovered = false;
- var winSize = cc.director.getWinSize();
- _this._fullScreenSize = cc.p(winSize.width, winSize.height);
- _this._halfScreenSize = cc.pMult(_this._fullScreenSize, 0.5);
- if (_this._boundarySet) {
- _this.leftBoundary = -((rect.x + rect.width) - _this._fullScreenSize.x);
- _this.rightBoundary = -rect.x;
- _this.topBoundary = -rect.y;
- _this.bottomBoundary = -((rect.y + rect.height) - _this._fullScreenSize.y);
- if (_this.rightBoundary < _this.leftBoundary) {
- _this.rightBoundary = _this.leftBoundary = (_this.leftBoundary + _this.rightBoundary) / 2;
- }
- if (_this.topBoundary < _this.bottomBoundary) {
- _this.topBoundary = _this.bottomBoundary = (_this.topBoundary + _this.bottomBoundary) / 2;
- }
- if ((_this.topBoundary === _this.bottomBoundary) && (_this.leftBoundary === _this.rightBoundary))
- _this._boundaryFullyCovered = true;
- }
- return true;
- },
- step:function (dt) {
- var tempPosX = this._followedNode.x;
- var tempPosY = this._followedNode.y;
- tempPosX = this._halfScreenSize.x - tempPosX;
- tempPosY = this._halfScreenSize.y - tempPosY;
- this.target._renderCmd._dirtyFlag = 0;
- if (this._boundarySet) {
- if (this._boundaryFullyCovered)
- return;
- this.target.setPosition(cc.clampf(tempPosX, this.leftBoundary, this.rightBoundary), cc.clampf(tempPosY, this.bottomBoundary, this.topBoundary));
- } else {
- this.target.setPosition(tempPosX, tempPosY);
- }
- },
- isDone:function () {
- return ( !this._followedNode.running );
- },
- stop:function () {
- this.target = null;
- cc.Action.prototype.stop.call(this);
- }
- });
- cc.follow = function (followedNode, rect) {
- return new cc.Follow(followedNode, rect);
- };
- cc.Follow.create = cc.follow;
- cc.ActionInterval = cc.FiniteTimeAction.extend({
- _elapsed:0,
- _firstTick:false,
- _easeList: null,
- _timesForRepeat:1,
- _repeatForever: false,
- _repeatMethod: false,//Compatible with repeat class, Discard after can be deleted
- _speed: 1,
- _speedMethod: false,//Compatible with speed class, Discard after can be deleted
- ctor:function (d) {
- this._speed = 1;
- this._timesForRepeat = 1;
- this._repeatForever = false;
- this.MAX_VALUE = 2;
- this._repeatMethod = false;//Compatible with repeat class, Discard after can be deleted
- this._speedMethod = false;//Compatible with repeat class, Discard after can be deleted
- cc.FiniteTimeAction.prototype.ctor.call(this);
- d !== undefined && this.initWithDuration(d);
- },
- getElapsed:function () {
- return this._elapsed;
- },
- initWithDuration:function (d) {
- this._duration = (d === 0) ? cc.FLT_EPSILON : d;
- this._elapsed = 0;
- this._firstTick = true;
- return true;
- },
- isDone:function () {
- return (this._elapsed >= this._duration);
- },
- _cloneDecoration: function(action){
- action._repeatForever = this._repeatForever;
- action._speed = this._speed;
- action._timesForRepeat = this._timesForRepeat;
- action._easeList = this._easeList;
- action._speedMethod = this._speedMethod;
- action._repeatMethod = this._repeatMethod;
- },
- _reverseEaseList: function(action){
- if(this._easeList){
- action._easeList = [];
- for(var i=0; i<this._easeList.length; i++){
- action._easeList.push(this._easeList[i].reverse());
- }
- }
- },
- clone:function () {
- var action = new cc.ActionInterval(this._duration);
- this._cloneDecoration(action);
- return action;
- },
- easing: function (easeObj) {
- if (this._easeList)
- this._easeList.length = 0;
- else
- this._easeList = [];
- for (var i = 0; i < arguments.length; i++)
- this._easeList.push(arguments[i]);
- return this;
- },
- _computeEaseTime: function (dt) {
- var locList = this._easeList;
- if ((!locList) || (locList.length === 0))
- return dt;
- for (var i = 0, n = locList.length; i < n; i++)
- dt = locList[i].easing(dt);
- return dt;
- },
- step:function (dt) {
- if (this._firstTick) {
- this._firstTick = false;
- this._elapsed = 0;
- } else
- this._elapsed += dt;
- var t = this._elapsed / (this._duration > 0.0000001192092896 ? this._duration : 0.0000001192092896);
- t = (1 > t ? t : 1);
- this.update(t > 0 ? t : 0);
- if(this._repeatMethod && this._timesForRepeat > 1 && this.isDone()){
- if(!this._repeatForever){
- this._timesForRepeat--;
- }
- this.startWithTarget(this.target);
- this.step(this._elapsed - this._duration);
- }
- },
- startWithTarget:function (target) {
- cc.Action.prototype.startWithTarget.call(this, target);
- this._elapsed = 0;
- this._firstTick = true;
- },
- reverse:function () {
- cc.log("cc.IntervalAction: reverse not implemented.");
- return null;
- },
- setAmplitudeRate:function (amp) {
- cc.log("cc.ActionInterval.setAmplitudeRate(): it should be overridden in subclass.");
- },
- getAmplitudeRate:function () {
- cc.log("cc.ActionInterval.getAmplitudeRate(): it should be overridden in subclass.");
- return 0;
- },
- speed: function(speed){
- if(speed <= 0){
- cc.log("The speed parameter error");
- return this;
- }
- this._speedMethod = true;//Compatible with repeat class, Discard after can be deleted
- this._speed *= speed;
- return this;
- },
- getSpeed: function(){
- return this._speed;
- },
- setSpeed: function(speed){
- this._speed = speed;
- return this;
- },
- repeat: function(times){
- times = Math.round(times);
- if(isNaN(times) || times < 1){
- cc.log("The repeat parameter error");
- return this;
- }
- this._repeatMethod = true;//Compatible with repeat class, Discard after can be deleted
- this._timesForRepeat *= times;
- return this;
- },
- repeatForever: function(){
- this._repeatMethod = true;//Compatible with repeat class, Discard after can be deleted
- this._timesForRepeat = this.MAX_VALUE;
- this._repeatForever = true;
- return this;
- }
- });
- cc.actionInterval = function (d) {
- return new cc.ActionInterval(d);
- };
- cc.ActionInterval.create = cc.actionInterval;
- cc.Sequence = cc.ActionInterval.extend({
- _actions:null,
- _split:null,
- _last:0,
- ctor:function (tempArray) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._actions = [];
- var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
- var last = paramArray.length - 1;
- if ((last >= 0) && (paramArray[last] == null))
- cc.log("parameters should not be ending with null in Javascript");
- if (last >= 0) {
- var prev = paramArray[0], action1;
- for (var i = 1; i < last; i++) {
- if (paramArray[i]) {
- action1 = prev;
- prev = cc.Sequence._actionOneTwo(action1, paramArray[i]);
- }
- }
- this.initWithTwoActions(prev, paramArray[last]);
- }
- },
- initWithTwoActions:function (actionOne, actionTwo) {
- if(!actionOne || !actionTwo)
- throw new Error("cc.Sequence.initWithTwoActions(): arguments must all be non nil");
- var d = actionOne._duration + actionTwo._duration;
- this.initWithDuration(d);
- this._actions[0] = actionOne;
- this._actions[1] = actionTwo;
- return true;
- },
- clone:function () {
- var action = new cc.Sequence();
- this._cloneDecoration(action);
- action.initWithTwoActions(this._actions[0].clone(), this._actions[1].clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._split = this._actions[0]._duration / this._duration;
- this._last = -1;
- },
- stop:function () {
- if (this._last !== -1)
- this._actions[this._last].stop();
- cc.Action.prototype.stop.call(this);
- },
- update:function (dt) {
- var new_t, found = 0;
- var locSplit = this._split, locActions = this._actions, locLast = this._last, actionFound;
- dt = this._computeEaseTime(dt);
- if (dt < locSplit) {
- new_t = (locSplit !== 0) ? dt / locSplit : 1;
- if (found === 0 && locLast === 1) {
- locActions[1].update(0);
- locActions[1].stop();
- }
- } else {
- found = 1;
- new_t = (locSplit === 1) ? 1 : (dt - locSplit) / (1 - locSplit);
- if (locLast === -1) {
- locActions[0].startWithTarget(this.target);
- locActions[0].update(1);
- locActions[0].stop();
- }
- if (!locLast) {
- locActions[0].update(1);
- locActions[0].stop();
- }
- }
- actionFound = locActions[found];
- if (locLast === found && actionFound.isDone())
- return;
- if (locLast !== found)
- actionFound.startWithTarget(this.target);
- new_t = new_t * actionFound._timesForRepeat;
- actionFound.update(new_t > 1 ? new_t % 1 : new_t);
- this._last = found;
- },
- reverse:function () {
- var action = cc.Sequence._actionOneTwo(this._actions[1].reverse(), this._actions[0].reverse());
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.sequence = function (tempArray) {
- var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
- if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var result, current, i, repeat;
- while(paramArray && paramArray.length > 0){
- current = Array.prototype.shift.call(paramArray);
- repeat = current._timesForRepeat || 1;
- current._repeatMethod = false;
- current._timesForRepeat = 1;
- i = 0;
- if(!result){
- result = current;
- i = 1;
- }
- for(i; i<repeat; i++){
- result = cc.Sequence._actionOneTwo(result, current);
- }
- }
- return result;
- };
- cc.Sequence.create = cc.sequence;
- cc.Sequence._actionOneTwo = function (actionOne, actionTwo) {
- var sequence = new cc.Sequence();
- sequence.initWithTwoActions(actionOne, actionTwo);
- return sequence;
- };
- cc.Repeat = cc.ActionInterval.extend({
- _times:0,
- _total:0,
- _nextDt:0,
- _actionInstant:false,
- _innerAction:null,
- ctor: function (action, times) {
- cc.ActionInterval.prototype.ctor.call(this);
- times !== undefined && this.initWithAction(action, times);
- },
- initWithAction:function (action, times) {
- var duration = action._duration * times;
- if (this.initWithDuration(duration)) {
- this._times = times;
- this._innerAction = action;
- if (action instanceof cc.ActionInstant){
- this._actionInstant = true;
- this._times -= 1;
- }
- this._total = 0;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.Repeat();
- this._cloneDecoration(action);
- action.initWithAction(this._innerAction.clone(), this._times);
- return action;
- },
- startWithTarget:function (target) {
- this._total = 0;
- this._nextDt = this._innerAction._duration / this._duration;
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._innerAction.startWithTarget(target);
- },
- stop:function () {
- this._innerAction.stop();
- cc.Action.prototype.stop.call(this);
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- var locInnerAction = this._innerAction;
- var locDuration = this._duration;
- var locTimes = this._times;
- var locNextDt = this._nextDt;
- if (dt >= locNextDt) {
- while (dt > locNextDt && this._total < locTimes) {
- locInnerAction.update(1);
- this._total++;
- locInnerAction.stop();
- locInnerAction.startWithTarget(this.target);
- locNextDt += locInnerAction._duration / locDuration;
- this._nextDt = locNextDt;
- }
- if (dt >= 1.0 && this._total < locTimes)
- this._total++;
- if (!this._actionInstant) {
- if (this._total === locTimes) {
- locInnerAction.update(1);
- locInnerAction.stop();
- } else {
- locInnerAction.update(dt - (locNextDt - locInnerAction._duration / locDuration));
- }
- }
- } else {
- locInnerAction.update((dt * locTimes) % 1.0);
- }
- },
- isDone:function () {
- return this._total === this._times;
- },
- reverse:function () {
- var action = new cc.Repeat(this._innerAction.reverse(), this._times);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- setInnerAction:function (action) {
- if (this._innerAction !== action) {
- this._innerAction = action;
- }
- },
- getInnerAction:function () {
- return this._innerAction;
- }
- });
- cc.repeat = function (action, times) {
- return new cc.Repeat(action, times);
- };
- cc.Repeat.create = cc.repeat;
- cc.RepeatForever = cc.ActionInterval.extend({
- _innerAction:null,
- ctor:function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._innerAction = null;
- action && this.initWithAction(action);
- },
- initWithAction:function (action) {
- if(!action)
- throw new Error("cc.RepeatForever.initWithAction(): action must be non null");
- this._innerAction = action;
- return true;
- },
- clone:function () {
- var action = new cc.RepeatForever();
- this._cloneDecoration(action);
- action.initWithAction(this._innerAction.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._innerAction.startWithTarget(target);
- },
- step:function (dt) {
- var locInnerAction = this._innerAction;
- locInnerAction.step(dt);
- if (locInnerAction.isDone()) {
- locInnerAction.startWithTarget(this.target);
- locInnerAction.step(locInnerAction.getElapsed() - locInnerAction._duration);
- }
- },
- isDone:function () {
- return false;
- },
- reverse:function () {
- var action = new cc.RepeatForever(this._innerAction.reverse());
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- setInnerAction:function (action) {
- if (this._innerAction !== action) {
- this._innerAction = action;
- }
- },
- getInnerAction:function () {
- return this._innerAction;
- }
- });
- cc.repeatForever = function (action) {
- return new cc.RepeatForever(action);
- };
- cc.RepeatForever.create = cc.repeatForever;
- cc.Spawn = cc.ActionInterval.extend({
- _one:null,
- _two:null,
- ctor:function (tempArray) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._one = null;
- this._two = null;
- var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
- var last = paramArray.length - 1;
- if ((last >= 0) && (paramArray[last] == null))
- cc.log("parameters should not be ending with null in Javascript");
- if (last >= 0) {
- var prev = paramArray[0], action1;
- for (var i = 1; i < last; i++) {
- if (paramArray[i]) {
- action1 = prev;
- prev = cc.Spawn._actionOneTwo(action1, paramArray[i]);
- }
- }
- this.initWithTwoActions(prev, paramArray[last]);
- }
- },
- initWithTwoActions:function (action1, action2) {
- if(!action1 || !action2)
- throw new Error("cc.Spawn.initWithTwoActions(): arguments must all be non null");
- var ret = false;
- var d1 = action1._duration;
- var d2 = action2._duration;
- if (this.initWithDuration(Math.max(d1, d2))) {
- this._one = action1;
- this._two = action2;
- if (d1 > d2) {
- this._two = cc.Sequence._actionOneTwo(action2, cc.delayTime(d1 - d2));
- } else if (d1 < d2) {
- this._one = cc.Sequence._actionOneTwo(action1, cc.delayTime(d2 - d1));
- }
- ret = true;
- }
- return ret;
- },
- clone:function () {
- var action = new cc.Spawn();
- this._cloneDecoration(action);
- action.initWithTwoActions(this._one.clone(), this._two.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._one.startWithTarget(target);
- this._two.startWithTarget(target);
- },
- stop:function () {
- this._one.stop();
- this._two.stop();
- cc.Action.prototype.stop.call(this);
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this._one)
- this._one.update(dt);
- if (this._two)
- this._two.update(dt);
- },
- reverse:function () {
- var action = cc.Spawn._actionOneTwo(this._one.reverse(), this._two.reverse());
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.spawn = function (tempArray) {
- var paramArray = (tempArray instanceof Array) ? tempArray : arguments;
- if ((paramArray.length > 0) && (paramArray[paramArray.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var prev = paramArray[0];
- for (var i = 1; i < paramArray.length; i++) {
- if (paramArray[i] != null)
- prev = cc.Spawn._actionOneTwo(prev, paramArray[i]);
- }
- return prev;
- };
- cc.Spawn.create = cc.spawn;
- cc.Spawn._actionOneTwo = function (action1, action2) {
- var pSpawn = new cc.Spawn();
- pSpawn.initWithTwoActions(action1, action2);
- return pSpawn;
- };
- cc.RotateTo = cc.ActionInterval.extend({
- _dstAngleX:0,
- _startAngleX:0,
- _diffAngleX:0,
- _dstAngleY:0,
- _startAngleY:0,
- _diffAngleY:0,
- ctor:function (duration, deltaAngleX, deltaAngleY) {
- cc.ActionInterval.prototype.ctor.call(this);
- deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
- },
- initWithDuration:function (duration, deltaAngleX, deltaAngleY) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._dstAngleX = deltaAngleX || 0;
- this._dstAngleY = deltaAngleY || this._dstAngleX;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.RotateTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._dstAngleX, this._dstAngleY);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- var locStartAngleX = target.rotationX % 360.0;
- var locDiffAngleX = this._dstAngleX - locStartAngleX;
- if (locDiffAngleX > 180)
- locDiffAngleX -= 360;
- if (locDiffAngleX < -180)
- locDiffAngleX += 360;
- this._startAngleX = locStartAngleX;
- this._diffAngleX = locDiffAngleX;
- this._startAngleY = target.rotationY % 360.0;
- var locDiffAngleY = this._dstAngleY - this._startAngleY;
- if (locDiffAngleY > 180)
- locDiffAngleY -= 360;
- if (locDiffAngleY < -180)
- locDiffAngleY += 360;
- this._diffAngleY = locDiffAngleY;
- },
- reverse:function () {
- cc.log("cc.RotateTo.reverse(): it should be overridden in subclass.");
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- this.target.rotationX = this._startAngleX + this._diffAngleX * dt;
- this.target.rotationY = this._startAngleY + this._diffAngleY * dt;
- }
- }
- });
- cc.rotateTo = function (duration, deltaAngleX, deltaAngleY) {
- return new cc.RotateTo(duration, deltaAngleX, deltaAngleY);
- };
- cc.RotateTo.create = cc.rotateTo;
- cc.RotateBy = cc.ActionInterval.extend({
- _angleX:0,
- _startAngleX:0,
- _angleY:0,
- _startAngleY:0,
- ctor: function (duration, deltaAngleX, deltaAngleY) {
- cc.ActionInterval.prototype.ctor.call(this);
- deltaAngleX !== undefined && this.initWithDuration(duration, deltaAngleX, deltaAngleY);
- },
- initWithDuration:function (duration, deltaAngleX, deltaAngleY) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._angleX = deltaAngleX || 0;
- this._angleY = deltaAngleY || this._angleX;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.RotateBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._angleX, this._angleY);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._startAngleX = target.rotationX;
- this._startAngleY = target.rotationY;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- this.target.rotationX = this._startAngleX + this._angleX * dt;
- this.target.rotationY = this._startAngleY + this._angleY * dt;
- }
- },
- reverse:function () {
- var action = new cc.RotateBy(this._duration, -this._angleX, -this._angleY);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.rotateBy = function (duration, deltaAngleX, deltaAngleY) {
- return new cc.RotateBy(duration, deltaAngleX, deltaAngleY);
- };
- cc.RotateBy.create = cc.rotateBy;
- cc.MoveBy = cc.ActionInterval.extend({
- _positionDelta:null,
- _startPosition:null,
- _previousPosition:null,
- ctor:function (duration, deltaPos, deltaY) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._positionDelta = cc.p(0, 0);
- this._startPosition = cc.p(0, 0);
- this._previousPosition = cc.p(0, 0);
- deltaPos !== undefined && this.initWithDuration(duration, deltaPos, deltaY);
- },
- initWithDuration:function (duration, position, y) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- if(position.x !== undefined) {
- y = position.y;
- position = position.x;
- }
- this._positionDelta.x = position;
- this._positionDelta.y = y;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.MoveBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._positionDelta);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- var locPosX = target.getPositionX();
- var locPosY = target.getPositionY();
- this._previousPosition.x = locPosX;
- this._previousPosition.y = locPosY;
- this._startPosition.x = locPosX;
- this._startPosition.y = locPosY;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- var x = this._positionDelta.x * dt;
- var y = this._positionDelta.y * dt;
- var locStartPosition = this._startPosition;
- if (cc.ENABLE_STACKABLE_ACTIONS) {
- var targetX = this.target.getPositionX();
- var targetY = this.target.getPositionY();
- var locPreviousPosition = this._previousPosition;
- locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
- locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y;
- x = x + locStartPosition.x;
- y = y + locStartPosition.y;
- locPreviousPosition.x = x;
- locPreviousPosition.y = y;
- this.target.setPosition(x, y);
- } else {
- this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y);
- }
- }
- },
- reverse:function () {
- var action = new cc.MoveBy(this._duration, cc.p(-this._positionDelta.x, -this._positionDelta.y));
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.moveBy = function (duration, deltaPos, deltaY) {
- return new cc.MoveBy(duration, deltaPos, deltaY);
- };
- cc.MoveBy.create = cc.moveBy;
- cc.MoveTo = cc.MoveBy.extend({
- _endPosition:null,
- ctor:function (duration, position, y) {
- cc.MoveBy.prototype.ctor.call(this);
- this._endPosition = cc.p(0, 0);
- position !== undefined && this.initWithDuration(duration, position, y);
- },
- initWithDuration:function (duration, position, y) {
- if (cc.MoveBy.prototype.initWithDuration.call(this, duration, position, y)) {
- if(position.x !== undefined) {
- y = position.y;
- position = position.x;
- }
- this._endPosition.x = position;
- this._endPosition.y = y;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.MoveTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._endPosition);
- return action;
- },
- startWithTarget:function (target) {
- cc.MoveBy.prototype.startWithTarget.call(this, target);
- this._positionDelta.x = this._endPosition.x - target.getPositionX();
- this._positionDelta.y = this._endPosition.y - target.getPositionY();
- }
- });
- cc.moveTo = function (duration, position, y) {
- return new cc.MoveTo(duration, position, y);
- };
- cc.MoveTo.create = cc.moveTo;
- cc.SkewTo = cc.ActionInterval.extend({
- _skewX:0,
- _skewY:0,
- _startSkewX:0,
- _startSkewY:0,
- _endSkewX:0,
- _endSkewY:0,
- _deltaX:0,
- _deltaY:0,
- ctor: function (t, sx, sy) {
- cc.ActionInterval.prototype.ctor.call(this);
- sy !== undefined && this.initWithDuration(t, sx, sy);
- },
- initWithDuration:function (t, sx, sy) {
- var ret = false;
- if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) {
- this._endSkewX = sx;
- this._endSkewY = sy;
- ret = true;
- }
- return ret;
- },
- clone:function () {
- var action = new cc.SkewTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._endSkewX, this._endSkewY);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._startSkewX = target.skewX % 180;
- this._deltaX = this._endSkewX - this._startSkewX;
- if (this._deltaX > 180)
- this._deltaX -= 360;
- if (this._deltaX < -180)
- this._deltaX += 360;
- this._startSkewY = target.skewY % 360;
- this._deltaY = this._endSkewY - this._startSkewY;
- if (this._deltaY > 180)
- this._deltaY -= 360;
- if (this._deltaY < -180)
- this._deltaY += 360;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- this.target.skewX = this._startSkewX + this._deltaX * dt;
- this.target.skewY = this._startSkewY + this._deltaY * dt;
- }
- });
- cc.skewTo = function (t, sx, sy) {
- return new cc.SkewTo(t, sx, sy);
- };
- cc.SkewTo.create = cc.skewTo;
- cc.SkewBy = cc.SkewTo.extend({
- ctor: function(t, sx, sy) {
- cc.SkewTo.prototype.ctor.call(this);
- sy !== undefined && this.initWithDuration(t, sx, sy);
- },
- initWithDuration:function (t, deltaSkewX, deltaSkewY) {
- var ret = false;
- if (cc.SkewTo.prototype.initWithDuration.call(this, t, deltaSkewX, deltaSkewY)) {
- this._skewX = deltaSkewX;
- this._skewY = deltaSkewY;
- ret = true;
- }
- return ret;
- },
- clone:function () {
- var action = new cc.SkewBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._skewX, this._skewY);
- return action;
- },
- startWithTarget:function (target) {
- cc.SkewTo.prototype.startWithTarget.call(this, target);
- this._deltaX = this._skewX;
- this._deltaY = this._skewY;
- this._endSkewX = this._startSkewX + this._deltaX;
- this._endSkewY = this._startSkewY + this._deltaY;
- },
- reverse:function () {
- var action = new cc.SkewBy(this._duration, -this._skewX, -this._skewY);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.skewBy = function (t, sx, sy) {
- return new cc.SkewBy(t, sx, sy);
- };
- cc.SkewBy.create = cc.skewBy;
- cc.JumpBy = cc.ActionInterval.extend({
- _startPosition:null,
- _delta:null,
- _height:0,
- _jumps:0,
- _previousPosition:null,
- ctor:function (duration, position, y, height, jumps) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._startPosition = cc.p(0, 0);
- this._previousPosition = cc.p(0, 0);
- this._delta = cc.p(0, 0);
- height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
- },
- initWithDuration:function (duration, position, y, height, jumps) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- if (jumps === undefined) {
- jumps = height;
- height = y;
- y = position.y;
- position = position.x;
- }
- this._delta.x = position;
- this._delta.y = y;
- this._height = height;
- this._jumps = jumps;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.JumpBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._delta, this._height, this._jumps);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- var locPosX = target.getPositionX();
- var locPosY = target.getPositionY();
- this._previousPosition.x = locPosX;
- this._previousPosition.y = locPosY;
- this._startPosition.x = locPosX;
- this._startPosition.y = locPosY;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- var frac = dt * this._jumps % 1.0;
- var y = this._height * 4 * frac * (1 - frac);
- y += this._delta.y * dt;
- var x = this._delta.x * dt;
- var locStartPosition = this._startPosition;
- if (cc.ENABLE_STACKABLE_ACTIONS) {
- var targetX = this.target.getPositionX();
- var targetY = this.target.getPositionY();
- var locPreviousPosition = this._previousPosition;
- locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
- locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y;
- x = x + locStartPosition.x;
- y = y + locStartPosition.y;
- locPreviousPosition.x = x;
- locPreviousPosition.y = y;
- this.target.setPosition(x, y);
- } else {
- this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y);
- }
- }
- },
- reverse:function () {
- var action = new cc.JumpBy(this._duration, cc.p(-this._delta.x, -this._delta.y), this._height, this._jumps);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.jumpBy = function (duration, position, y, height, jumps) {
- return new cc.JumpBy(duration, position, y, height, jumps);
- };
- cc.JumpBy.create = cc.jumpBy;
- cc.JumpTo = cc.JumpBy.extend({
- _endPosition:null,
- ctor:function (duration, position, y, height, jumps) {
- cc.JumpBy.prototype.ctor.call(this);
- this._endPosition = cc.p(0, 0);
- height !== undefined && this.initWithDuration(duration, position, y, height, jumps);
- },
- initWithDuration:function (duration, position, y, height, jumps) {
- if (cc.JumpBy.prototype.initWithDuration.call(this, duration, position, y, height, jumps)) {
- if (jumps === undefined) {
- y = position.y;
- position = position.x;
- }
- this._endPosition.x = position;
- this._endPosition.y = y;
- return true;
- }
- return false;
- },
- startWithTarget:function (target) {
- cc.JumpBy.prototype.startWithTarget.call(this, target);
- this._delta.x = this._endPosition.x - this._startPosition.x;
- this._delta.y = this._endPosition.y - this._startPosition.y;
- },
- clone:function () {
- var action = new cc.JumpTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._endPosition, this._height, this._jumps);
- return action;
- }
- });
- cc.jumpTo = function (duration, position, y, height, jumps) {
- return new cc.JumpTo(duration, position, y, height, jumps);
- };
- cc.JumpTo.create = cc.jumpTo;
- cc.bezierAt = function (a, b, c, d, t) {
- return (Math.pow(1 - t, 3) * a +
- 3 * t * (Math.pow(1 - t, 2)) * b +
- 3 * Math.pow(t, 2) * (1 - t) * c +
- Math.pow(t, 3) * d );
- };
- cc.BezierBy = cc.ActionInterval.extend({
- _config:null,
- _startPosition:null,
- _previousPosition:null,
- ctor:function (t, c) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._config = [];
- this._startPosition = cc.p(0, 0);
- this._previousPosition = cc.p(0, 0);
- c && this.initWithDuration(t, c);
- },
- initWithDuration:function (t, c) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) {
- this._config = c;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.BezierBy();
- this._cloneDecoration(action);
- var newConfigs = [];
- for (var i = 0; i < this._config.length; i++) {
- var selConf = this._config[i];
- newConfigs.push(cc.p(selConf.x, selConf.y));
- }
- action.initWithDuration(this._duration, newConfigs);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- var locPosX = target.getPositionX();
- var locPosY = target.getPositionY();
- this._previousPosition.x = locPosX;
- this._previousPosition.y = locPosY;
- this._startPosition.x = locPosX;
- this._startPosition.y = locPosY;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- var locConfig = this._config;
- var xa = 0;
- var xb = locConfig[0].x;
- var xc = locConfig[1].x;
- var xd = locConfig[2].x;
- var ya = 0;
- var yb = locConfig[0].y;
- var yc = locConfig[1].y;
- var yd = locConfig[2].y;
- var x = cc.bezierAt(xa, xb, xc, xd, dt);
- var y = cc.bezierAt(ya, yb, yc, yd, dt);
- var locStartPosition = this._startPosition;
- if (cc.ENABLE_STACKABLE_ACTIONS) {
- var targetX = this.target.getPositionX();
- var targetY = this.target.getPositionY();
- var locPreviousPosition = this._previousPosition;
- locStartPosition.x = locStartPosition.x + targetX - locPreviousPosition.x;
- locStartPosition.y = locStartPosition.y + targetY - locPreviousPosition.y;
- x = x + locStartPosition.x;
- y = y + locStartPosition.y;
- locPreviousPosition.x = x;
- locPreviousPosition.y = y;
- this.target.setPosition(x, y);
- } else {
- this.target.setPosition(locStartPosition.x + x, locStartPosition.y + y);
- }
- }
- },
- reverse:function () {
- var locConfig = this._config;
- var r = [
- cc.pAdd(locConfig[1], cc.pNeg(locConfig[2])),
- cc.pAdd(locConfig[0], cc.pNeg(locConfig[2])),
- cc.pNeg(locConfig[2]) ];
- var action = new cc.BezierBy(this._duration, r);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.bezierBy = function (t, c) {
- return new cc.BezierBy(t, c);
- };
- cc.BezierBy.create = cc.bezierBy;
- cc.BezierTo = cc.BezierBy.extend({
- _toConfig:null,
- ctor:function (t, c) {
- cc.BezierBy.prototype.ctor.call(this);
- this._toConfig = [];
- c && this.initWithDuration(t, c);
- },
- initWithDuration:function (t, c) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, t)) {
- this._toConfig = c;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.BezierTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._toConfig);
- return action;
- },
- startWithTarget:function (target) {
- cc.BezierBy.prototype.startWithTarget.call(this, target);
- var locStartPos = this._startPosition;
- var locToConfig = this._toConfig;
- var locConfig = this._config;
- locConfig[0] = cc.pSub(locToConfig[0], locStartPos);
- locConfig[1] = cc.pSub(locToConfig[1], locStartPos);
- locConfig[2] = cc.pSub(locToConfig[2], locStartPos);
- }
- });
- cc.bezierTo = function (t, c) {
- return new cc.BezierTo(t, c);
- };
- cc.BezierTo.create = cc.bezierTo;
- cc.ScaleTo = cc.ActionInterval.extend({
- _scaleX:1,
- _scaleY:1,
- _startScaleX:1,
- _startScaleY:1,
- _endScaleX:0,
- _endScaleY:0,
- _deltaX:0,
- _deltaY:0,
- ctor:function (duration, sx, sy) {
- cc.ActionInterval.prototype.ctor.call(this);
- sx !== undefined && this.initWithDuration(duration, sx, sy);
- },
- initWithDuration:function (duration, sx, sy) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._endScaleX = sx;
- this._endScaleY = (sy != null) ? sy : sx;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.ScaleTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._endScaleX, this._endScaleY);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._startScaleX = target.scaleX;
- this._startScaleY = target.scaleY;
- this._deltaX = this._endScaleX - this._startScaleX;
- this._deltaY = this._endScaleY - this._startScaleY;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target) {
- this.target.scaleX = this._startScaleX + this._deltaX * dt;
- this.target.scaleY = this._startScaleY + this._deltaY * dt;
- }
- }
- });
- cc.scaleTo = function (duration, sx, sy) {
- return new cc.ScaleTo(duration, sx, sy);
- };
- cc.ScaleTo.create = cc.scaleTo;
- cc.ScaleBy = cc.ScaleTo.extend({
- startWithTarget:function (target) {
- cc.ScaleTo.prototype.startWithTarget.call(this, target);
- this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX;
- this._deltaY = this._startScaleY * this._endScaleY - this._startScaleY;
- },
- reverse:function () {
- var action = new cc.ScaleBy(this._duration, 1 / this._endScaleX, 1 / this._endScaleY);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- clone:function () {
- var action = new cc.ScaleBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._endScaleX, this._endScaleY);
- return action;
- }
- });
- cc.scaleBy = function (duration, sx, sy) {
- return new cc.ScaleBy(duration, sx, sy);
- };
- cc.ScaleBy.create = cc.scaleBy;
- cc.Blink = cc.ActionInterval.extend({
- _times:0,
- _originalState:false,
- ctor:function (duration, blinks) {
- cc.ActionInterval.prototype.ctor.call(this);
- blinks !== undefined && this.initWithDuration(duration, blinks);
- },
- initWithDuration:function (duration, blinks) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._times = blinks;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.Blink();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._times);
- return action;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this.target && !this.isDone()) {
- var slice = 1.0 / this._times;
- var m = dt % slice;
- this.target.visible = (m > (slice / 2));
- }
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._originalState = target.visible;
- },
- stop:function () {
- this.target.visible = this._originalState;
- cc.ActionInterval.prototype.stop.call(this);
- },
- reverse:function () {
- var action = new cc.Blink(this._duration, this._times);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.blink = function (duration, blinks) {
- return new cc.Blink(duration, blinks);
- };
- cc.Blink.create = cc.blink;
- cc.FadeTo = cc.ActionInterval.extend({
- _toOpacity:0,
- _fromOpacity:0,
- ctor:function (duration, opacity) {
- cc.ActionInterval.prototype.ctor.call(this);
- opacity !== undefined && this.initWithDuration(duration, opacity);
- },
- initWithDuration:function (duration, opacity) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._toOpacity = opacity;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.FadeTo();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._toOpacity);
- return action;
- },
- update:function (time) {
- time = this._computeEaseTime(time);
- var fromOpacity = this._fromOpacity !== undefined ? this._fromOpacity : 255;
- this.target.opacity = fromOpacity + (this._toOpacity - fromOpacity) * time;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._fromOpacity = target.opacity;
- }
- });
- cc.fadeTo = function (duration, opacity) {
- return new cc.FadeTo(duration, opacity);
- };
- cc.FadeTo.create = cc.fadeTo;
- cc.FadeIn = cc.FadeTo.extend({
- _reverseAction: null,
- ctor:function (duration) {
- cc.FadeTo.prototype.ctor.call(this);
- if (duration == null)
- duration = 0;
- this.initWithDuration(duration, 255);
- },
- reverse:function () {
- var action = new cc.FadeOut();
- action.initWithDuration(this._duration, 0);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- clone:function () {
- var action = new cc.FadeIn();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._toOpacity);
- return action;
- },
- startWithTarget:function (target) {
- if(this._reverseAction)
- this._toOpacity = this._reverseAction._fromOpacity;
- cc.FadeTo.prototype.startWithTarget.call(this, target);
- }
- });
- cc.fadeIn = function (duration) {
- return new cc.FadeIn(duration);
- };
- cc.FadeIn.create = cc.fadeIn;
- cc.FadeOut = cc.FadeTo.extend({
- ctor:function (duration) {
- cc.FadeTo.prototype.ctor.call(this);
- if (duration == null)
- duration = 0;
- this.initWithDuration(duration, 0);
- },
- reverse:function () {
- var action = new cc.FadeIn();
- action._reverseAction = this;
- action.initWithDuration(this._duration, 255);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- clone:function () {
- var action = new cc.FadeOut();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._toOpacity);
- return action;
- }
- });
- cc.fadeOut = function (d) {
- return new cc.FadeOut(d);
- };
- cc.FadeOut.create = cc.fadeOut;
- cc.TintTo = cc.ActionInterval.extend({
- _to:null,
- _from:null,
- ctor:function (duration, red, green, blue) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._to = cc.color(0, 0, 0);
- this._from = cc.color(0, 0, 0);
- blue !== undefined && this.initWithDuration(duration, red, green, blue);
- },
- initWithDuration:function (duration, red, green, blue) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._to = cc.color(red, green, blue);
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.TintTo();
- this._cloneDecoration(action);
- var locTo = this._to;
- action.initWithDuration(this._duration, locTo.r, locTo.g, locTo.b);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._from = this.target.color;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- var locFrom = this._from, locTo = this._to;
- if (locFrom) {
- this.target.setColor(
- cc.color(
- locFrom.r + (locTo.r - locFrom.r) * dt,
- locFrom.g + (locTo.g - locFrom.g) * dt,
- locFrom.b + (locTo.b - locFrom.b) * dt)
- );
- }
- }
- });
- cc.tintTo = function (duration, red, green, blue) {
- return new cc.TintTo(duration, red, green, blue);
- };
- cc.TintTo.create = cc.tintTo;
- cc.TintBy = cc.ActionInterval.extend({
- _deltaR:0,
- _deltaG:0,
- _deltaB:0,
- _fromR:0,
- _fromG:0,
- _fromB:0,
- ctor:function (duration, deltaRed, deltaGreen, deltaBlue) {
- cc.ActionInterval.prototype.ctor.call(this);
- deltaBlue !== undefined && this.initWithDuration(duration, deltaRed, deltaGreen, deltaBlue);
- },
- initWithDuration:function (duration, deltaRed, deltaGreen, deltaBlue) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this._deltaR = deltaRed;
- this._deltaG = deltaGreen;
- this._deltaB = deltaBlue;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.TintBy();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration, this._deltaR, this._deltaG, this._deltaB);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- var color = target.color;
- this._fromR = color.r;
- this._fromG = color.g;
- this._fromB = color.b;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- this.target.color = cc.color(this._fromR + this._deltaR * dt,
- this._fromG + this._deltaG * dt,
- this._fromB + this._deltaB * dt);
- },
- reverse:function () {
- var action = new cc.TintBy(this._duration, -this._deltaR, -this._deltaG, -this._deltaB);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- }
- });
- cc.tintBy = function (duration, deltaRed, deltaGreen, deltaBlue) {
- return new cc.TintBy(duration, deltaRed, deltaGreen, deltaBlue);
- };
- cc.TintBy.create = cc.tintBy;
- cc.DelayTime = cc.ActionInterval.extend({
- update:function (dt) {},
- reverse:function () {
- var action = new cc.DelayTime(this._duration);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- clone:function () {
- var action = new cc.DelayTime();
- this._cloneDecoration(action);
- action.initWithDuration(this._duration);
- return action;
- }
- });
- cc.delayTime = function (d) {
- return new cc.DelayTime(d);
- };
- cc.DelayTime.create = cc.delayTime;
- cc.ReverseTime = cc.ActionInterval.extend({
- _other:null,
- ctor:function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._other = null;
- action && this.initWithAction(action);
- },
- initWithAction:function (action) {
- if(!action)
- throw new Error("cc.ReverseTime.initWithAction(): action must be non null");
- if(action === this._other)
- throw new Error("cc.ReverseTime.initWithAction(): the action was already passed in.");
- if (cc.ActionInterval.prototype.initWithDuration.call(this, action._duration)) {
- this._other = action;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.ReverseTime();
- this._cloneDecoration(action);
- action.initWithAction(this._other.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._other.startWithTarget(target);
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (this._other)
- this._other.update(1 - dt);
- },
- reverse:function () {
- return this._other.clone();
- },
- stop:function () {
- this._other.stop();
- cc.Action.prototype.stop.call(this);
- }
- });
- cc.reverseTime = function (action) {
- return new cc.ReverseTime(action);
- };
- cc.ReverseTime.create = cc.reverseTime;
- cc.Animate = cc.ActionInterval.extend({
- _animation:null,
- _nextFrame:0,
- _origFrame:null,
- _executedLoops:0,
- _splitTimes: null,
- _currFrameIndex:0,
- ctor:function (animation) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._splitTimes = [];
- animation && this.initWithAnimation(animation);
- },
- getAnimation:function () {
- return this._animation;
- },
- setAnimation:function (animation) {
- this._animation = animation;
- },
- getCurrentFrameIndex: function () {
- return this._currFrameIndex;
- },
- initWithAnimation:function (animation) {
- if(!animation)
- throw new Error("cc.Animate.initWithAnimation(): animation must be non-NULL");
- var singleDuration = animation.getDuration();
- if (this.initWithDuration(singleDuration * animation.getLoops())) {
- this._nextFrame = 0;
- this.setAnimation(animation);
- this._origFrame = null;
- this._executedLoops = 0;
- var locTimes = this._splitTimes;
- locTimes.length = 0;
- var accumUnitsOfTime = 0;
- var newUnitOfTimeValue = singleDuration / animation.getTotalDelayUnits();
- var frames = animation.getFrames();
- cc.arrayVerifyType(frames, cc.AnimationFrame);
- for (var i = 0; i < frames.length; i++) {
- var frame = frames[i];
- var value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
- accumUnitsOfTime += frame.getDelayUnits();
- locTimes.push(value);
- }
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.Animate();
- this._cloneDecoration(action);
- action.initWithAnimation(this._animation.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- if (this._animation.getRestoreOriginalFrame())
- this._origFrame = target.displayFrame();
- this._nextFrame = 0;
- this._executedLoops = 0;
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- if (dt < 1.0) {
- dt *= this._animation.getLoops();
- var loopNumber = 0 | dt;
- if (loopNumber > this._executedLoops) {
- this._nextFrame = 0;
- this._executedLoops++;
- }
- dt = dt % 1.0;
- }
- var frames = this._animation.getFrames();
- var numberOfFrames = frames.length, locSplitTimes = this._splitTimes;
- for (var i = this._nextFrame; i < numberOfFrames; i++) {
- if (locSplitTimes[i] <= dt) {
- _currFrameIndex = i;
- this.target.setSpriteFrame(frames[_currFrameIndex].getSpriteFrame());
- this._nextFrame = i + 1;
- } else {
- break;
- }
- }
- },
- reverse:function () {
- var locAnimation = this._animation;
- var oldArray = locAnimation.getFrames();
- var newArray = [];
- cc.arrayVerifyType(oldArray, cc.AnimationFrame);
- if (oldArray.length > 0) {
- for (var i = oldArray.length - 1; i >= 0; i--) {
- var element = oldArray[i];
- if (!element)
- break;
- newArray.push(element.clone());
- }
- }
- var newAnim = new cc.Animation(newArray, locAnimation.getDelayPerUnit(), locAnimation.getLoops());
- newAnim.setRestoreOriginalFrame(locAnimation.getRestoreOriginalFrame());
- var action = new cc.Animate(newAnim);
- this._cloneDecoration(action);
- this._reverseEaseList(action);
- return action;
- },
- stop:function () {
- if (this._animation.getRestoreOriginalFrame() && this.target)
- this.target.setSpriteFrame(this._origFrame);
- cc.Action.prototype.stop.call(this);
- }
- });
- cc.animate = function (animation) {
- return new cc.Animate(animation);
- };
- cc.Animate.create = cc.animate;
- cc.TargetedAction = cc.ActionInterval.extend({
- _action:null,
- _forcedTarget:null,
- ctor: function (target, action) {
- cc.ActionInterval.prototype.ctor.call(this);
- action && this.initWithTarget(target, action);
- },
- initWithTarget:function (target, action) {
- if (this.initWithDuration(action._duration)) {
- this._forcedTarget = target;
- this._action = action;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.TargetedAction();
- this._cloneDecoration(action);
- action.initWithTarget(this._forcedTarget, this._action.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._action.startWithTarget(this._forcedTarget);
- },
- stop:function () {
- this._action.stop();
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- this._action.update(dt);
- },
- getForcedTarget:function () {
- return this._forcedTarget;
- },
- setForcedTarget:function (forcedTarget) {
- if (this._forcedTarget !== forcedTarget)
- this._forcedTarget = forcedTarget;
- }
- });
- cc.targetedAction = function (target, action) {
- return new cc.TargetedAction(target, action);
- };
- cc.TargetedAction.create = cc.targetedAction;
- cc.ActionInstant = cc.FiniteTimeAction.extend({
- isDone:function () {
- return true;
- },
- step:function (dt) {
- this.update(1);
- },
- update:function (dt) {
- },
- reverse:function(){
- return this.clone();
- },
- clone:function(){
- return new cc.ActionInstant();
- }
- });
- cc.Show = cc.ActionInstant.extend({
- update:function (dt) {
- this.target.visible = true;
- },
- reverse:function () {
- return new cc.Hide();
- },
- clone:function(){
- return new cc.Show();
- }
- });
- cc.show = function () {
- return new cc.Show();
- };
- cc.Show.create = cc.show;
- cc.Hide = cc.ActionInstant.extend({
- update:function (dt) {
- this.target.visible = false;
- },
- reverse:function () {
- return new cc.Show();
- },
- clone:function(){
- return new cc.Hide();
- }
- });
- cc.hide = function () {
- return new cc.Hide();
- };
- cc.Hide.create = cc.hide;
- cc.ToggleVisibility = cc.ActionInstant.extend({
- update:function (dt) {
- this.target.visible = !this.target.visible;
- },
- reverse:function () {
- return new cc.ToggleVisibility();
- },
- clone:function(){
- return new cc.ToggleVisibility();
- }
- });
- cc.toggleVisibility = function () {
- return new cc.ToggleVisibility();
- };
- cc.ToggleVisibility.create = cc.toggleVisibility;
- cc.RemoveSelf = cc.ActionInstant.extend({
- _isNeedCleanUp: true,
- ctor:function(isNeedCleanUp){
- cc.FiniteTimeAction.prototype.ctor.call(this);
- isNeedCleanUp !== undefined && this.init(isNeedCleanUp);
- },
- update:function(dt){
- this.target.removeFromParent(this._isNeedCleanUp);
- },
- /**
- * Initialization of the node, please do not call this function by yourself, you should pass the parameters to constructor to initialize it
.
- * @param isNeedCleanUp
- * @returns {boolean}
- */
- init:function(isNeedCleanUp){
- this._isNeedCleanUp = isNeedCleanUp;
- return true;
- },
- reverse:function(){
- return new cc.RemoveSelf(this._isNeedCleanUp);
- },
- clone:function(){
- return new cc.RemoveSelf(this._isNeedCleanUp);
- }
- });
- cc.removeSelf = function(isNeedCleanUp){
- return new cc.RemoveSelf(isNeedCleanUp);
- };
- cc.RemoveSelf.create = cc.removeSelf;
- cc.FlipX = cc.ActionInstant.extend({
- _flippedX:false,
- ctor:function(flip){
- cc.FiniteTimeAction.prototype.ctor.call(this);
- this._flippedX = false;
- flip !== undefined && this.initWithFlipX(flip);
- },
- initWithFlipX:function (flip) {
- this._flippedX = flip;
- return true;
- },
- update:function (dt) {
- this.target.flippedX = this._flippedX;
- },
- reverse:function () {
- return new cc.FlipX(!this._flippedX);
- },
- clone:function(){
- var action = new cc.FlipX();
- action.initWithFlipX(this._flippedX);
- return action;
- }
- });
- cc.flipX = function (flip) {
- return new cc.FlipX(flip);
- };
- cc.FlipX.create = cc.flipX;
- cc.FlipY = cc.ActionInstant.extend({
- _flippedY:false,
- ctor: function(flip){
- cc.FiniteTimeAction.prototype.ctor.call(this);
- this._flippedY = false;
- flip !== undefined && this.initWithFlipY(flip);
- },
- initWithFlipY:function (flip) {
- this._flippedY = flip;
- return true;
- },
- update:function (dt) {
- this.target.flippedY = this._flippedY;
- },
- reverse:function () {
- return new cc.FlipY(!this._flippedY);
- },
- clone:function(){
- var action = new cc.FlipY();
- action.initWithFlipY(this._flippedY);
- return action;
- }
- });
- cc.flipY = function (flip) {
- return new cc.FlipY(flip);
- };
- cc.FlipY.create = cc.flipY;
- cc.Place = cc.ActionInstant.extend({
- _x: 0,
- _y: 0,
- ctor:function(pos, y){
- cc.FiniteTimeAction.prototype.ctor.call(this);
- this._x = 0;
- this._y = 0;
- if (pos !== undefined) {
- if (pos.x !== undefined) {
- y = pos.y;
- pos = pos.x;
- }
- this.initWithPosition(pos, y);
- }
- },
- initWithPosition: function (x, y) {
- this._x = x;
- this._y = y;
- return true;
- },
- update:function (dt) {
- this.target.setPosition(this._x, this._y);
- },
- clone:function(){
- var action = new cc.Place();
- action.initWithPosition(this._x, this._y);
- return action;
- }
- });
- cc.place = function (pos, y) {
- return new cc.Place(pos, y);
- };
- cc.Place.create = cc.place;
- cc.CallFunc = cc.ActionInstant.extend({
- _selectorTarget:null,
- _function:null,
- _data:null,
- ctor:function(selector, selectorTarget, data){
- cc.FiniteTimeAction.prototype.ctor.call(this);
- this.initWithFunction(selector, selectorTarget, data);
- },
- initWithFunction:function (selector, selectorTarget, data) {
- if (selector) {
- this._function = selector;
- }
- if (selectorTarget) {
- this._selectorTarget = selectorTarget;
- }
- if (data !== undefined) {
- this._data = data;
- }
- return true;
- },
- execute:function () {
- if (this._function) {
- this._function.call(this._selectorTarget, this.target, this._data);
- }
- },
- update:function (dt) {
- this.execute();
- },
- getTargetCallback:function () {
- return this._selectorTarget;
- },
- setTargetCallback:function (sel) {
- if (sel !== this._selectorTarget) {
- if (this._selectorTarget)
- this._selectorTarget = null;
- this._selectorTarget = sel;
- }
- },
- clone:function(){
- var action = new cc.CallFunc();
- action.initWithFunction(this._function, this._selectorTarget, this._data);
- return action;
- }
- });
- cc.callFunc = function (selector, selectorTarget, data) {
- return new cc.CallFunc(selector, selectorTarget, data);
- };
- cc.CallFunc.create = cc.callFunc;
- cc.ActionEase = cc.ActionInterval.extend({
- _inner:null,
- ctor: function (action) {
- cc.ActionInterval.prototype.ctor.call(this);
- action && this.initWithAction(action);
- },
- initWithAction:function (action) {
- if(!action)
- throw new Error("cc.ActionEase.initWithAction(): action must be non nil");
- if (this.initWithDuration(action.getDuration())) {
- this._inner = action;
- return true;
- }
- return false;
- },
- clone:function(){
- var action = new cc.ActionEase();
- action.initWithAction(this._inner.clone());
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._inner.startWithTarget(this.target);
- },
- stop:function () {
- this._inner.stop();
- cc.ActionInterval.prototype.stop.call(this);
- },
- update:function (dt) {
- this._inner.update(dt);
- },
- reverse:function () {
- return new cc.ActionEase(this._inner.reverse());
- },
- getInnerAction:function(){
- return this._inner;
- }
- });
- cc.actionEase = function (action) {
- return new cc.ActionEase(action);
- };
- cc.ActionEase.create = cc.actionEase;
- cc.EaseRateAction = cc.ActionEase.extend({
- _rate:0,
- ctor: function(action, rate){
- cc.ActionEase.prototype.ctor.call(this);
- rate !== undefined && this.initWithAction(action, rate);
- },
- setRate:function (rate) {
- this._rate = rate;
- },
- getRate:function () {
- return this._rate;
- },
- initWithAction:function (action, rate) {
- if (cc.ActionEase.prototype.initWithAction.call(this, action)) {
- this._rate = rate;
- return true;
- }
- return false;
- },
- clone:function(){
- var action = new cc.EaseRateAction();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- },
- reverse:function () {
- return new cc.EaseRateAction(this._inner.reverse(), 1 / this._rate);
- }
- });
- cc.easeRateAction = function (action, rate) {
- return new cc.EaseRateAction(action, rate);
- };
- cc.EaseRateAction.create = cc.easeRateAction;
- cc.EaseIn = cc.EaseRateAction.extend({
- update:function (dt) {
- this._inner.update(Math.pow(dt, this._rate));
- },
- reverse:function () {
- return new cc.EaseIn(this._inner.reverse(), 1 / this._rate);
- },
- clone:function(){
- var action = new cc.EaseIn();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- }
- });
- cc.EaseIn.create = function (action, rate) {
- return new cc.EaseIn(action, rate);
- };
- cc.easeIn = function (rate) {
- return {
- _rate: rate,
- easing: function (dt) {
- return Math.pow(dt, this._rate);
- },
- reverse: function(){
- return cc.easeIn(1 / this._rate);
- }
- };
- };
- cc.EaseOut = cc.EaseRateAction.extend({
- update:function (dt) {
- this._inner.update(Math.pow(dt, 1 / this._rate));
- },
- reverse:function () {
- return new cc.EaseOut(this._inner.reverse(), 1 / this._rate);
- },
- clone:function(){
- var action = new cc.EaseOut();
- action.initWithAction(this._inner.clone(),this._rate);
- return action;
- }
- });
- cc.EaseOut.create = function (action, rate) {
- return new cc.EaseOut(action, rate);
- };
- cc.easeOut = function (rate) {
- return {
- _rate: rate,
- easing: function (dt) {
- return Math.pow(dt, 1 / this._rate);
- },
- reverse: function(){
- return cc.easeOut(1 / this._rate)
- }
- };
- };
- cc.EaseInOut = cc.EaseRateAction.extend({
- update:function (dt) {
- dt *= 2;
- if (dt < 1)
- this._inner.update(0.5 * Math.pow(dt, this._rate));
- else
- this._inner.update(1.0 - 0.5 * Math.pow(2 - dt, this._rate));
- },
- clone:function(){
- var action = new cc.EaseInOut();
- action.initWithAction(this._inner.clone(), this._rate);
- return action;
- },
- reverse:function () {
- return new cc.EaseInOut(this._inner.reverse(), this._rate);
- }
- });
- cc.EaseInOut.create = function (action, rate) {
- return new cc.EaseInOut(action, rate);
- };
- cc.easeInOut = function (rate) {
- return {
- _rate: rate,
- easing: function (dt) {
- dt *= 2;
- if (dt < 1)
- return 0.5 * Math.pow(dt, this._rate);
- else
- return 1.0 - 0.5 * Math.pow(2 - dt, this._rate);
- },
- reverse: function(){
- return cc.easeInOut(this._rate);
- }
- };
- };
- cc.EaseExponentialIn = cc.ActionEase.extend({
- update:function (dt) {
- this._inner.update(dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1)));
- },
- reverse:function () {
- return new cc.EaseExponentialOut(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseExponentialIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseExponentialIn.create = function (action) {
- return new cc.EaseExponentialIn(action);
- };
- cc._easeExponentialInObj = {
- easing: function(dt){
- return dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1));
- },
- reverse: function(){
- return cc._easeExponentialOutObj;
- }
- };
- cc.easeExponentialIn = function(){
- return cc._easeExponentialInObj;
- };
- cc.EaseExponentialOut = cc.ActionEase.extend({
- update:function (dt) {
- this._inner.update(dt === 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1));
- },
- reverse:function () {
- return new cc.EaseExponentialIn(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseExponentialOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseExponentialOut.create = function (action) {
- return new cc.EaseExponentialOut(action);
- };
- cc._easeExponentialOutObj = {
- easing: function(dt){
- return dt === 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1);
- },
- reverse: function(){
- return cc._easeExponentialInObj;
- }
- };
- cc.easeExponentialOut = function(){
- return cc._easeExponentialOutObj;
- };
- cc.EaseExponentialInOut = cc.ActionEase.extend({
- update:function (dt) {
- if( dt !== 1 && dt !== 0) {
- dt *= 2;
- if (dt < 1)
- dt = 0.5 * Math.pow(2, 10 * (dt - 1));
- else
- dt = 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
- }
- this._inner.update(dt);
- },
- reverse:function () {
- return new cc.EaseExponentialInOut(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseExponentialInOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseExponentialInOut.create = function (action) {
- return new cc.EaseExponentialInOut(action);
- };
- cc._easeExponentialInOutObj = {
- easing: function(dt){
- if( dt !== 1 && dt !== 0) {
- dt *= 2;
- if (dt < 1)
- return 0.5 * Math.pow(2, 10 * (dt - 1));
- else
- return 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
- }
- return dt;
- },
- reverse: function(){
- return cc._easeExponentialInOutObj;
- }
- };
- cc.easeExponentialInOut = function(){
- return cc._easeExponentialInOutObj;
- };
- cc.EaseSineIn = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
- this._inner.update(dt);
- },
- reverse:function () {
- return new cc.EaseSineOut(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseSineIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseSineIn.create = function (action) {
- return new cc.EaseSineIn(action);
- };
- cc._easeSineInObj = {
- easing: function(dt){
- return (dt===0 || dt===1) ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
- },
- reverse: function(){
- return cc._easeSineOutObj;
- }
- };
- cc.easeSineIn = function(){
- return cc._easeSineInObj;
- };
- cc.EaseSineOut = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : Math.sin(dt * Math.PI / 2);
- this._inner.update(dt);
- },
- reverse:function () {
- return new cc.EaseSineIn(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseSineOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseSineOut.create = function (action) {
- return new cc.EaseSineOut(action);
- };
- cc._easeSineOutObj = {
- easing: function(dt){
- return (dt===0 || dt===1) ? dt : Math.sin(dt * Math.PI / 2);
- },
- reverse: function(){
- return cc._easeSineInObj;
- }
- };
- cc.easeSineOut = function(){
- return cc._easeSineOutObj;
- };
- cc.EaseSineInOut = cc.ActionEase.extend({
- update:function (dt) {
- dt = dt===0 || dt===1 ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
- this._inner.update(dt);
- },
- clone:function(){
- var action = new cc.EaseSineInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse:function () {
- return new cc.EaseSineInOut(this._inner.reverse());
- }
- });
- cc.EaseSineInOut.create = function (action) {
- return new cc.EaseSineInOut(action);
- };
- cc._easeSineInOutObj = {
- easing: function(dt){
- return (dt === 0 || dt === 1) ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
- },
- reverse: function(){
- return cc._easeSineInOutObj;
- }
- };
- cc.easeSineInOut = function(){
- return cc._easeSineInOutObj;
- };
- cc.EaseElastic = cc.ActionEase.extend({
- _period: 0.3,
- ctor:function(action, period){
- cc.ActionEase.prototype.ctor.call(this);
- action && this.initWithAction(action, period);
- },
- getPeriod:function () {
- return this._period;
- },
- setPeriod:function (period) {
- this._period = period;
- },
- initWithAction:function (action, period) {
- cc.ActionEase.prototype.initWithAction.call(this, action);
- this._period = (period == null) ? 0.3 : period;
- return true;
- },
- reverse:function () {
- cc.log("cc.EaseElastic.reverse(): it should be overridden in subclass.");
- return null;
- },
- clone:function(){
- var action = new cc.EaseElastic();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
- });
- cc.EaseElastic.create = function (action, period) {
- return new cc.EaseElastic(action, period);
- };
- cc.EaseElasticIn = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- var s = this._period / 4;
- dt = dt - 1;
- newT = -Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / this._period);
- }
- this._inner.update(newT);
- },
- reverse:function () {
- return new cc.EaseElasticOut(this._inner.reverse(), this._period);
- },
- clone:function(){
- var action = new cc.EaseElasticIn();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
- });
- cc.EaseElasticIn.create = function (action, period) {
- return new cc.EaseElasticIn(action, period);
- };
- cc._easeElasticInObj = {
- easing:function(dt){
- if (dt === 0 || dt === 1)
- return dt;
- dt = dt - 1;
- return -Math.pow(2, 10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3);
- },
- reverse:function(){
- return cc._easeElasticOutObj;
- }
- };
- cc.easeElasticIn = function (period) {
- if(period && period !== 0.3){
- return {
- _period: period,
- easing: function (dt) {
- if (dt === 0 || dt === 1)
- return dt;
- dt = dt - 1;
- return -Math.pow(2, 10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period);
- },
- reverse:function () {
- return cc.easeElasticOut(this._period);
- }
- };
- }
- return cc._easeElasticInObj;
- };
- cc.EaseElasticOut = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- var s = this._period / 4;
- newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / this._period) + 1;
- }
- this._inner.update(newT);
- },
- reverse:function () {
- return new cc.EaseElasticIn(this._inner.reverse(), this._period);
- },
- clone:function(){
- var action = new cc.EaseElasticOut();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
- });
- cc.EaseElasticOut.create = function (action, period) {
- return new cc.EaseElasticOut(action, period);
- };
- cc._easeElasticOutObj = {
- easing: function (dt) {
- return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3) + 1;
- },
- reverse:function(){
- return cc._easeElasticInObj;
- }
- };
- cc.easeElasticOut = function (period) {
- if(period && period !== 0.3){
- return {
- _period: period,
- easing: function (dt) {
- return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period) + 1;
- },
- reverse:function(){
- return cc.easeElasticIn(this._period);
- }
- };
- }
- return cc._easeElasticOutObj;
- };
- cc.EaseElasticInOut = cc.EaseElastic.extend({
- update:function (dt) {
- var newT = 0;
- var locPeriod = this._period;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- dt = dt * 2;
- if (!locPeriod)
- locPeriod = this._period = 0.3 * 1.5;
- var s = locPeriod / 4;
- dt = dt - 1;
- if (dt < 0)
- newT = -0.5 * Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod);
- else
- newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod) * 0.5 + 1;
- }
- this._inner.update(newT);
- },
- reverse:function () {
- return new cc.EaseElasticInOut(this._inner.reverse(), this._period);
- },
- clone:function(){
- var action = new cc.EaseElasticInOut();
- action.initWithAction(this._inner.clone(), this._period);
- return action;
- }
- });
- cc.EaseElasticInOut.create = function (action, period) {
- return new cc.EaseElasticInOut(action, period);
- };
- cc.easeElasticInOut = function (period) {
- period = period || 0.3;
- return {
- _period: period,
- easing: function (dt) {
- var newT = 0;
- var locPeriod = this._period;
- if (dt === 0 || dt === 1) {
- newT = dt;
- } else {
- dt = dt * 2;
- if (!locPeriod)
- locPeriod = this._period = 0.3 * 1.5;
- var s = locPeriod / 4;
- dt = dt - 1;
- if (dt < 0)
- newT = -0.5 * Math.pow(2, 10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod);
- else
- newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod) * 0.5 + 1;
- }
- return newT;
- },
- reverse: function(){
- return cc.easeElasticInOut(this._period);
- }
- };
- };
- cc.EaseBounce = cc.ActionEase.extend({
- bounceTime:function (time1) {
- if (time1 < 1 / 2.75) {
- return 7.5625 * time1 * time1;
- } else if (time1 < 2 / 2.75) {
- time1 -= 1.5 / 2.75;
- return 7.5625 * time1 * time1 + 0.75;
- } else if (time1 < 2.5 / 2.75) {
- time1 -= 2.25 / 2.75;
- return 7.5625 * time1 * time1 + 0.9375;
- }
- time1 -= 2.625 / 2.75;
- return 7.5625 * time1 * time1 + 0.984375;
- },
- clone:function(){
- var action = new cc.EaseBounce();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse:function () {
- return new cc.EaseBounce(this._inner.reverse());
- }
- });
- cc.EaseBounce.create = function (action) {
- return new cc.EaseBounce(action);
- };
- cc.EaseBounceIn = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = 1 - this.bounceTime(1 - dt);
- this._inner.update(newT);
- },
- reverse:function () {
- return new cc.EaseBounceOut(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseBounceIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseBounceIn.create = function (action) {
- return new cc.EaseBounceIn(action);
- };
- cc._bounceTime = function (time1) {
- if (time1 < 1 / 2.75) {
- return 7.5625 * time1 * time1;
- } else if (time1 < 2 / 2.75) {
- time1 -= 1.5 / 2.75;
- return 7.5625 * time1 * time1 + 0.75;
- } else if (time1 < 2.5 / 2.75) {
- time1 -= 2.25 / 2.75;
- return 7.5625 * time1 * time1 + 0.9375;
- }
- time1 -= 2.625 / 2.75;
- return 7.5625 * time1 * time1 + 0.984375;
- };
- cc._easeBounceInObj = {
- easing: function(dt){
- return 1 - cc._bounceTime(1 - dt);
- },
- reverse: function(){
- return cc._easeBounceOutObj;
- }
- };
- cc.easeBounceIn = function(){
- return cc._easeBounceInObj;
- };
- cc.EaseBounceOut = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = this.bounceTime(dt);
- this._inner.update(newT);
- },
- reverse:function () {
- return new cc.EaseBounceIn(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseBounceOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseBounceOut.create = function (action) {
- return new cc.EaseBounceOut(action);
- };
- cc._easeBounceOutObj = {
- easing: function(dt){
- return cc._bounceTime(dt);
- },
- reverse:function () {
- return cc._easeBounceInObj;
- }
- };
- cc.easeBounceOut = function(){
- return cc._easeBounceOutObj;
- };
- cc.EaseBounceInOut = cc.EaseBounce.extend({
- update:function (dt) {
- var newT = 0;
- if (dt < 0.5) {
- dt = dt * 2;
- newT = (1 - this.bounceTime(1 - dt)) * 0.5;
- } else {
- newT = this.bounceTime(dt * 2 - 1) * 0.5 + 0.5;
- }
- this._inner.update(newT);
- },
- clone:function(){
- var action = new cc.EaseBounceInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse:function () {
- return new cc.EaseBounceInOut(this._inner.reverse());
- }
- });
- cc.EaseBounceInOut.create = function (action) {
- return new cc.EaseBounceInOut(action);
- };
- cc._easeBounceInOutObj = {
- easing: function (time1) {
- var newT;
- if (time1 < 0.5) {
- time1 = time1 * 2;
- newT = (1 - cc._bounceTime(1 - time1)) * 0.5;
- } else {
- newT = cc._bounceTime(time1 * 2 - 1) * 0.5 + 0.5;
- }
- return newT;
- },
- reverse: function(){
- return cc._easeBounceInOutObj;
- }
- };
- cc.easeBounceInOut = function(){
- return cc._easeBounceInOutObj;
- };
- cc.EaseBackIn = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158;
- dt = dt===0 || dt===1 ? dt : dt * dt * ((overshoot + 1) * dt - overshoot);
- this._inner.update(dt);
- },
- reverse:function () {
- return new cc.EaseBackOut(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseBackIn();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseBackIn.create = function (action) {
- return new cc.EaseBackIn(action);
- };
- cc._easeBackInObj = {
- easing: function (time1) {
- var overshoot = 1.70158;
- return (time1===0 || time1===1) ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot);
- },
- reverse: function(){
- return cc._easeBackOutObj;
- }
- };
- cc.easeBackIn = function(){
- return cc._easeBackInObj;
- };
- cc.EaseBackOut = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158;
- dt = dt - 1;
- this._inner.update(dt * dt * ((overshoot + 1) * dt + overshoot) + 1);
- },
- reverse:function () {
- return new cc.EaseBackIn(this._inner.reverse());
- },
- clone:function(){
- var action = new cc.EaseBackOut();
- action.initWithAction(this._inner.clone());
- return action;
- }
- });
- cc.EaseBackOut.create = function (action) {
- return new cc.EaseBackOut(action);
- };
- cc._easeBackOutObj = {
- easing: function (time1) {
- var overshoot = 1.70158;
- time1 = time1 - 1;
- return time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1;
- },
- reverse: function(){
- return cc._easeBackInObj;
- }
- };
- cc.easeBackOut = function(){
- return cc._easeBackOutObj;
- };
- cc.EaseBackInOut = cc.ActionEase.extend({
- update:function (dt) {
- var overshoot = 1.70158 * 1.525;
- dt = dt * 2;
- if (dt < 1) {
- this._inner.update((dt * dt * ((overshoot + 1) * dt - overshoot)) / 2);
- } else {
- dt = dt - 2;
- this._inner.update((dt * dt * ((overshoot + 1) * dt + overshoot)) / 2 + 1);
- }
- },
- clone:function(){
- var action = new cc.EaseBackInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse:function () {
- return new cc.EaseBackInOut(this._inner.reverse());
- }
- });
- cc.EaseBackInOut.create = function (action) {
- return new cc.EaseBackInOut(action);
- };
- cc._easeBackInOutObj = {
- easing: function (time1) {
- var overshoot = 1.70158 * 1.525;
- time1 = time1 * 2;
- if (time1 < 1) {
- return (time1 * time1 * ((overshoot + 1) * time1 - overshoot)) / 2;
- } else {
- time1 = time1 - 2;
- return (time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1;
- }
- },
- reverse: function(){
- return cc._easeBackInOutObj;
- }
- };
- cc.easeBackInOut = function(){
- return cc._easeBackInOutObj;
- };
- cc.EaseBezierAction = cc.ActionEase.extend({
- _p0: null,
- _p1: null,
- _p2: null,
- _p3: null,
- ctor: function(action){
- cc.ActionEase.prototype.ctor.call(this, action);
- },
- _updateTime: function(a, b, c, d, t){
- return (Math.pow(1-t,3) * a + 3*t*(Math.pow(1-t,2))*b + 3*Math.pow(t,2)*(1-t)*c + Math.pow(t,3)*d );
- },
- update: function(dt){
- var t = this._updateTime(this._p0, this._p1, this._p2, this._p3, dt);
- this._inner.update(t);
- },
- clone: function(){
- var action = new cc.EaseBezierAction();
- action.initWithAction(this._inner.clone());
- action.setBezierParamer(this._p0, this._p1, this._p2, this._p3);
- return action;
- },
- reverse: function(){
- var action = new cc.EaseBezierAction(this._inner.reverse());
- action.setBezierParamer(this._p3, this._p2, this._p1, this._p0);
- return action;
- },
- setBezierParamer: function(p0, p1, p2, p3){
- this._p0 = p0 || 0;
- this._p1 = p1 || 0;
- this._p2 = p2 || 0;
- this._p3 = p3 || 0;
- }
- });
- cc.EaseBezierAction.create = function(action){
- return new cc.EaseBezierAction(action);
- };
- cc.easeBezierAction = function(p0, p1, p2, p3){
- return {
- easing: function(time){
- return cc.EaseBezierAction.prototype._updateTime(p0, p1, p2, p3, time);
- },
- reverse: function(){
- return cc.easeBezierAction(p3, p2, p1, p0);
- }
- };
- };
- cc.EaseQuadraticActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return Math.pow(time, 2);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuadraticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuadraticActionIn(this._inner.reverse());
- }
- });
- cc.EaseQuadraticActionIn.create = function(action){
- return new cc.EaseQuadraticActionIn(action);
- };
- cc._easeQuadraticActionIn = {
- easing: cc.EaseQuadraticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionIn;
- }
- };
- cc.easeQuadraticActionIn = function(){
- return cc._easeQuadraticActionIn;
- };
- cc.EaseQuadraticActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- return -time*(time-2);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuadraticActionOut();
- action.initWithAction();
- return action;
- },
- reverse: function(){
- return new cc.EaseQuadraticActionOut(this._inner.reverse());
- }
- });
- cc.EaseQuadraticActionOut.create = function(action){
- return new cc.EaseQuadraticActionOut(action);
- };
- cc._easeQuadraticActionOut = {
- easing: cc.EaseQuadraticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionOut;
- }
- };
- cc.easeQuadraticActionOut = function(){
- return cc._easeQuadraticActionOut;
- };
- cc.EaseQuadraticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- var resultTime = time;
- time *= 2;
- if(time < 1){
- resultTime = time * time * 0.5;
- }else{
- --time;
- resultTime = -0.5 * ( time * ( time - 2 ) - 1)
- }
- return resultTime;
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuadraticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuadraticActionInOut(this._inner.reverse());
- }
- });
- cc.EaseQuadraticActionInOut.create = function(action){
- return new cc.EaseQuadraticActionInOut(action);
- };
- cc._easeQuadraticActionInOut = {
- easing: cc.EaseQuadraticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuadraticActionInOut;
- }
- };
- cc.easeQuadraticActionInOut = function(){
- return cc._easeQuadraticActionInOut;
- };
- cc.EaseQuarticActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time * time;
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuarticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuarticActionIn(this._inner.reverse());
- }
- });
- cc.EaseQuarticActionIn.create = function(action){
- return new cc.EaseQuarticActionIn(action);
- };
- cc._easeQuarticActionIn = {
- easing: cc.EaseQuarticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionIn;
- }
- };
- cc.easeQuarticActionIn = function(){
- return cc._easeQuarticActionIn;
- };
- cc.EaseQuarticActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -= 1;
- return -(time * time * time * time - 1);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuarticActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuarticActionOut(this._inner.reverse());
- }
- });
- cc.EaseQuarticActionOut.create = function(action){
- return new cc.EaseQuarticActionOut(action);
- };
- cc._easeQuarticActionOut = {
- easing: cc.EaseQuarticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionOut;
- }
- };
- cc.easeQuarticActionOut = function(){
- return cc._easeQuarticActionOut;
- };
- cc.EaseQuarticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time * time;
- time -= 2;
- return -0.5 * (time * time * time * time - 2);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuarticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuarticActionInOut(this._inner.reverse());
- }
- });
- cc.EaseQuarticActionInOut.create = function(action){
- return new cc.EaseQuarticActionInOut(action);
- };
- cc._easeQuarticActionInOut = {
- easing: cc.EaseQuarticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuarticActionInOut;
- }
- };
- cc.easeQuarticActionInOut = function(){
- return cc._easeQuarticActionInOut;
- };
- cc.EaseQuinticActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time * time * time;
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuinticActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuinticActionIn(this._inner.reverse());
- }
- });
- cc.EaseQuinticActionIn.create = function(action){
- return new cc.EaseQuinticActionIn(action);
- };
- cc._easeQuinticActionIn = {
- easing: cc.EaseQuinticActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionIn;
- }
- };
- cc.easeQuinticActionIn = function(){
- return cc._easeQuinticActionIn;
- };
- cc.EaseQuinticActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -=1;
- return (time * time * time * time * time + 1);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuinticActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuinticActionOut(this._inner.reverse());
- }
- });
- cc.EaseQuinticActionOut.create = function(action){
- return new cc.EaseQuinticActionOut(action);
- };
- cc._easeQuinticActionOut = {
- easing: cc.EaseQuinticActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionOut;
- }
- };
- cc.easeQuinticActionOut = function(){
- return cc._easeQuinticActionOut;
- };
- cc.EaseQuinticActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time * time * time;
- time -= 2;
- return 0.5 * (time * time * time * time * time + 2);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseQuinticActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseQuinticActionInOut(this._inner.reverse());
- }
- });
- cc.EaseQuinticActionInOut.create = function(action){
- return new cc.EaseQuinticActionInOut(action);
- };
- cc._easeQuinticActionInOut = {
- easing: cc.EaseQuinticActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeQuinticActionInOut;
- }
- };
- cc.easeQuinticActionInOut = function(){
- return cc._easeQuinticActionInOut;
- };
- cc.EaseCircleActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return -1 * (Math.sqrt(1 - time * time) - 1);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCircleActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCircleActionIn(this._inner.reverse());
- }
- });
- cc.EaseCircleActionIn.create = function(action){
- return new cc.EaseCircleActionIn(action);
- };
- cc._easeCircleActionIn = {
- easing: cc.EaseCircleActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionIn;
- }
- };
- cc.easeCircleActionIn = function(){
- return cc._easeCircleActionIn;
- };
- cc.EaseCircleActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time - 1;
- return Math.sqrt(1 - time * time);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCircleActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCircleActionOut(this._inner.reverse());
- }
- });
- cc.EaseCircleActionOut.create = function(action){
- return new cc.EaseCircleActionOut(action);
- };
- cc._easeCircleActionOut = {
- easing: cc.EaseCircleActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionOut;
- }
- };
- cc.easeCircleActionOut = function(){
- return cc._easeCircleActionOut;
- };
- cc.EaseCircleActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time * 2;
- if (time < 1)
- return -0.5 * (Math.sqrt(1 - time * time) - 1);
- time -= 2;
- return 0.5 * (Math.sqrt(1 - time * time) + 1);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCircleActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCircleActionInOut(this._inner.reverse());
- }
- });
- cc.EaseCircleActionInOut.create = function(action){
- return new cc.EaseCircleActionInOut(action);
- };
- cc._easeCircleActionInOut = {
- easing: cc.EaseCircleActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCircleActionInOut;
- }
- };
- cc.easeCircleActionInOut = function(){
- return cc._easeCircleActionInOut;
- };
- cc.EaseCubicActionIn = cc.ActionEase.extend({
- _updateTime: function(time){
- return time * time * time;
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCubicActionIn();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCubicActionIn(this._inner.reverse());
- }
- });
- cc.EaseCubicActionIn.create = function(action){
- return new cc.EaseCubicActionIn(action);
- };
- cc._easeCubicActionIn = {
- easing: cc.EaseCubicActionIn.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionIn;
- }
- };
- cc.easeCubicActionIn = function(){
- return cc._easeCubicActionIn;
- };
- cc.EaseCubicActionOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time -= 1;
- return (time * time * time + 1);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCubicActionOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCubicActionOut(this._inner.reverse());
- }
- });
- cc.EaseCubicActionOut.create = function(action){
- return new cc.EaseCubicActionOut(action);
- };
- cc._easeCubicActionOut = {
- easing: cc.EaseCubicActionOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionOut;
- }
- };
- cc.easeCubicActionOut = function(){
- return cc._easeCubicActionOut;
- };
- cc.EaseCubicActionInOut = cc.ActionEase.extend({
- _updateTime: function(time){
- time = time*2;
- if (time < 1)
- return 0.5 * time * time * time;
- time -= 2;
- return 0.5 * (time * time * time + 2);
- },
- update: function(dt){
- this._inner.update(this._updateTime(dt));
- },
- clone: function(){
- var action = new cc.EaseCubicActionInOut();
- action.initWithAction(this._inner.clone());
- return action;
- },
- reverse: function(){
- return new cc.EaseCubicActionInOut(this._inner.reverse());
- }
- });
- cc.EaseCubicActionInOut.create = function(action){
- return new cc.EaseCubicActionInOut(action);
- };
- cc._easeCubicActionInOut = {
- easing: cc.EaseCubicActionInOut.prototype._updateTime,
- reverse: function(){
- return cc._easeCubicActionInOut;
- }
- };
- cc.easeCubicActionInOut = function(){
- return cc._easeCubicActionInOut;
- };
- cc.cardinalSplineAt = function (p0, p1, p2, p3, tension, t) {
- var t2 = t * t;
- var t3 = t2 * t;
- var s = (1 - tension) / 2;
- var b1 = s * ((-t3 + (2 * t2)) - t);
- var b2 = s * (-t3 + t2) + (2 * t3 - 3 * t2 + 1);
- var b3 = s * (t3 - 2 * t2 + t) + (-2 * t3 + 3 * t2);
- var b4 = s * (t3 - t2);
- var x = (p0.x * b1 + p1.x * b2 + p2.x * b3 + p3.x * b4);
- var y = (p0.y * b1 + p1.y * b2 + p2.y * b3 + p3.y * b4);
- return cc.p(x, y);
- };
- cc.reverseControlPoints = function (controlPoints) {
- var newArray = [];
- for (var i = controlPoints.length - 1; i >= 0; i--) {
- newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
- }
- return newArray;
- };
- cc.cloneControlPoints = function (controlPoints) {
- var newArray = [];
- for (var i = 0; i < controlPoints.length; i++)
- newArray.push(cc.p(controlPoints[i].x, controlPoints[i].y));
- return newArray;
- };
- cc.copyControlPoints = cc.cloneControlPoints;
- cc.getControlPointAt = function (controlPoints, pos) {
- var p = Math.min(controlPoints.length - 1, Math.max(pos, 0));
- return controlPoints[p];
- };
- cc.reverseControlPointsInline = function (controlPoints) {
- var len = controlPoints.length;
- var mid = 0 | (len / 2);
- for (var i = 0; i < mid; ++i) {
- var temp = controlPoints[i];
- controlPoints[i] = controlPoints[len - i - 1];
- controlPoints[len - i - 1] = temp;
- }
- };
- cc.CardinalSplineTo = cc.ActionInterval.extend({
- _points:null,
- _deltaT:0,
- _tension:0,
- _previousPosition:null,
- _accumulatedDiff:null,
- ctor: function (duration, points, tension) {
- cc.ActionInterval.prototype.ctor.call(this);
- this._points = [];
- tension !== undefined && this.initWithDuration(duration, points, tension);
- },
- initWithDuration:function (duration, points, tension) {
- if(!points || points.length === 0)
- throw new Error("Invalid configuration. It must at least have one control point");
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this.setPoints(points);
- this._tension = tension;
- return true;
- }
- return false;
- },
- clone:function () {
- var action = new cc.CardinalSplineTo();
- action.initWithDuration(this._duration, cc.copyControlPoints(this._points), this._tension);
- return action;
- },
- startWithTarget:function (target) {
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this._deltaT = 1 / (this._points.length - 1);
- this._previousPosition = cc.p(this.target.getPositionX(), this.target.getPositionY());
- this._accumulatedDiff = cc.p(0, 0);
- },
- update:function (dt) {
- dt = this._computeEaseTime(dt);
- var p, lt;
- var ps = this._points;
- if (dt === 1) {
- p = ps.length - 1;
- lt = 1;
- } else {
- var locDT = this._deltaT;
- p = 0 | (dt / locDT);
- lt = (dt - locDT * p) / locDT;
- }
- var newPos = cc.cardinalSplineAt(
- cc.getControlPointAt(ps, p - 1),
- cc.getControlPointAt(ps, p - 0),
- cc.getControlPointAt(ps, p + 1),
- cc.getControlPointAt(ps, p + 2),
- this._tension, lt);
- if (cc.ENABLE_STACKABLE_ACTIONS) {
- var tempX, tempY;
- tempX = this.target.getPositionX() - this._previousPosition.x;
- tempY = this.target.getPositionY() - this._previousPosition.y;
- if (tempX !== 0 || tempY !== 0) {
- var locAccDiff = this._accumulatedDiff;
- tempX = locAccDiff.x + tempX;
- tempY = locAccDiff.y + tempY;
- locAccDiff.x = tempX;
- locAccDiff.y = tempY;
- newPos.x += tempX;
- newPos.y += tempY;
- }
- }
- this.updatePosition(newPos);
- },
- reverse:function () {
- var reversePoints = cc.reverseControlPoints(this._points);
- return cc.cardinalSplineTo(this._duration, reversePoints, this._tension);
- },
- updatePosition:function (newPos) {
- this.target.setPosition(newPos);
- this._previousPosition = newPos;
- },
- getPoints:function () {
- return this._points;
- },
- setPoints:function (points) {
- this._points = points;
- }
- });
- cc.cardinalSplineTo = function (duration, points, tension) {
- return new cc.CardinalSplineTo(duration, points, tension);
- };
- cc.CardinalSplineTo.create = cc.cardinalSplineTo;
- cc.CardinalSplineBy = cc.CardinalSplineTo.extend({
- _startPosition:null,
- ctor:function (duration, points, tension) {
- cc.CardinalSplineTo.prototype.ctor.call(this);
- this._startPosition = cc.p(0, 0);
- tension !== undefined && this.initWithDuration(duration, points, tension);
- },
- startWithTarget:function (target) {
- cc.CardinalSplineTo.prototype.startWithTarget.call(this, target);
- this._startPosition.x = target.getPositionX();
- this._startPosition.y = target.getPositionY();
- },
- reverse:function () {
- var copyConfig = this._points.slice();
- var current;
- var p = copyConfig[0];
- for (var i = 1; i < copyConfig.length; ++i) {
- current = copyConfig[i];
- copyConfig[i] = cc.pSub(current, p);
- p = current;
- }
- var reverseArray = cc.reverseControlPoints(copyConfig);
- p = reverseArray[ reverseArray.length - 1 ];
- reverseArray.pop();
- p.x = -p.x;
- p.y = -p.y;
- reverseArray.unshift(p);
- for (var i = 1; i < reverseArray.length; ++i) {
- current = reverseArray[i];
- current.x = -current.x;
- current.y = -current.y;
- current.x += p.x;
- current.y += p.y;
- reverseArray[i] = current;
- p = current;
- }
- return cc.cardinalSplineBy(this._duration, reverseArray, this._tension);
- },
- updatePosition:function (newPos) {
- var pos = this._startPosition;
- var posX = newPos.x + pos.x;
- var posY = newPos.y + pos.y;
- this._previousPosition.x = posX;
- this._previousPosition.y = posY;
- this.target.setPosition(posX, posY);
- },
- clone:function () {
- var a = new cc.CardinalSplineBy();
- a.initWithDuration(this._duration, cc.copyControlPoints(this._points), this._tension);
- return a;
- }
- });
- cc.cardinalSplineBy = function (duration, points, tension) {
- return new cc.CardinalSplineBy(duration, points, tension);
- };
- cc.CardinalSplineBy.create = cc.cardinalSplineBy;
- cc.CatmullRomTo = cc.CardinalSplineTo.extend({
- ctor: function(dt, points) {
- points && this.initWithDuration(dt, points);
- },
- initWithDuration:function (dt, points) {
- return cc.CardinalSplineTo.prototype.initWithDuration.call(this, dt, points, 0.5);
- },
- clone:function () {
- var action = new cc.CatmullRomTo();
- action.initWithDuration(this._duration, cc.copyControlPoints(this._points));
- return action;
- }
- });
- cc.catmullRomTo = function (dt, points) {
- return new cc.CatmullRomTo(dt, points);
- };
- cc.CatmullRomTo.create = cc.catmullRomTo;
- cc.CatmullRomBy = cc.CardinalSplineBy.extend({
- ctor: function(dt, points) {
- cc.CardinalSplineBy.prototype.ctor.call(this);
- points && this.initWithDuration(dt, points);
- },
- initWithDuration:function (dt, points) {
- return cc.CardinalSplineTo.prototype.initWithDuration.call(this, dt, points, 0.5);
- },
- clone:function () {
- var action = new cc.CatmullRomBy();
- action.initWithDuration(this._duration, cc.copyControlPoints(this._points));
- return action;
- }
- });
- cc.catmullRomBy = function (dt, points) {
- return new cc.CatmullRomBy(dt, points);
- };
- cc.CatmullRomBy.create = cc.catmullRomBy;
- cc.ActionTweenDelegate = cc.Class.extend({
- updateTweenAction:function(value, key){}
- });
- cc.ActionTween = cc.ActionInterval.extend({
- key:"",
- from:0,
- to:0,
- delta:0,
- ctor:function(duration, key, from, to){
- cc.ActionInterval.prototype.ctor.call(this);
- this.key = "";
- to !== undefined && this.initWithDuration(duration, key, from, to);
- },
- initWithDuration:function (duration, key, from, to) {
- if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
- this.key = key;
- this.to = to;
- this.from = from;
- return true;
- }
- return false;
- },
- startWithTarget:function (target) {
- if(!target || !target.updateTweenAction)
- throw new Error("cc.ActionTween.startWithTarget(): target must be non-null, and target must implement updateTweenAction function");
- cc.ActionInterval.prototype.startWithTarget.call(this, target);
- this.delta = this.to - this.from;
- },
- update:function (dt) {
- this.target.updateTweenAction(this.to - this.delta * (1 - dt), this.key);
- },
- reverse:function () {
- return new cc.ActionTween(this.duration, this.key, this.to, this.from);
- },
- clone:function(){
- var action = new cc.ActionTween();
- action.initWithDuration(this._duration, this.key, this.from, this.to);
- return action;
- }
- });
- cc.actionTween = function (duration, key, from, to) {
- return new cc.ActionTween(duration, key, from, to);
- };
- cc.ActionTween.create = cc.actionTween;
- (function(){
- var DEBUG = false;
- var sys = cc.sys;
- var version = sys.browserVersion;
- var supportWebAudio = !!(window.AudioContext || window.webkitAudioContext || window.mozAudioContext);
- var support = {ONLY_ONE: false, WEB_AUDIO: supportWebAudio, DELAY_CREATE_CTX: false, ONE_SOURCE: false };
- if (sys.browserType === sys.BROWSER_TYPE_FIREFOX) {
- support.DELAY_CREATE_CTX = true;
- support.USE_LOADER_EVENT = 'canplay';
- }
- if (sys.os === sys.OS_IOS) {
- support.USE_LOADER_EVENT = 'loadedmetadata';
- }
- if (sys.os === sys.OS_ANDROID) {
- if (sys.browserType === sys.BROWSER_TYPE_UC) {
- support.ONE_SOURCE = true;
- }
- }
- window.__audioSupport = support;
- if(DEBUG){
- setTimeout(function(){
- cc.log("browse type: " + sys.browserType);
- cc.log("browse version: " + version);
- cc.log("MULTI_CHANNEL: " + window.__audioSupport.MULTI_CHANNEL);
- cc.log("WEB_AUDIO: " + window.__audioSupport.WEB_AUDIO);
- cc.log("AUTOPLAY: " + window.__audioSupport.AUTOPLAY);
- }, 0);
- }
- })();
- cc.Audio = cc.Class.extend({
- src: null,
- _element: null,
- _AUDIO_TYPE: "AUDIO",
- ctor: function(url){
- this.src = url;
- },
- setBuffer: function (buffer) {
- this._AUDIO_TYPE = "WEBAUDIO";
- this._element = new cc.Audio.WebAudio(buffer);
- },
- setElement: function (element) {
- this._AUDIO_TYPE = "AUDIO";
- this._element = element;
- element.addEventListener('ended', function () {
- if (!element.loop) {
- element.paused = true;
- }
- });
- },
- play: function (offset, loop) {
- if (!this._element) return;
- this._element.loop = loop;
- this._element.play();
- if (this._AUDIO_TYPE === 'AUDIO' && this._element.paused) {
- this.stop();
- cc.Audio.touchPlayList.push({ loop: loop, offset: offset, audio: this._element });
- }
- if (cc.Audio.bindTouch === false) {
- cc.Audio.bindTouch = true;
- cc.game.canvas.addEventListener('touchstart', cc.Audio.touchStart);
- }
- },
- getPlaying: function () {
- if (!this._element) return true;
- return !this._element.paused;
- },
- stop: function () {
- if (!this._element) return;
- this._element.pause();
- try{
- this._element.currentTime = 0;
- } catch (err) {}
- },
- pause: function () {
- if (!this._element) return;
- this._element.pause();
- },
- resume: function () {
- if (!this._element) return;
- this._element.play();
- },
- setVolume: function (volume) {
- if (!this._element) return;
- this._element.volume = volume;
- },
- getVolume: function () {
- if (!this._element) return;
- return this._element.volume;
- },
- cloneNode: function () {
- var audio = new cc.Audio(this.src);
- if (this._AUDIO_TYPE === "AUDIO") {
- var elem = document.createElement("audio");
- var sources = elem.getElementsByTagName('source');
- for (var i=0; i<sources.length; i++) {
- elem.appendChild(sources[i]);
- }
- elem.src = this.src;
- audio.setElement(elem);
- } else {
- audio.setBuffer(this._element.buffer);
- }
- return audio;
- }
- });
- cc.Audio.touchPlayList = [
- ];
- cc.Audio.bindTouch = false;
- cc.Audio.touchStart = function () {
- var list = cc.Audio.touchPlayList;
- var item = null;
- while (item = list.pop()) {
- item.audio.loop = !!item.loop;
- item.audio.play(item.offset);
- }
- };
- cc.Audio.WebAudio = function (buffer) {
- this.buffer = buffer;
- this.context = cc.Audio._context;
- var volume = this.context['createGain']();
- volume['gain'].value = 1;
- volume['connect'](this.context['destination']);
- this._volume = volume;
- this._loop = false;
- this._startTime = -1;
- this._currentSource = null;
- this.playedLength = 0;
- this._currextTimer = null;
- };
- cc.Audio.WebAudio.prototype = {
- constructor: cc.Audio.WebAudio,
- get paused () {
- if (this._currentSource && this._currentSource.loop)
- return false;
- if (this._startTime === -1)
- return true;
- return this.context.currentTime - this._startTime > this.buffer.duration;
- },
- set paused (bool) {},
- get loop () { return this._loop; },
- set loop (bool) { return this._loop = bool; },
- get volume () { return this._volume['gain'].value; },
- set volume (num) { return this._volume['gain'].value = num; },
- get currentTime () { return this.playedLength; },
- set currentTime (num) { return this.playedLength = num; },
- play: function (offset) {
- if (this._currentSource && !this.paused) {
- this._currentSource.stop(0);
- this.playedLength = 0;
- }
- var audio = this.context["createBufferSource"]();
- audio.buffer = this.buffer;
- audio["connect"](this._volume);
- audio.loop = this._loop;
- this._startTime = this.context.currentTime;
- offset = offset || this.playedLength;
- var duration = this.buffer.duration;
- if (!this._loop) {
- if (audio.start)
- audio.start(0, offset, duration - offset);
- else if (audio["notoGrainOn"])
- audio["noteGrainOn"](0, offset, duration - offset);
- else
- audio["noteOn"](0, offset, duration - offset);
- } else {
- if (audio.start)
- audio.start(0);
- else if (audio["notoGrainOn"])
- audio["noteGrainOn"](0);
- else
- audio["noteOn"](0);
- }
- this._currentSource = audio;
- if (this.context.currentTime === 0) {
- var self = this;
- clearTimeout(this._currextTimer);
- this._currextTimer = setTimeout(function () {
- if (self.context.currentTime === 0) {
- cc.Audio.touchPlayList.push({
- offset: offset,
- audio: self
- });
- }
- }, 10);
- }
- },
- pause: function () {
- this.playedLength = this.context.currentTime - this._startTime;
- this.playedLength %= this.buffer.duration;
- var audio = this._currentSource;
- this._currentSource = null;
- this._startTime = -1;
- if (audio)
- audio.stop(0);
- }
- };
- (function(polyfill){
- var SWA = polyfill.WEB_AUDIO, SWB = polyfill.ONLY_ONE;
- var support = [];
- (function(){
- var audio = document.createElement("audio");
- if(audio.canPlayType) {
- var ogg = audio.canPlayType('audio/ogg; codecs="vorbis"');
- if (ogg && ogg !== "") support.push(".ogg");
- var mp3 = audio.canPlayType("audio/mpeg");
- if (mp3 && mp3 !== "") support.push(".mp3");
- var wav = audio.canPlayType('audio/wav; codecs="1"');
- if (wav && wav !== "") support.push(".wav");
- var mp4 = audio.canPlayType("audio/mp4");
- if (mp4 && mp4 !== "") support.push(".mp4");
- var m4a = audio.canPlayType("audio/x-m4a");
- if (m4a && m4a !== "") support.push(".m4a");
- }
- })();
- try{
- if(SWA){
- var context = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)();
- cc.Audio._context = context;
- if(polyfill.DELAY_CREATE_CTX)
- setTimeout(function(){
- context = new (window.AudioContext || window.webkitAudioContext || window.mozAudioContext)();
- cc.Audio._context = context;
- }, 0);
- }
- }catch(error){
- SWA = false;
- cc.log("browser don't support web audio");
- }
- var loader = {
- cache: {},
- useWebAudio: false,
- loadBuffer: function (url, cb) {
- if (!SWA) return;
- var request = new XMLHttpRequest();
- request.open("GET", url, true);
- request.responseType = "arraybuffer";
- request.onload = function () {
- context["decodeAudioData"](request.response, function(buffer){
- cb(null, buffer);
- }, function(){
- cb('decode error - ' + url);
- });
- };
- request.onerror = function(){
- cb('request error - ' + url);
- };
- request.send();
- },
- load: function(realUrl, url, res, cb){
- if(support.length === 0)
- return cb("can not support audio!");
- var audio = cc.loader.getRes(url);
- if (audio)
- return cb(null, audio);
- var i;
- if(cc.loader.audioPath)
- realUrl = cc.path.join(cc.loader.audioPath, realUrl);
- var extname = cc.path.extname(realUrl);
- var typeList = [extname];
- for(i=0; i<support.length; i++){
- if(extname !== support[i]){
- typeList.push(support[i]);
- }
- }
- audio = new cc.Audio(realUrl);
- cc.loader.cache[url] = audio;
- this.loadAudioFromExtList(realUrl, typeList, audio, cb);
- return audio;
- },
- loadAudioFromExtList: function(realUrl, typeList, audio, cb){
- if(typeList.length === 0){
- var ERRSTR = "can not found the resource of audio! Last match url is : ";
- ERRSTR += realUrl.replace(/\.(.*)?$/, "(");
- support.forEach(function(ext){
- ERRSTR += ext + "|";
- });
- ERRSTR = ERRSTR.replace(/\|$/, ")");
- return cb({status:520, errorMessage:ERRSTR}, null);
- }
- if (SWA && this.useWebAudio) {
- this.loadBuffer(realUrl, function (error, buffer) {
- if (error)
- cc.log(error);
- if (buffer)
- audio.setBuffer(buffer);
- cb(null, audio);
- });
- return;
- }
- var num = polyfill.ONE_SOURCE ? 1 : typeList.length;
- var dom = document.createElement('audio');
- for (var i=0; i<num; i++) {
- var source = document.createElement('source');
- source.src = cc.path.changeExtname(realUrl, typeList[i]);
- dom.appendChild(source);
- }
- audio.setElement(dom);
- var timer = setTimeout(function(){
- if (dom.readyState === 0) {
- failure();
- } else {
- success();
- }
- }, 8000);
- var success = function () {
- dom.removeEventListener("canplaythrough", success, false);
- dom.removeEventListener("error", failure, false);
- dom.removeEventListener("emptied", success, false);
- if (polyfill.USE_LOADER_EVENT)
- dom.removeEventListener(polyfill.USE_LOADER_EVENT, success, false);
- clearTimeout(timer);
- cb(null, audio);
- };
- var failure = function () {
- cc.log('load audio failure - ' + realUrl);
- success();
- };
- dom.addEventListener("canplaythrough", success, false);
- dom.addEventListener("error", failure, false);
- if(polyfill.USE_LOADER_EVENT)
- dom.addEventListener(polyfill.USE_LOADER_EVENT, success, false);
- }
- };
- cc.loader.register(["mp3", "ogg", "wav", "mp4", "m4a"], loader);
- cc.audioEngine = {
- _currMusic: null,
- _musicVolume: 1,
- features: polyfill,
- willPlayMusic: function(){return false;},
- playMusic: function(url, loop){
- var bgMusic = this._currMusic;
- if (bgMusic && bgMusic.getPlaying()) {
- bgMusic.stop();
- }
- var audio = cc.loader.getRes(url);
- if (!audio) {
- cc.loader.load(url);
- audio = cc.loader.getRes(url);
- }
- audio.setVolume(this._musicVolume);
- audio.play(0, loop || false);
- this._currMusic = audio;
- },
- stopMusic: function(releaseData){
- var audio = this._currMusic;
- if (audio) {
- audio.stop();
- this._currMusic = null;
- if (releaseData)
- cc.loader.release(audio.src);
- }
- },
- pauseMusic: function(){
- var audio = this._currMusic;
- if (audio)
- audio.pause();
- },
- resumeMusic: function(){
- var audio = this._currMusic;
- if (audio)
- audio.resume();
- },
- rewindMusic: function(){
- var audio = this._currMusic;
- if (audio){
- audio.stop();
- audio.play();
- }
- },
- getMusicVolume: function(){
- return this._musicVolume;
- },
- setMusicVolume: function(volume){
- volume = volume - 0;
- if (isNaN(volume)) volume = 1;
- if (volume > 1) volume = 1;
- if (volume < 0) volume = 0;
- this._musicVolume = volume;
- var audio = this._currMusic;
- if (audio) {
- audio.setVolume(volume);
- }
- },
- isMusicPlaying: function(){
- var audio = this._currMusic;
- if (audio) {
- return audio.getPlaying();
- } else {
- return false;
- }
- },
- _audioPool: {},
- _maxAudioInstance: 10,
- _effectVolume: 1,
- playEffect: function(url, loop){
- if (SWB && this._currMusic && this._currMusic.getPlaying()) {
- cc.log('Browser is only allowed to play one audio');
- return null;
- }
- var effectList = this._audioPool[url];
- if (!effectList) {
- effectList = this._audioPool[url] = [];
- }
- var i;
- for (i = 0; i < effectList.length; i++) {
- if (!effectList[i].getPlaying()) {
- break;
- }
- }
- if (!SWA && i > this._maxAudioInstance) {
- var first = effectList.shift();
- first.stop();
- effectList.push(first);
- i = effectList.length - 1;
- }
- var audio;
- if (effectList[i]) {
- audio = effectList[i];
- audio.setVolume(this._effectVolume);
- audio.play(0, loop || false);
- return audio;
- }
- audio = cc.loader.getRes(url);
- if (audio && SWA && audio._AUDIO_TYPE === 'AUDIO') {
- cc.loader.release(url);
- audio = null;
- }
- if (audio) {
- if (SWA && audio._AUDIO_TYPE === 'AUDIO') {
- loader.loadBuffer(url, function (error, buffer) {
- audio.setBuffer(buffer);
- audio.setVolume(cc.audioEngine._effectVolume);
- if (!audio.getPlaying())
- audio.play(0, loop || false);
- });
- } else {
- audio = audio.cloneNode();
- audio.setVolume(this._effectVolume);
- audio.play(0, loop || false);
- effectList.push(audio);
- return audio;
- }
- }
- loader.useWebAudio = true;
- cc.loader.load(url, function (audio) {
- audio = cc.loader.getRes(url);
- audio = audio.cloneNode();
- audio.setVolume(cc.audioEngine._effectVolume);
- audio.play(0, loop || false);
- effectList.push(audio);
- });
- loader.useWebAudio = false;
- return audio;
- },
- setEffectsVolume: function(volume){
- volume = volume - 0;
- if(isNaN(volume)) volume = 1;
- if(volume > 1) volume = 1;
- if(volume < 0) volume = 0;
- this._effectVolume = volume;
- var audioPool = this._audioPool;
- for(var p in audioPool){
- var audioList = audioPool[p];
- if(Array.isArray(audioList))
- for(var i=0; i<audioList.length; i++){
- audioList[i].setVolume(volume);
- }
- }
- },
- getEffectsVolume: function(){
- return this._effectVolume;
- },
- pauseEffect: function(audio){
- if(audio){
- audio.pause();
- }
- },
- pauseAllEffects: function(){
- var ap = this._audioPool;
- for(var p in ap){
- var list = ap[p];
- for(var i=0; i<ap[p].length; i++){
- if(list[i].getPlaying()){
- list[i].pause();
- }
- }
- }
- },
- resumeEffect: function(audio){
- if(audio)
- audio.resume();
- },
- resumeAllEffects: function(){
- var ap = this._audioPool;
- for(var p in ap){
- var list = ap[p];
- for(var i=0; i<ap[p].length; i++){
- list[i].resume();
- }
- }
- },
- stopEffect: function(audio){
- if(audio) {
- audio.stop();
- }
- },
- stopAllEffects: function(){
- var ap = this._audioPool;
- for(var p in ap){
- var list = ap[p];
- for(var i=0; i<list.length; i++){
- list[i].stop();
- }
- list.length = 0;
- }
- },
- unloadEffect: function(url){
- if(!url){
- return;
- }
- cc.loader.release(url);
- var pool = this._audioPool[url];
- if(pool) pool.length = 0;
- delete this._audioPool[url];
- },
- end: function(){
- this.stopMusic();
- this.stopAllEffects();
- },
- _pauseCache: [],
- _pausePlaying: function(){
- var bgMusic = this._currMusic;
- if(bgMusic && bgMusic.getPlaying()){
- bgMusic.pause();
- this._pauseCache.push(bgMusic);
- }
- var ap = this._audioPool;
- for(var p in ap){
- var list = ap[p];
- for(var i=0; i<ap[p].length; i++){
- if(list[i].getPlaying()){
- list[i].pause();
- this._pauseCache.push(list[i]);
- }
- }
- }
- },
- _resumePlaying: function(){
- var list = this._pauseCache;
- for(var i=0; i<list.length; i++){
- list[i].resume();
- }
- list.length = 0;
- }
- };
- })(window.__audioSupport);
- cc._globalFontSize = cc.ITEM_SIZE;
- cc._globalFontName = "Arial";
- cc._globalFontNameRelease = false;
- cc.MenuItem = cc.Node.extend({
- _enabled: false,
- _target: null,
- _callback: null,
- _isSelected: false,
- _className: "MenuItem",
- ctor: function (callback, target) {
- var nodeP = cc.Node.prototype;
- nodeP.ctor.call(this);
- this._target = null;
- this._callback = null;
- this._isSelected = false;
- this._enabled = false;
- nodeP.setAnchorPoint.call(this, 0.5, 0.5);
- this._target = target || null;
- this._callback = callback || null;
- if (this._callback) {
- this._enabled = true;
- }
- },
- isSelected: function () {
- return this._isSelected;
- },
- setOpacityModifyRGB: function (value) {
- },
- isOpacityModifyRGB: function () {
- return false;
- },
- setTarget: function (selector, rec) {
- this._target = rec;
- this._callback = selector;
- },
- isEnabled: function () {
- return this._enabled;
- },
- setEnabled: function (enable) {
- this._enabled = enable;
- },
- initWithCallback: function (callback, target) {
- this.anchorX = 0.5;
- this.anchorY = 0.5;
- this._target = target;
- this._callback = callback;
- this._enabled = true;
- this._isSelected = false;
- return true;
- },
- rect: function () {
- var locPosition = this._position, locContentSize = this._contentSize, locAnchorPoint = this._anchorPoint;
- return cc.rect(locPosition.x - locContentSize.width * locAnchorPoint.x,
- locPosition.y - locContentSize.height * locAnchorPoint.y,
- locContentSize.width, locContentSize.height);
- },
- selected: function () {
- this._isSelected = true;
- },
- unselected: function () {
- this._isSelected = false;
- },
- setCallback: function (callback, target) {
- this._target = target;
- this._callback = callback;
- },
- activate: function () {
- if (this._enabled) {
- var locTarget = this._target, locCallback = this._callback;
- if (!locCallback)
- return;
- if (locTarget && cc.isString(locCallback)) {
- locTarget[locCallback](this);
- } else if (locTarget && cc.isFunction(locCallback)) {
- locCallback.call(locTarget, this);
- } else
- locCallback(this);
- }
- }
- });
- var _p = cc.MenuItem.prototype;
- _p.enabled;
- cc.defineGetterSetter(_p, "enabled", _p.isEnabled, _p.setEnabled);
- cc.MenuItem.create = function (callback, target) {
- return new cc.MenuItem(callback, target);
- };
- cc.MenuItemLabel = cc.MenuItem.extend({
- _disabledColor: null,
- _label: null,
- _originalScale: 0,
- _colorBackup: null,
- ctor: function (label, selector, target) {
- cc.MenuItem.prototype.ctor.call(this, selector, target);
- this._disabledColor = null;
- this._label = null;
- this._colorBackup = null;
- if (label) {
- this._originalScale = 1.0;
- this._colorBackup = cc.color.WHITE;
- this._disabledColor = cc.color(126, 126, 126);
- this.setLabel(label);
- if (label.textureLoaded && !label.textureLoaded()) {
- label.addEventListener("load", function (sender) {
- this.width = sender.width;
- this.height = sender.height;
- if (this.parent instanceof cc.Menu) {
- this.parent.updateAlign();
- }
- }, this);
- }
- this.setCascadeColorEnabled(true);
- this.setCascadeOpacityEnabled(true);
- }
- },
- getDisabledColor: function () {
- return this._disabledColor;
- },
- setDisabledColor: function (color) {
- this._disabledColor = color;
- },
- getLabel: function () {
- return this._label;
- },
- setLabel: function (label) {
- if (label) {
- this.addChild(label);
- label.anchorX = 0;
- label.anchorY = 0;
- this.width = label.width;
- this.height = label.height;
- label.setCascadeColorEnabled(true);
- }
- if (this._label) {
- this.removeChild(this._label, true);
- }
- this._label = label;
- },
- setEnabled: function (enabled) {
- if (this._enabled !== enabled) {
- if (!enabled) {
- this._colorBackup = this.color;
- this.setColor(this._disabledColor);
- } else {
- this.setColor(this._colorBackup);
- }
- }
- cc.MenuItem.prototype.setEnabled.call(this, enabled);
- },
- initWithLabel: function (label, selector, target) {
- this.initWithCallback(selector, target);
- this._originalScale = 1.0;
- this._colorBackup = cc.color.WHITE;
- this._disabledColor = cc.color(126, 126, 126);
- this.setLabel(label);
- this.setCascadeColorEnabled(true);
- this.setCascadeOpacityEnabled(true);
- return true;
- },
- setString: function (label) {
- this._label.string = label;
- this.width = this._label.width;
- this.height = this._label.height;
- },
- getString: function () {
- return this._label.string;
- },
- activate: function () {
- if (this._enabled) {
- this.stopAllActions();
- this.scale = this._originalScale;
- cc.MenuItem.prototype.activate.call(this);
- }
- },
- selected: function () {
- if (this._enabled) {
- cc.MenuItem.prototype.selected.call(this);
- var action = this.getActionByTag(cc.ZOOM_ACTION_TAG);
- if (action)
- this.stopAction(action);
- else
- this._originalScale = this.scale;
- var zoomAction = cc.scaleTo(0.1, this._originalScale * 1.2);
- zoomAction.setTag(cc.ZOOM_ACTION_TAG);
- this.runAction(zoomAction);
- }
- },
- unselected: function () {
- if (this._enabled) {
- cc.MenuItem.prototype.unselected.call(this);
- this.stopActionByTag(cc.ZOOM_ACTION_TAG);
- var zoomAction = cc.scaleTo(0.1, this._originalScale);
- zoomAction.setTag(cc.ZOOM_ACTION_TAG);
- this.runAction(zoomAction);
- }
- }
- });
- var _p = cc.MenuItemLabel.prototype;
- _p.string;
- cc.defineGetterSetter(_p, "string", _p.getString, _p.setString);
- _p.disabledColor;
- cc.defineGetterSetter(_p, "disabledColor", _p.getDisabledColor, _p.setDisabledColor);
- _p.label;
- cc.defineGetterSetter(_p, "label", _p.getLabel, _p.setLabel);
- cc.MenuItemLabel.create = function (label, selector, target) {
- return new cc.MenuItemLabel(label, selector, target);
- };
- cc.MenuItemAtlasFont = cc.MenuItemLabel.extend({
- ctor: function (value, charMapFile, itemWidth, itemHeight, startCharMap, callback, target) {
- var label;
- if (value && value.length > 0) {
- label = new cc.LabelAtlas(value, charMapFile, itemWidth, itemHeight, startCharMap);
- }
- cc.MenuItemLabel.prototype.ctor.call(this, label, callback, target);
- },
- initWithString: function (value, charMapFile, itemWidth, itemHeight, startCharMap, callback, target) {
- if (!value || value.length === 0)
- throw new Error("cc.MenuItemAtlasFont.initWithString(): value should be non-null and its length should be greater than 0");
- var label = new cc.LabelAtlas();
- label.initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap);
- if (this.initWithLabel(label, callback, target)) {
- }
- return true;
- }
- });
- cc.MenuItemAtlasFont.create = function (value, charMapFile, itemWidth, itemHeight, startCharMap, callback, target) {
- return new cc.MenuItemAtlasFont(value, charMapFile, itemWidth, itemHeight, startCharMap, callback, target);
- };
- cc.MenuItemFont = cc.MenuItemLabel.extend({
- _fontSize: null,
- _fontName: null,
- ctor: function (value, callback, target) {
- var label;
- if (value && value.length > 0) {
- this._fontName = cc._globalFontName;
- this._fontSize = cc._globalFontSize;
- label = new cc.LabelTTF(value, this._fontName, this._fontSize);
- }
- else {
- this._fontSize = 0;
- this._fontName = "";
- }
- cc.MenuItemLabel.prototype.ctor.call(this, label, callback, target);
- },
- initWithString: function (value, callback, target) {
- if (!value || value.length === 0)
- throw new Error("Value should be non-null and its length should be greater than 0");
- this._fontName = cc._globalFontName;
- this._fontSize = cc._globalFontSize;
- var label = new cc.LabelTTF(value, this._fontName, this._fontSize);
- if (this.initWithLabel(label, callback, target)) {
- }
- return true;
- },
- setFontSize: function (s) {
- this._fontSize = s;
- this._recreateLabel();
- },
- getFontSize: function () {
- return this._fontSize;
- },
- setFontName: function (name) {
- this._fontName = name;
- this._recreateLabel();
- },
- getFontName: function () {
- return this._fontName;
- },
- _recreateLabel: function () {
- var label = new cc.LabelTTF(this._label.string, this._fontName, this._fontSize);
- this.setLabel(label);
- }
- });
- cc.MenuItemFont.setFontSize = function (fontSize) {
- cc._globalFontSize = fontSize;
- };
- cc.MenuItemFont.fontSize = function () {
- return cc._globalFontSize;
- };
- cc.MenuItemFont.setFontName = function (name) {
- if (cc._globalFontNameRelease) {
- cc._globalFontName = '';
- }
- cc._globalFontName = name;
- cc._globalFontNameRelease = true;
- };
- var _p = cc.MenuItemFont.prototype;
- _p.fontSize;
- cc.defineGetterSetter(_p, "fontSize", _p.getFontSize, _p.setFontSize);
- _p.fontName;
- cc.defineGetterSetter(_p, "fontName", _p.getFontName, _p.setFontName);
- cc.MenuItemFont.fontName = function () {
- return cc._globalFontName;
- };
- cc.MenuItemFont.create = function (value, callback, target) {
- return new cc.MenuItemFont(value, callback, target);
- };
- cc.MenuItemSprite = cc.MenuItem.extend({
- _normalImage: null,
- _selectedImage: null,
- _disabledImage: null,
- ctor: function (normalSprite, selectedSprite, three, four, five) {
- cc.MenuItem.prototype.ctor.call(this);
- this._normalImage = null;
- this._selectedImage = null;
- this._disabledImage = null;
- this._loader = new cc.Sprite.LoadManager();
- if (normalSprite !== undefined) {
- selectedSprite = selectedSprite || null;
- var disabledImage, target, callback;
- if (five !== undefined) {
- disabledImage = three;
- callback = four;
- target = five;
- } else if (four !== undefined && cc.isFunction(four)) {
- disabledImage = three;
- callback = four;
- } else if (four !== undefined && cc.isFunction(three)) {
- target = four;
- callback = three;
- disabledImage = null;
- } else if (three === undefined) {
- disabledImage = null;
- }
- this._loader.clear();
- if (normalSprite.textureLoaded && !normalSprite.textureLoaded()) {
- this._loader.once(normalSprite, function () {
- this.initWithNormalSprite(normalSprite, selectedSprite, disabledImage, callback, target);
- }, this);
- return false;
- }
- this.initWithNormalSprite(normalSprite, selectedSprite, disabledImage, callback, target);
- return true;
- }
- },
- getNormalImage: function () {
- return this._normalImage;
- },
- setNormalImage: function (normalImage) {
- if (this._normalImage === normalImage) {
- return;
- }
- if (normalImage) {
- this.addChild(normalImage, 0, cc.NORMAL_TAG);
- normalImage.anchorX = 0;
- normalImage.anchorY = 0;
- }
- if (this._normalImage) {
- this.removeChild(this._normalImage, true);
- }
- this._normalImage = normalImage;
- if(!this._normalImage)
- return;
- this.width = this._normalImage.width;
- this.height = this._normalImage.height;
- this._updateImagesVisibility();
- if (normalImage.textureLoaded && !normalImage.textureLoaded()) {
- normalImage.addEventListener("load", function (sender) {
- this.width = sender.width;
- this.height = sender.height;
- if (this.parent instanceof cc.Menu) {
- this.parent.updateAlign();
- }
- }, this);
- }
- },
- getSelectedImage: function () {
- return this._selectedImage;
- },
- setSelectedImage: function (selectedImage) {
- if (this._selectedImage === selectedImage)
- return;
- if (selectedImage) {
- this.addChild(selectedImage, 0, cc.SELECTED_TAG);
- selectedImage.anchorX = 0;
- selectedImage.anchorY = 0;
- }
- if (this._selectedImage) {
- this.removeChild(this._selectedImage, true);
- }
- this._selectedImage = selectedImage;
- this._updateImagesVisibility();
- },
- getDisabledImage: function () {
- return this._disabledImage;
- },
- setDisabledImage: function (disabledImage) {
- if (this._disabledImage === disabledImage)
- return;
- if (disabledImage) {
- this.addChild(disabledImage, 0, cc.DISABLE_TAG);
- disabledImage.anchorX = 0;
- disabledImage.anchorY = 0;
- }
- if (this._disabledImage)
- this.removeChild(this._disabledImage, true);
- this._disabledImage = disabledImage;
- this._updateImagesVisibility();
- },
- initWithNormalSprite: function (normalSprite, selectedSprite, disabledSprite, callback, target) {
- this._loader.clear();
- if (normalSprite.textureLoaded && !normalSprite.textureLoaded()) {
- this._loader.once(normalSprite, function () {
- this.initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback, target);
- }, this);
- return false;
- }
- this.initWithCallback(callback, target);
- this.setNormalImage(normalSprite);
- this.setSelectedImage(selectedSprite);
- this.setDisabledImage(disabledSprite);
- var locNormalImage = this._normalImage;
- if (locNormalImage) {
- this.width = locNormalImage.width;
- this.height = locNormalImage.height;
- }
- this.setCascadeColorEnabled(true);
- this.setCascadeOpacityEnabled(true);
- return true;
- },
- selected: function () {
- cc.MenuItem.prototype.selected.call(this);
- if (this._normalImage) {
- if (this._disabledImage)
- this._disabledImage.visible = false;
- if (this._selectedImage) {
- this._normalImage.visible = false;
- this._selectedImage.visible = true;
- } else
- this._normalImage.visible = true;
- }
- },
- unselected: function () {
- cc.MenuItem.prototype.unselected.call(this);
- if (this._normalImage) {
- this._normalImage.visible = true;
- if (this._selectedImage)
- this._selectedImage.visible = false;
- if (this._disabledImage)
- this._disabledImage.visible = false;
- }
- },
- setEnabled: function (bEnabled) {
- if (this._enabled !== bEnabled) {
- cc.MenuItem.prototype.setEnabled.call(this, bEnabled);
- this._updateImagesVisibility();
- }
- },
- _updateImagesVisibility: function () {
- var locNormalImage = this._normalImage, locSelImage = this._selectedImage, locDisImage = this._disabledImage;
- if (this._enabled) {
- if (locNormalImage)
- locNormalImage.visible = true;
- if (locSelImage)
- locSelImage.visible = false;
- if (locDisImage)
- locDisImage.visible = false;
- } else {
- if (locDisImage) {
- if (locNormalImage)
- locNormalImage.visible = false;
- if (locSelImage)
- locSelImage.visible = false;
- if (locDisImage)
- locDisImage.visible = true;
- } else {
- if (locNormalImage)
- locNormalImage.visible = true;
- if (locSelImage)
- locSelImage.visible = false;
- }
- }
- }
- });
- var _p = cc.MenuItemSprite.prototype;
- _p.normalImage;
- cc.defineGetterSetter(_p, "normalImage", _p.getNormalImage, _p.setNormalImage);
- _p.selectedImage;
- cc.defineGetterSetter(_p, "selectedImage", _p.getSelectedImage, _p.setSelectedImage);
- _p.disabledImage;
- cc.defineGetterSetter(_p, "disabledImage", _p.getDisabledImage, _p.setDisabledImage);
- cc.MenuItemSprite.create = function (normalSprite, selectedSprite, three, four, five) {
- return new cc.MenuItemSprite(normalSprite, selectedSprite, three, four, five || undefined);
- };
- cc.MenuItemImage = cc.MenuItemSprite.extend({
- ctor: function (normalImage, selectedImage, three, four, five) {
- var normalSprite = null,
- selectedSprite = null,
- disabledSprite = null,
- callback = null,
- target = null;
- if (normalImage === undefined || normalImage === null) {
- cc.MenuItemSprite.prototype.ctor.call(this);
- }
- else {
- normalSprite = new cc.Sprite(normalImage);
- selectedImage &&
- (selectedSprite = new cc.Sprite(selectedImage));
- if (four === undefined) {
- callback = three;
- }
- else if (five === undefined) {
- callback = three;
- target = four;
- }
- else if (five) {
- disabledSprite = new cc.Sprite(three);
- callback = four;
- target = five;
- }
- cc.MenuItemSprite.prototype.ctor.call(this, normalSprite, selectedSprite, disabledSprite, callback, target);
- }
- },
- setNormalSpriteFrame: function (frame) {
- this.setNormalImage(new cc.Sprite(frame));
- },
- setSelectedSpriteFrame: function (frame) {
- this.setSelectedImage(new cc.Sprite(frame));
- },
- setDisabledSpriteFrame: function (frame) {
- this.setDisabledImage(new cc.Sprite(frame));
- },
- initWithNormalImage: function (normalImage, selectedImage, disabledImage, callback, target) {
- var normalSprite = null;
- var selectedSprite = null;
- var disabledSprite = null;
- if (normalImage) {
- normalSprite = new cc.Sprite(normalImage);
- }
- if (selectedImage) {
- selectedSprite = new cc.Sprite(selectedImage);
- }
- if (disabledImage) {
- disabledSprite = new cc.Sprite(disabledImage);
- }
- return this.initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, callback, target);
- }
- });
- cc.MenuItemImage.create = function (normalImage, selectedImage, three, four, five) {
- return new cc.MenuItemImage(normalImage, selectedImage, three, four, five);
- };
- cc.MenuItemToggle = cc.MenuItem.extend({
- subItems: null,
- _selectedIndex: 0,
- _opacity: null,
- _color: null,
- ctor: function () {
- cc.MenuItem.prototype.ctor.call(this);
- this._selectedIndex = 0;
- this.subItems = [];
- this._opacity = 0;
- this._color = cc.color.WHITE;
- if(arguments.length > 0)
- this.initWithItems(Array.prototype.slice.apply(arguments));
- },
- getOpacity: function () {
- return this._opacity;
- },
- setOpacity: function (opacity) {
- this._opacity = opacity;
- if (this.subItems && this.subItems.length > 0) {
- for (var it = 0; it < this.subItems.length; it++) {
- this.subItems[it].opacity = opacity;
- }
- }
- this._color.a = opacity;
- },
- getColor: function () {
- var locColor = this._color;
- return cc.color(locColor.r, locColor.g, locColor.b, locColor.a);
- },
- setColor: function (color) {
- var locColor = this._color;
- locColor.r = color.r;
- locColor.g = color.g;
- locColor.b = color.b;
- if (this.subItems && this.subItems.length > 0) {
- for (var it = 0; it < this.subItems.length; it++) {
- this.subItems[it].setColor(color);
- }
- }
- if (color.a !== undefined && !color.a_undefined) {
- this.setOpacity(color.a);
- }
- },
- getSelectedIndex: function () {
- return this._selectedIndex;
- },
- setSelectedIndex: function (SelectedIndex) {
- if (SelectedIndex !== this._selectedIndex) {
- this._selectedIndex = SelectedIndex;
- var currItem = this.getChildByTag(cc.CURRENT_ITEM);
- if (currItem)
- currItem.removeFromParent(false);
- var item = this.subItems[this._selectedIndex];
- this.addChild(item, 0, cc.CURRENT_ITEM);
- var w = item.width, h = item.height;
- this.width = w;
- this.height = h;
- item.setPosition(w / 2, h / 2);
- }
- },
- getSubItems: function () {
- return this.subItems;
- },
- setSubItems: function (subItems) {
- this.subItems = subItems;
- },
- initWithItems: function (args) {
- var l = args.length;
- if (cc.isFunction(args[args.length - 2])) {
- this.initWithCallback(args[args.length - 2], args[args.length - 1]);
- l = l - 2;
- } else if (cc.isFunction(args[args.length - 1])) {
- this.initWithCallback(args[args.length - 1], null);
- l = l - 1;
- } else {
- this.initWithCallback(null, null);
- }
- var locSubItems = this.subItems;
- locSubItems.length = 0;
- for (var i = 0; i < l; i++) {
- if (args[i])
- locSubItems.push(args[i]);
- }
- this._selectedIndex = cc.UINT_MAX;
- this.setSelectedIndex(0);
- this.setCascadeColorEnabled(true);
- this.setCascadeOpacityEnabled(true);
- return true;
- },
- addSubItem: function (item) {
- this.subItems.push(item);
- },
- activate: function () {
- if (this._enabled) {
- var newIndex = (this._selectedIndex + 1) % this.subItems.length;
- this.setSelectedIndex(newIndex);
- }
- cc.MenuItem.prototype.activate.call(this);
- },
- selected: function () {
- cc.MenuItem.prototype.selected.call(this);
- this.subItems[this._selectedIndex].selected();
- },
- unselected: function () {
- cc.MenuItem.prototype.unselected.call(this);
- this.subItems[this._selectedIndex].unselected();
- },
- setEnabled: function (enabled) {
- if (this._enabled !== enabled) {
- cc.MenuItem.prototype.setEnabled.call(this, enabled);
- var locItems = this.subItems;
- if (locItems && locItems.length > 0) {
- for (var it = 0; it < locItems.length; it++)
- locItems[it].enabled = enabled;
- }
- }
- },
- selectedItem: function () {
- return this.subItems[this._selectedIndex];
- },
- getSelectedItem: function() {
- return this.subItems[this._selectedIndex];
- },
- onEnter: function () {
- cc.Node.prototype.onEnter.call(this);
- this.setSelectedIndex(this._selectedIndex);
- }
- });
- var _p = cc.MenuItemToggle.prototype;
- _p.selectedIndex;
- cc.defineGetterSetter(_p, "selectedIndex", _p.getSelectedIndex, _p.setSelectedIndex);
- cc.MenuItemToggle.create = function () {
- if ((arguments.length > 0) && (arguments[arguments.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var ret = new cc.MenuItemToggle();
- ret.initWithItems(Array.prototype.slice.apply(arguments));
- return ret;
- };
- cc.MENU_STATE_WAITING = 0;
- cc.MENU_STATE_TRACKING_TOUCH = 1;
- cc.MENU_HANDLER_PRIORITY = -128;
- cc.DEFAULT_PADDING = 5;
- cc.Menu = cc.Layer.extend({
- enabled: false,
- _selectedItem: null,
- _state: -1,
- _touchListener: null,
- _className: "Menu",
- ctor: function (menuItems) {
- cc.Layer.prototype.ctor.call(this);
- this._color = cc.color.WHITE;
- this.enabled = false;
- this._opacity = 255;
- this._selectedItem = null;
- this._state = -1;
- this._touchListener = cc.EventListener.create({
- event: cc.EventListener.TOUCH_ONE_BY_ONE,
- swallowTouches: true,
- onTouchBegan: this._onTouchBegan,
- onTouchMoved: this._onTouchMoved,
- onTouchEnded: this._onTouchEnded,
- onTouchCancelled: this._onTouchCancelled
- });
- if ((arguments.length > 0) && (arguments[arguments.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var argc = arguments.length, items;
- if (argc === 0) {
- items = [];
- } else if (argc === 1) {
- if (menuItems instanceof Array) {
- items = menuItems;
- }
- else items = [menuItems];
- }
- else if (argc > 1) {
- items = [];
- for (var i = 0; i < argc; i++) {
- if (arguments[i])
- items.push(arguments[i]);
- }
- }
- this.initWithArray(items);
- },
- onEnter: function () {
- var locListener = this._touchListener;
- if (!locListener._isRegistered())
- cc.eventManager.addListener(locListener, this);
- cc.Node.prototype.onEnter.call(this);
- },
- isEnabled: function () {
- return this.enabled;
- },
- setEnabled: function (enabled) {
- this.enabled = enabled;
- },
- initWithItems: function (args) {
- var pArray = [];
- if (args) {
- for (var i = 0; i < args.length; i++) {
- if (args[i])
- pArray.push(args[i]);
- }
- }
- return this.initWithArray(pArray);
- },
- initWithArray: function (arrayOfItems) {
- if (cc.Layer.prototype.init.call(this)) {
- this.enabled = true;
- var winSize = cc.winSize;
- this.setPosition(winSize.width / 2, winSize.height / 2);
- this.setContentSize(winSize);
- this.setAnchorPoint(0.5, 0.5);
- this.ignoreAnchorPointForPosition(true);
- if (arrayOfItems) {
- for (var i = 0; i < arrayOfItems.length; i++)
- this.addChild(arrayOfItems[i], i);
- }
- this._selectedItem = null;
- this._state = cc.MENU_STATE_WAITING;
- this.cascadeColor = true;
- this.cascadeOpacity = true;
- return true;
- }
- return false;
- },
- addChild: function (child, zOrder, tag) {
- if (!(child instanceof cc.MenuItem))
- throw new Error("cc.Menu.addChild() : Menu only supports MenuItem objects as children");
- cc.Layer.prototype.addChild.call(this, child, zOrder, tag);
- },
- updateAlign: function () {
- switch (this._align) {
- case 'vertically':
- this.alignItemsVertically();
- break;
- case 'horizontally':
- this.alignItemsHorizontally();
- break;
- }
- },
- alignItemsVertically: function () {
- this.alignItemsVerticallyWithPadding(cc.DEFAULT_PADDING);
- },
- alignItemsVerticallyWithPadding: function (padding) {
- this._align = 'vertically';
- var height = -padding, locChildren = this._children, len, i, locScaleY, locHeight, locChild;
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++)
- height += locChildren[i].height * locChildren[i].scaleY + padding;
- var y = height / 2.0;
- for (i = 0, len = locChildren.length; i < len; i++) {
- locChild = locChildren[i];
- locHeight = locChild.height;
- locScaleY = locChild.scaleY;
- locChild.setPosition(0, y - locHeight * locScaleY / 2);
- y -= locHeight * locScaleY + padding;
- }
- }
- },
- alignItemsHorizontally: function () {
- this.alignItemsHorizontallyWithPadding(cc.DEFAULT_PADDING);
- },
- alignItemsHorizontallyWithPadding: function (padding) {
- this._align = 'horizontally';
- var width = -padding, locChildren = this._children, i, len, locScaleX, locWidth, locChild;
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++)
- width += locChildren[i].width * locChildren[i].scaleX + padding;
- var x = -width / 2.0;
- for (i = 0, len = locChildren.length; i < len; i++) {
- locChild = locChildren[i];
- locScaleX = locChild.scaleX;
- locWidth = locChildren[i].width;
- locChild.setPosition(x + locWidth * locScaleX / 2, 0);
- x += locWidth * locScaleX + padding;
- }
- }
- },
- alignItemsInColumns: function () {
- if ((arguments.length > 0) && (arguments[arguments.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var rows = [];
- for (var i = 0; i < arguments.length; i++) {
- rows.push(arguments[i]);
- }
- var height = -5;
- var row = 0;
- var rowHeight = 0;
- var columnsOccupied = 0;
- var rowColumns, tmp, len;
- var locChildren = this._children;
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++) {
- if (row >= rows.length)
- continue;
- rowColumns = rows[row];
- if (!rowColumns)
- continue;
- tmp = locChildren[i].height;
- rowHeight = ((rowHeight >= tmp || isNaN(tmp)) ? rowHeight : tmp);
- ++columnsOccupied;
- if (columnsOccupied >= rowColumns) {
- height += rowHeight + 5;
- columnsOccupied = 0;
- rowHeight = 0;
- ++row;
- }
- }
- }
- var winSize = cc.director.getWinSize();
- row = 0;
- rowHeight = 0;
- rowColumns = 0;
- var w = 0.0;
- var x = 0.0;
- var y = (height / 2);
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++) {
- var child = locChildren[i];
- if (rowColumns === 0) {
- rowColumns = rows[row];
- w = winSize.width / (1 + rowColumns);
- x = w;
- }
- tmp = child._getHeight();
- rowHeight = ((rowHeight >= tmp || isNaN(tmp)) ? rowHeight : tmp);
- child.setPosition(x - winSize.width / 2, y - tmp / 2);
- x += w;
- ++columnsOccupied;
- if (columnsOccupied >= rowColumns) {
- y -= rowHeight + 5;
- columnsOccupied = 0;
- rowColumns = 0;
- rowHeight = 0;
- ++row;
- }
- }
- }
- },
- alignItemsInRows: function () {
- if ((arguments.length > 0) && (arguments[arguments.length - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var columns = [], i;
- for (i = 0; i < arguments.length; i++) {
- columns.push(arguments[i]);
- }
- var columnWidths = [];
- var columnHeights = [];
- var width = -10;
- var columnHeight = -5;
- var column = 0;
- var columnWidth = 0;
- var rowsOccupied = 0;
- var columnRows, child, len, tmp;
- var locChildren = this._children;
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++) {
- child = locChildren[i];
- if (column >= columns.length)
- continue;
- columnRows = columns[column];
- if (!columnRows)
- continue;
- tmp = child.width;
- columnWidth = ((columnWidth >= tmp || isNaN(tmp)) ? columnWidth : tmp);
- columnHeight += (child.height + 5);
- ++rowsOccupied;
- if (rowsOccupied >= columnRows) {
- columnWidths.push(columnWidth);
- columnHeights.push(columnHeight);
- width += columnWidth + 10;
- rowsOccupied = 0;
- columnWidth = 0;
- columnHeight = -5;
- ++column;
- }
- }
- }
- var winSize = cc.director.getWinSize();
- column = 0;
- columnWidth = 0;
- columnRows = 0;
- var x = -width / 2;
- var y = 0.0;
- if (locChildren && locChildren.length > 0) {
- for (i = 0, len = locChildren.length; i < len; i++) {
- child = locChildren[i];
- if (columnRows === 0) {
- columnRows = columns[column];
- y = columnHeights[column];
- }
- tmp = child._getWidth();
- columnWidth = ((columnWidth >= tmp || isNaN(tmp)) ? columnWidth : tmp);
- child.setPosition(x + columnWidths[column] / 2, y - winSize.height / 2);
- y -= child.height + 10;
- ++rowsOccupied;
- if (rowsOccupied >= columnRows) {
- x += columnWidth + 5;
- rowsOccupied = 0;
- columnRows = 0;
- columnWidth = 0;
- ++column;
- }
- }
- }
- },
- removeChild: function (child, cleanup) {
- if (child == null)
- return;
- if (!(child instanceof cc.MenuItem)) {
- cc.log("cc.Menu.removeChild():Menu only supports MenuItem objects as children");
- return;
- }
- if (this._selectedItem === child)
- this._selectedItem = null;
- cc.Node.prototype.removeChild.call(this, child, cleanup);
- },
- _onTouchBegan: function (touch, event) {
- var target = event.getCurrentTarget();
- if (target._state !== cc.MENU_STATE_WAITING || !target._visible || !target.enabled)
- return false;
- for (var c = target.parent; c != null; c = c.parent) {
- if (!c.isVisible())
- return false;
- }
- target._selectedItem = target._itemForTouch(touch);
- if (target._selectedItem) {
- target._state = cc.MENU_STATE_TRACKING_TOUCH;
- target._selectedItem.selected();
- target._selectedItem.setNodeDirty();
- return true;
- }
- return false;
- },
- _onTouchEnded: function (touch, event) {
- var target = event.getCurrentTarget();
- if (target._state !== cc.MENU_STATE_TRACKING_TOUCH) {
- cc.log("cc.Menu.onTouchEnded(): invalid state");
- return;
- }
- if (target._selectedItem) {
- target._selectedItem.unselected();
- target._selectedItem.setNodeDirty();
- target._selectedItem.activate();
- }
- target._state = cc.MENU_STATE_WAITING;
- },
- _onTouchCancelled: function (touch, event) {
- var target = event.getCurrentTarget();
- if (target._state !== cc.MENU_STATE_TRACKING_TOUCH) {
- cc.log("cc.Menu.onTouchCancelled(): invalid state");
- return;
- }
- if (target._selectedItem) {
- target._selectedItem.unselected();
- target._selectedItem.setNodeDirty();
- }
- target._state = cc.MENU_STATE_WAITING;
- },
- _onTouchMoved: function (touch, event) {
- var target = event.getCurrentTarget();
- if (target._state !== cc.MENU_STATE_TRACKING_TOUCH) {
- cc.log("cc.Menu.onTouchMoved(): invalid state");
- return;
- }
- var currentItem = target._itemForTouch(touch);
- if (currentItem !== target._selectedItem) {
- if (target._selectedItem) {
- target._selectedItem.unselected();
- target._selectedItem.setNodeDirty();
- }
- target._selectedItem = currentItem;
- if (target._selectedItem) {
- target._selectedItem.selected();
- target._selectedItem.setNodeDirty();
- }
- }
- },
- onExit: function () {
- if (this._state === cc.MENU_STATE_TRACKING_TOUCH) {
- if (this._selectedItem) {
- this._selectedItem.unselected();
- this._selectedItem = null;
- }
- this._state = cc.MENU_STATE_WAITING;
- }
- cc.Node.prototype.onExit.call(this);
- },
- setOpacityModifyRGB: function (value) {
- },
- isOpacityModifyRGB: function () {
- return false;
- },
- _itemForTouch: function (touch) {
- var touchLocation = touch.getLocation();
- var itemChildren = this._children, locItemChild;
- if (itemChildren && itemChildren.length > 0) {
- for (var i = itemChildren.length - 1; i >= 0; i--) {
- locItemChild = itemChildren[i];
- if (locItemChild.isVisible() && locItemChild.isEnabled()) {
- var local = locItemChild.convertToNodeSpace(touchLocation);
- var r = locItemChild.rect();
- r.x = 0;
- r.y = 0;
- if (cc.rectContainsPoint(r, local))
- return locItemChild;
- }
- }
- }
- return null;
- }
- });
- var _p = cc.Menu.prototype;
- _p.enabled;
- cc.Menu.create = function (menuItems) {
- var argc = arguments.length;
- if ((argc > 0) && (arguments[argc - 1] == null))
- cc.log("parameters should not be ending with null in Javascript");
- var ret;
- if (argc === 0)
- ret = new cc.Menu();
- else if (argc === 1)
- ret = new cc.Menu(menuItems);
- else
- ret = new cc.Menu(Array.prototype.slice.call(arguments, 0));
- return ret;
- };
|