From c81cf0c8828d8fb0eae13f8fcd93e1756e331b31 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 2 Jul 2013 23:41:25 +0100 Subject: [PATCH] Lots of Tilemap updates, moved the renderer out, added components and new tests. --- Docs/game art/avoid-digits.png | Bin 0 -> 1263 bytes Docs/game art/avoid-panel.png | Bin 0 -> 1434 bytes Docs/game art/avoid-sheet.png | Bin 0 -> 2823 bytes Docs/game art/avoidmock4x2.png | Bin 0 -> 9416 bytes Phaser/components/Texture.ts | 8 +- Phaser/components/TilemapLayer.ts | 261 ++----- Phaser/components/sprite/Events.ts | 12 + Phaser/components/sprite/Input.ts | 4 +- Phaser/core/Group.ts | 46 +- Phaser/gameobjects/IGameObject.ts | 5 + Phaser/gameobjects/Sprite.ts | 17 +- Phaser/gameobjects/Tilemap.ts | 86 ++- Phaser/phaser.js | 16 + Phaser/physics/Body.ts | 113 +-- Phaser/physics/ContactSolver.ts | 13 - Phaser/renderers/CanvasRenderer.ts | 132 +++- Phaser/tweens/Tween.ts | 10 + Phaser/utils/DebugUtils.ts | 7 + Phaser/utils/PointUtils.ts | 2 +- README.md | 13 +- Tests/Tests.csproj | 16 + Tests/phaser.js | 1060 +++++++++++++++------------- Tests/physics/simple test 1.js | 15 +- Tests/physics/simple test 1.ts | 6 + Tests/tilemaps/csv tilemap.js | 32 + Tests/tilemaps/csv tilemap.ts | 54 ++ Tests/tilemaps/map draw.js | 41 ++ Tests/tilemaps/map draw.ts | 60 ++ Tests/tilemaps/tiled layers.js | 34 + Tests/tilemaps/tiled layers.ts | 58 ++ Tests/tilemaps/tiled tilemap.js | 32 + Tests/tilemaps/tiled tilemap.ts | 54 ++ build/phaser.d.ts | 691 ++++++++++-------- build/phaser.js | 1060 +++++++++++++++------------- 34 files changed, 2395 insertions(+), 1563 deletions(-) create mode 100644 Docs/game art/avoid-digits.png create mode 100644 Docs/game art/avoid-panel.png create mode 100644 Docs/game art/avoid-sheet.png create mode 100644 Docs/game art/avoidmock4x2.png create mode 100644 Tests/tilemaps/csv tilemap.js create mode 100644 Tests/tilemaps/csv tilemap.ts create mode 100644 Tests/tilemaps/map draw.js create mode 100644 Tests/tilemaps/map draw.ts create mode 100644 Tests/tilemaps/tiled layers.js create mode 100644 Tests/tilemaps/tiled layers.ts create mode 100644 Tests/tilemaps/tiled tilemap.js create mode 100644 Tests/tilemaps/tiled tilemap.ts diff --git a/Docs/game art/avoid-digits.png b/Docs/game art/avoid-digits.png new file mode 100644 index 0000000000000000000000000000000000000000..c3bf0af14ff1b8a1f6878b9ec2a6cc12717964cf GIT binary patch literal 1263 zcmeAS@N?(olHy`uVBq!ia0vp^8-Q4WgBeJ+@-yi(FfcO&_=LF13d#aSl+@I%ObtE# z9mB)JGn1kci`#3f;#wxhVDGlrc{eO_YApRD5;YvIm{$DHUG{(f4ThPkH4iN) zdw=Es|Nn2#>pz++_qxdGzp342QRysg{uRp6f&zTv;^GXt45Mf?1O{6Ol*Sb;STg(5 zr^^%m2rB?H0Dp;VL`iUdT1k0gQ7VIbQDRz!(Sk+6SwN|%z1e-N3F4xF1d$KkcV7;P zV_;y^^mK6yiD-R0Z6jZ+0f%dMbGEGPpa1V`?AX26g*&WP^F4J$S3!MiuE(Vrs**(; z6Jt*XZ`_mhw)>LA^(z0CA1wEeSE&7UR6lvkgZZtp0rRH@?NauCY!%rH8cGj0*KbQ> zh)#X@YxjX`OFx?IUc&R^qU=5vD5{;1!QO4L^KMw=)L8mQBx*QZF|GKYyX^n|8w@j7YaUuq z_WsKM|Nq~f*MBru?sbvVe^a~5qS9H~{412B1qJxT#l;zP8Aj1)2n@CmD2*#xuw?e9 zPnReB5e8)p{u0-SlHmNblJdl&R0j8=#Iy>d1&e~SK)EHk$S)m8GX%tgNC9~esh|%c z4eUXrgFlE&$On-H^+1BDp&!JaFdxKTupY$TupdMoI1eH(UImfYZi2`M@4GLD#4#{1 zUh#Bs42fucJLBx8W(A(ssVqtxUaVXF```IWM-{fG%jafVzwJp+O#a)$<$l1&<(@>= zi32u*kr#9&n>Z4LFC6<~oZ+j<>=e6$sYPnb+Kxm2quCT@oag$VwK;XcsgIRv6Bn}b z7>hLQdK+Z=K<%qV!(pBXhRr--2YMNP*B;DI^b((__Bj^vhusdIU{rAWv8IQ^e$_;l8ONluF1M6r>V91` zZDp3*LVt!AHMt9?KUFiY@-ffSFgJSZe8Bemz5>(o?b4FRRPEQ)OzU=)R_9&x=UFme z;>_cHzix-l4fwa@9{U-iACV8v@|wO`bDIA?YfRmbO#2;z4$2N9p0D~nZ5a-0t>D&R zbzS-VMr3!>(r6v01$8?!Z+gc)ZVJr~db}v|^=pOccW1@3ZxMgj!*p2K$X&&&zHM7P wFV_s4>Hjoj*iyF@CwWhM>Mq^i{OHqT`~4>UG9PjSjX*K&>FVdQ&MBb@02;MhO#lD@ literal 0 HcmV?d00001 diff --git a/Docs/game art/avoid-sheet.png b/Docs/game art/avoid-sheet.png new file mode 100644 index 0000000000000000000000000000000000000000..c88ce1ba67b09632586ccc4c72073f0176200890 GIT binary patch literal 2823 zcmeIz_ct5*8wc>1wQ4kNwWYY!s$g*>d(WIM!i%mq?i@yZ0zD^Y({oNaJy$f*CHK

VmDY8MJq60eN@1^qZeijN~5}Z$Di;nc05G>O8JE=6*jp zYajLiKy?|jO%@-FJc${C2TyC&pPs~>hf}w#+%Uq~=|$GMpm@ifrG!OkwEQfza6#%% z)M-n@K`Pw+_<%VJ^ur6JP#{_AG=5WKDNh=48pM(D<+tc&*#yrRtVpvAkmdQ?-!=Vf z7aNqpH7LYjHrDE`>5(EC21aWav6Q@#qWQd)y160jHZaNn`VdAa*TSioTY|W28!Lr+ ztX}&L=(82y8a2(kBglr_#pJ*5bvfeD=1w|g zg{kw4r1z%o^+lg9HT^XwQiTeG0E9L<76piIj)Q&x&ZjIb%~GZ8w$00;3UEsY=3?%b zD9J<7WNFlexW=E;1c8hNAPFbM9uOi1Qj?dF*t(X0 z&QjyXcHJZGsk*QcGf3LCF^#--WWm0+lO$XrNo2OctAR&(mEy659F6BeOkXJ5%`ue! zSr8ULDULHVz@qyPMZ!bt*D`_#mdZuBWI3Zxy!m!72M%vB>l6fL=hyKbimn8{>@~3m z1|DaX1LgZL7@rM1EDCfiy*>qWmqaX&n1Ls0Ov9P0OPx8H2CRssJT#JfpH^li-*+9~ z6R5F+A1PKNC~Kpi7d&x6PvI3eRi_OT_8PLu$-`KQ>x!@BHB;rl>KNsm&^nOPBFLKfL`O!$N?G|+6PAP z)s-}Dp4ix&!Hny@nb;#;Vs1qsB7KS$;}0)gs=J+j^*yd^VjA{g)%)X{$k!(d-&r{x z{T+6s-N3_^JD})391f8Ykt`vVV9S{To#ES4KsFDdpEht6$g!|8rk60{|KB79M^ z_^E3|6=qp>a&)t;dA7C+K6@D8C*FKg*t5HE+DMRWEtIWxhgj%|-KZHg$~2?;j9^7u zV|ZXX@l$5m{D%rl?MuZ^OiskbG$T(l7zb;TF3WqC12=`tW8$A{9C|Z5&?t$P`=8ps zYPI&Ec2D$HcQF0&N9zkQfdk+pz5vPTga{r=ih96N1360Ii%IKea+iw9WA?qDX*G6_ z6b*y(&D`3loeLU_KHsSB4Es8QdMjw*$lsUoS8UY)qeK-zgscp6ftcWjkz`Q*!wDG_ z!!{P}#M)=PX7;C%Jr#>T(+lqie`R1QK_ExRO6Uxu{WrChl)n?TC*YGRuDFs3k(JTmpQRvKPfdKw zzVh5VFKe9s!dFh37oCyi-x|o#rKqZ|tm-v(D|ue8t%yAy>Z(dDZLl~S;@onw*s|$X z4<3dTen|D4p`j-Bj^fLWaeK73Y;~RWJeN1C7k6_szr-NgV)X6rF&bcc&mK!14b>u5<>d2__$s0cAWh1w~y)>={nZU!ReThDCdeP7$n5t?wS zkP#DFjG1h;2^VsxmW4L}K*8|uBm!i8W&r?h8N5_ed-m*wmyehC3oj^_wwf9j^tG4s zOLr##z<&X5>|$cP!=!{=IZ@S#4gI9!WyDCvWuzJ(dOL|vkei(LX)Jf%Jfk6!PD6u) z{l}MB;)I0I_l$e*X~q5;zOI`EZB=04wWGjJGRib9 zNkgen%2L(4bm)lwp1#!$QI)V;_n`nTs5~JGg=g>?1HO;|AcGF}>wsq>00@7` zuSq~C9G4kL1hD+X%}Dem3BbkR6srz+p#Z2DHG8K406zrWcGl^U1I&p49%`FAYXJ}q zfX)$GiW&eJCE%f9Y?J_iBoF}k!NcPZh|C1sesXNC_(!Occ1w_eRA!B0(|tLOFiSF# zS3q-f(Yp^uw3&r&OWWPB%Tf{TdYj2A5%!1%jTr&}z9cacW{bJIp-d;DPf0dw~^&TTpcrQ*hS)iA90`Itn622e? zp`-u^R}fKPl1PcQ1My!Sep;|k=Nc9OIBxMmPCXza4t)`^I_if%RKC*u!V3s>)=qu} z0NAMC7d81=tK3fp0H}Wn6GS{_KS8nxcaq*g-dsXbTtcKHRqyw7snV+6atyum8X`~; zuKFN)7{MV35t~xsc+_e5B02?1E!t(;NUa2=IkzLrK|W{=BPV(MgN(tBdm)y{{vDVn zfs8pb3dfDqBB77J&ovNx+wh)Fl9ZOX(K{0^Q!S2TrPnv)VyvDtCn@{@NQ7TTw`z)i z3ac?xnxd>zYbudpi+qw#G3Mwao|VY-C421kcQ&Q>(s^5Bji@tlYZVxeVWRb$}T8oQd(A2wo*o6iZLBD zNi4N74z7G+Drvl4N{6;w5>w_<;$@=z6=rc2M{3cn+ijrs)$mKT z?Rsk;7li|Bt-mn08&!Gqn=q*!zUtxmAYZ|jj4O_oc%`z^JUKPVr;_HiMwm~|%E0xE zSGdnU`s7;=iqkQ$cPqCK1=a-EiyrAVi91=jm8GSpfy=eZ4a+t6+N3M@i{V9W8Z8zV zVbqWNpYmJrYq}(k+=Oo#&l@in-zsL(Q<6We6fJWrWY23+_v`R1KFG*vw+YSB^(tO@ z+qQLnCs^#tXnxwhgkpOA44_kZWXmcyHvaM)ySl# zam9k^Cm){BynoqewSIryqtBzSfRB`qn@>k?SMMOpNUy0#ph!ViLAQT+XgGg(CQ~X~ zNqkmfD|;(@HXGFddG7yQxW1&m(Mh{z<9U(AL4B)d)N?tDLa^y`>)I#Z;NN&>TE4Xu z(-k-Ar|6gG%(!$T{?rfDmo~5>Hs?qeE9*V#gY8`GnOz!sE4vR;+ERj>gFjp;0jXl< zsmnQ@bHKd6zrHPRCclz3^7%kHxc4M&N6ZC0N;^6yxn9pODA4l~Zk#=->B8*Neem)iW+`{*QLaFag{1db z_YXC+;pVt9MQ-XtH&g}8K+Pb`rEZHy%t0*4{M#&|q0p}kYj?;D`U`rUyAE1clv$Bj zv9KMI>1_DXFlf;2m17%)QVZe1JK_WIGX}K#Wf$KKqvVf@i87B? zPJqUO*~Z1wrToU1)VxvZ=jv(dE7>mM269y*Po)GwWumT%3o^}*nw9%Roh^o@!Ems) zyUrasQNc=SPxp4z|;__QM+bHgBZsB&wLHRFqy=K21e8R$unh(PLV{ z5~laO#|(bF3Af&Madf%d6C0NvkDXJq61=N_tR<)yko-HTRqE~iUdck?&8A5H(vPjW zRJzOA@;OXdzFZy>O7d;u5y?p(U#XUH>!sAY?7IAN_8qKnimJKp^^9*2yPFCeaI5`T zannNNR=sM`w#oAcvx2}H7bkP)j^VhUa%tr`Lc{w*wLcd>%6vY|#qZO1(XS@g7e?!t zi*SH{wN<#v)hNDtyLfAz@upC;8EJ)Lv6~ z!t~Z=RPf%??7p=DSj+-dXLlYAX9qFHy{o*v$ehj?GWTG~f0I4N>t{#i(x>mG_ z4^;i_#txPog}qB9zu@~muwoTB$?41C!Xf6WnsuD@B-=Ra!qVQd*%7?XjQ3p?SHDK5vO@8PNNV3_FH5@a#IK5)xn1m#NOb=XYnvpS)HkKa;g zRT!~4ZuB{>S=?kWZ#2)UlDGBP_1RUtPMI|5Z~5GkRoP_a)^rfiRu|}u-C@s>8CgDQ zd;5n8KQo;pr?lLL3Gl-9Voy;_%dpq{S0jTh^M3pX-&ze?ZBJD8AJ3~T$4o0*UN6lZ zE`_*u`hCHSFKJ>)qasGHlTH(9)NUqbCJshZMepUvg5>1ZlwV)%To$X1I*#(?Fkk0i z4^}cWiNSEwd$S|s8RL2B$LT2@9zlgyyPbQiRf~OHeRtaj{3XS0PRuU$k$y{l9ESxc z8iS1>u8;@#7iZO{#$&}7DXb|ecoO0a%%y{*$Ra^+aye)j=>Y%%yZ}IG1ORY`CtP;` zfHw~TfL#axAfEvMFncB2_C5gshyl-ZO*HTxMfi@nDJg%u2P$^nF>(fAS@)oOeEfjS za)GWdzK2s^+Um6p9!Dm71qaw5O1$?+#pr0M*Wh;GHkwoAwno7?JoR)LKh105@c99CY!_&| z=q3?flWHoEmZV4aQKISe^t8wD+#Z~W99>)3op2L%lKIKiV(9E?+s5S%MuAV(eTNnx z?ba719dlydIH11D!H#NR&XqBW3&#t6acL$6Fa7WA5_YbxW2r1}^i^a4IPce4MbDjt-Berovoof2cBY5otiD&+-_nG6 zhYrfNa)}^Xi9|E`k8}8jcC+7Y|Fb3$z7-JSYQu40U@`76@F{~<>jSUA#TzE{s)URB zr;8JZT-5KYmkE$fC1B)`PqupW4{H5g+bu4A{t1*(-Axy6NefK$ z4*tyfEZ~VWKepxE^p6E0`7J6njKhqwFJwJ6kYj&v{yv0%zwzNk=ksF#pM=O5cvwGk3!gC-VR{ny|DFQp+HhJEw z?hY*{%h}1$*%V))L{|Svl?*wDqC|R;(n{`J+~G@mUvC5Z8FObVuauCx?d7(k`TXD3 z&~9Waw~!zBaq)jY15e%#o`(OWMCy#SFUHChOtf3l0cRP4Sb&N8Fjy_NR#x`sDQFZo z=8>!+l|w6B78k()_qJM>sARzwEu2jk%2>URZ_~gPxbEdxLuJ`6qQ_R8dXzs9lMQB-~MerWRT zE&(DhhuXnq?AYbIgt#NOC*2-yS+zk{WS-5;SJn-e*G-1+wyW)ah<#o#7vmrOWnhm{SWs<VET10X53Z9!Ld8^)dFDnqnBi5t)C$~SpPu-UoKJHn zS|XXr+be0o9VXSPvWuwMjsp=rj>6NEoa@V?T>LP};`=iIlr?Ynt|!45>Tt;b#txme zJ01ON4->0^tcf~LP%$o3qcD%&Ga?ErC4D!8KT7urUO<~9HpjZ*^u#VZ5h^u_Y#wdO zTX3A-i*nKmZwC?a;7L`)_8s=t2?wg%O_K^iP%t6ya|zQ7m_jW%252O%%SeMBsTa8#yCb$AAq7dJ z>3Gt5bThVo6|`vV%ws(2vQgv|joxBuv`eDl#qMC&Xy)HwRGi)TOPHS=EXIe%d85>| ze!ukB?Ql!YqtDGjh;45vh{rLqpw|89%!7xdAqM@gk&aRa1oojoo}NK;4#vBGADx|{ zIi>o)Ey?O|H|mkhZbcY3Y0^00{sut>r5g)LbU?VXW)ZfpLEK@~blzEb67 z38zUr4OYgtmeKZI!fy0sSI(SW#j8TQovw69dIC72UW2q}uveEDomTp4_LVcz3N4{u z+qhQ~9cgm%3yeUN5a(}zLQ^^O&u)R?Ub{WhOtH(yOzcZW;a|a$}7QiNgTOaTPJ;oUpF&*Kls;Ey70xvM=Qkb(wv_s_{Ux$Mk}36k>lFA%{FTC zDk^{z=&7$NG`;$jDm0L+y&W`Xr_FiNtgX;#uV#DxeZ(kMExc+Au;dl!$4bZl&kGl` zz`=|m3=4+r^tn{Ve*d^(Dk=(M7>C~5i|~7|Ww8n&66aR4fUoM7zF7}a^DK(ow7zG@ z-N-?L%Ar}I8=w6HQAa7t?U#rhn5uU-d~{x446k!aqQkFEjTq)bmxQlI z&$G=z0^5v{SSB3UwtWg1FA=U>3z{pKKW#fKG9yE?<4s!|uFv7sZC<)f?w*&N_7NIc z=+P3Idfm&#lk=6=x`B(Q*mT+@pYV=f_K*i#DeXVc+cihmClvF(>XQ?U5&9)nKh9o%HP$2hXBlvp?n_p{U z?X^KTaW;hWz|_N_#=l0-0^qk3cvBCPWC>I@ud?0SK?RN%u$a|RdS4yNwb3rxOWr6u z@c&ploG(qQ=v*57-Cbd31}o(bt=L*|J=Q&TvwHaU%&u3#tdNIcUvg{o_BuCrBNa(G zV}RLQq;vU+VB2_Fj`l9*#6}K-aX9<%f#$;qjY~&WQYF5_N)?JBw^?6fz!3R6?`;Kr z-xA<<)=A{GhIB`gF=Iz+k<0QJj1mrx;L4?V08>bOG|P4hs`VfDxDWo&LzM}j4x3;2 zolqHic2*Oo4V~Z4SaOKaQ4OloD4Sg!8cp2vOJ6tNjKHulBr!EEUrfV^56_QcX_rXF z7S@R0Z{68V!{Wx4A`RALZZ^9kyhrU+(?xdp9}*Y<&JH>%=_5@KUSH!V0o@~M2t)It z)6PFD-MDkD=)nQ$^)gBtUrL6c;H%x4xtzmCH_W$^f99NIY;)zm%0rvaau5QP%2BAO z!diOGOKbZY)=w$)i}lVp80gwVQW-T!%{d4(cxsMwx%0mrv+8z;_U(z-J(4DiEzsb= z!7;nRzMu|XYkGHgdG}bI(K8WBWmJ0Q2ry7)b0Z2ZJ%_Ga_3LHPLcHg^_^c({=M$SKah`hj^b7;)bQfr+j>R)6v}REoEwerY~!&3rJaEFsfVxOdo2R9i6X z<#t};TewxN^X{f*2NHz<{kc>J;h4w?3CbT9Mx`T^)8V%3FxmAs=4*a&9qw9rA-6#= z@XZ7Tp&C}eOPO<8rP45kYn&#Ib+}tdOw4}`w)N?t4K9VHzHWV+cs_S?yYAvf(7r|p zdK}4@H|n)78Sz2mr#Z-n(>w!{-(8N!&sP2$pm+`aa4YrKMgH3{U5krU8Po4uHyGAO z#pYLE1aLd`8)y$gC>-1Vx>`)W$zcyD$DaK%svFqy^C{RoaT}o>yS@3uN8M*G zzfVV|{CT4&r+bpw2q-YYF%2$FTk*uynUeX!;y_YVer(kCnLjm0`%!UG`XcYldaeh( zynF}=2YtQcdZA=^_GcP14ANHFtARjc_SVW0_a8#76dh>JhnK}OBVM}us;2jgD_tl2 z3)WAO4O(QLAS4gOm@Sxb4fCgTJ>O4uuCCx_?RkNIX_oDW^!gmDmLOZ0!B)g%m!j{~ zh^hAKzvU6mU1$&*Q}%nbJ}>XwyHA8#F2}==(hD)4<&_^>&)$2ubB-1tC+gU}zLQ-p zQNBYTo^5bMpH6+3qEmA5Vz_2~wg*|9I>yUa)V~Hv$`Z=cJaWQWAipT+Kl2QfcY4>)5HFaZ{VuuSrV@%BXObCi)C{j;!%LT7NV<&3+aH zh3$9cu$nggu$ceyFlV_}?DKGtD|h1#N%?7n`T5Idqhp^UqwH{Cd{PBoXb%{lqeBSb zD!T51#>K*M-qN@XW|2KS$o>kQV$)XLWfy}3yzt{f>w#reU znD#qkxTPLqBf>TeHF*Z9 zM&>VYz9MAVRNDbyd?gR~n^*ZgM0e29rw)g!<&LY?3WCPXK?h&C5=`0kbGm|zQ|vhg zBc={P9U!nN?ht&WXX_V`vu&&E`Mkm8#IF}gNWJxygTUOJ6k9S+AhO|C#59J<^q}rB z7I*PaG3WeC>bA2R5d`6%5#IJO=t%NRNtyFfQ;=Q#X1FP3P*o6gs(F!RdFasT481eo zABFx)D}0I^t?fvrVOrKlOaZqxJG*D#O|78DITy2F0BFNSJf$?1>DYnt2Rgxs z?dRdyR-Bg+et>pcXq!&gEg(fKIqUAY!3sYtq?Crq+5qak7ZH+tOoi*Exo$$AbI=9v z=RP^{ru>?FawS$pQ$KQGcRQTDl5`e`mtMNAC@eV-0LE~j5keIvw_$78jtWpC=-x=p zGb7HWN?Gu3M7)`QKPfIb@VeXJTKONUQ3O;u%kW2d!~eBDEeJYK9jJM=b)oa0`*U=S zstJt`?jv6BS3J|QD&k#Ob}CK%S>Z*#Ena{i_?H;MEe)WPyAl1Z7*2?I`>OFo%#qL; zWPG1QrV8XAB$16_YicYJ`ypTtZU+tEEK#`Tl0~f6Ai&Iyq1k zK}-2al5@#vn0ihEf-ye|3=Bq?Hb4Ex4M9>*n_%csx?(rBj7Gngv>^fgYX->QG`pe` z@*ms~WwsnIJ8G9wPO;NKv0;?)cRka7Tc;~@aAHXH&9vr`>L55lWlt51l~#0BYqLNw zGSk2+R(g8}A^}24P2cIP5?YwZ?_Z%CdBle57-VZfOa5Nu?o2s{jMK3zmfmUVDA0_J z89t2g$3ZJLYe&234K4;a?kL`H2qbMKlDr{29AlsbgpwI5y&1({TdPiV>E6gxUCLr@ z9^rK1`?o(4bC+Xzy;k%+*8#%W{~;(K7@-_;epcl#OS16yek4wA^zE&$P1u;MjZd_k zG&bmqDs773XNQzpfZUwx!X|z0yuStNdVDPM?tj8$&>R_gGtr4qKnyv>)lli($=L<` z@FzwFz>T0A;S0sm$S!_>FrWJS4CSlCTEr`DQ{$te#B%BFrK#`Y)YjaMe@K7}e|>cw z>q(6Q9NU^GtY#>|>-HV!_T#TH{v<`H*$Fymz!95oB<^d4?yr-1lrr~M&7SDXih4_j zc(L7?hgGEN@8`&n9}Wl3yV#@zWq9T$Y>HxfKW6Z5KhPWQ`RjTiDkM!ge}s(ucso1C znTN1ZL_(2xGq|~8dpGID=+(8c*$H^#An*yK-C7^(XgIEb_$b@R7(AZoOcFVCBK*Pf zo*tsi@0sCZJ8b98Uu!~d30}TP29k)F!OwI_*Lyh^SJq}jlOG=WIuX8qwI0IKs#fMM8q6Bd+?f)dLpJhvNXDHq*>+bvMVEENb z0qV-ZE_a<*N0&ROkmpDFF78rwWqQZbvSWr9O|N;WJ+<$AKD-J4lXsz#Ix07nDxqXX z>CF>n;}X&nEkfh~XT0Vr{l-gHy+ce9-MT)RcX86;)${b?YPVg;pkz*Rxi}`}g5$Y( z84kXnx|8uwyWGhvc5=V07pH?Pd#wB!of1>Zafs8Qi7%|2QkaUo$zyb{_Q@2ll3FhR zG);PzLe)JMitU|(pQKwBrm#s^M|T2m!JREu!XCloI^;zDlsYf2uTMST_XO&Tmt4n` zWHrhpG2N`*ug6Mx(9Dww;U$KVk^TL>zhZ&QjX_u4*!{Z&a- z!5%c1o%~^Rp)K}= 0 && y < this.mapData.length) { @@ -287,7 +279,7 @@ module Phaser { for (var r = 0; r < this._tempTileBlock.length; r++) { - this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles); + this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles); } } @@ -344,8 +336,8 @@ module Phaser { */ public getTileFromWorldXY(x: number, y: number): number { - x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; return this.getTileIndex(x, y); @@ -365,10 +357,10 @@ module Phaser { } // What tiles do we need to check against? - this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; - this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; - this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; - this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; + this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; + this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; + this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; + this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; // Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock) @@ -378,7 +370,7 @@ module Phaser { /* for (var r = 0; r < this._tempTileBlock.length; r++) { - if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) + if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) { this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile }); } @@ -428,16 +420,16 @@ module Phaser { if (collisionOnly) { // We only want to consider the tile for checking if you can actually collide with it - if (this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Types.NONE) + if (this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Types.NONE) { - this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] }); + this._tempTileBlock.push({ x: tx, y: ty, tile: this.parent.tiles[this.mapData[ty][tx]] }); } } else { if (this.mapData[ty] && this.mapData[ty][tx]) { - this._tempTileBlock.push({ x: tx, y: ty, tile: this._parent.tiles[this.mapData[ty][tx]] }); + this._tempTileBlock.push({ x: tx, y: ty, tile: this.parent.tiles[this.mapData[ty][tx]] }); } } } @@ -502,34 +494,35 @@ module Phaser { /** * Parse tile offsets from map data. - * @return {number} length of _tileOffsets array. + * @return {number} length of tileOffsets array. */ public parseTileOffsets():number { - this._tileOffsets = []; + this.tileOffsets = []; var i = 0; if (this.mapFormat == Tilemap.FORMAT_TILED_JSON) { // For some reason Tiled counts from 1 not 0 - this._tileOffsets[0] = null; + this.tileOffsets[0] = null; i = 1; } - for (var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) + for (var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing)) { - for (var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) + for (var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing)) { - this._tileOffsets[i] = { x: tx, y: ty }; + this.tileOffsets[i] = { x: tx, y: ty }; i++; } } - return this._tileOffsets.length; + return this.tileOffsets.length; } + /* public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { this.context.fillStyle = color; @@ -539,125 +532,7 @@ module Phaser { this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42); } - - /** - * Render this layer to a specific camera with offset to camera. - * @param camera {Camera} The camera the layer is going to be rendered. - * @param dx {number} X offset to the camera. - * @param dy {number} Y offset to the camera. - * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed. - */ - public render(camera: Camera, dx, dy): bool { - - if (this.visible === false || this.alpha < 0.1) - { - return false; - } - - // Work out how many tiles we can fit into our camera and round it up for the edges - this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1; - this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1; - - // And now work out where in the tilemap the camera actually is - this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth); - this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight); - - // Tilemap bounds check - if (this._startX < 0) - { - this._startX = 0; - } - - if (this._startY < 0) - { - this._startY = 0; - } - - if (this._maxX > this.widthInTiles) - { - this._maxX = this.widthInTiles; - } - - if (this._maxY > this.heightInTiles) - { - this._maxY = this.heightInTiles; - } - - if (this._startX + this._maxX > this.widthInTiles) - { - this._startX = this.widthInTiles - this._maxX; - } - - if (this._startY + this._maxY > this.heightInTiles) - { - this._startY = this.heightInTiles - this._maxY; - } - - // Finally get the offset to avoid the blocky movement - this._dx = dx; - this._dy = dy; - - this._dx += -(camera.worldView.x - (this._startX * this.tileWidth)); - this._dy += -(camera.worldView.y - (this._startY * this.tileHeight)); - - this._tx = this._dx; - this._ty = this._dy; - - // Apply camera difference - /* - if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0) - { - this._dx -= (camera.worldView.x * this.scrollFactor.x); - this._dy -= (camera.worldView.y * this.scrollFactor.y); - } - */ - - // Alpha - if (this.alpha !== 1) - { - var globalAlpha = this.context.globalAlpha; - this.context.globalAlpha = this.alpha; - } - - for (var row = this._startY; row < this._startY + this._maxY; row++) - { - this._columnData = this.mapData[row]; - - for (var tile = this._startX; tile < this._startX + this._maxX; tile++) - { - if (this._tileOffsets[this._columnData[tile]]) - { - this.context.drawImage( - this._texture, // Source Image - this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image) - this._tileOffsets[this._columnData[tile]].y, // Source Y - this.tileWidth, // Source Width - this.tileHeight, // Source Height - this._tx, // Destination X (where on the canvas it'll be drawn) - this._ty, // Destination Y - this.tileWidth, // Destination Width (always same as Source Width unless scaled) - this.tileHeight // Destination Height (always same as Source Height unless scaled) - ); - - } - - this._tx += this.tileWidth; - - } - - this._tx = this._dx; - this._ty += this.tileHeight; - - } - - if (globalAlpha > -1) - { - this.context.globalAlpha = globalAlpha; - } - - return true; - - } + */ } } \ No newline at end of file diff --git a/Phaser/components/sprite/Events.ts b/Phaser/components/sprite/Events.ts index 2dcd55e9..b8e2e3d9 100644 --- a/Phaser/components/sprite/Events.ts +++ b/Phaser/components/sprite/Events.ts @@ -24,10 +24,13 @@ module Phaser.Components.Sprite { this.onKilled = new Phaser.Signal; this.onRevived = new Phaser.Signal; + // Only create these if Sprite input is enabled? this.onInputOver = new Phaser.Signal; this.onInputOut = new Phaser.Signal; this.onInputDown = new Phaser.Signal; this.onInputUp = new Phaser.Signal; + this.onDragStart = new Phaser.Signal; + this.onDragStop = new Phaser.Signal; } @@ -81,6 +84,15 @@ module Phaser.Components.Sprite { */ public onInputUp: Phaser.Signal; + /** + * Dispatched by the Input component when the Sprite starts being dragged + */ + public onDragStart: Phaser.Signal; + + /** + * Dispatched by the Input component when the Sprite stops being dragged + */ + public onDragStop: Phaser.Signal; diff --git a/Phaser/components/sprite/Input.ts b/Phaser/components/sprite/Input.ts index c6e0a0b9..2c36f72a 100644 --- a/Phaser/components/sprite/Input.ts +++ b/Phaser/components/sprite/Input.ts @@ -595,6 +595,8 @@ module Phaser.Components.Sprite { this.sprite.group.bringToTop(this.sprite); } + this.sprite.events.onDragStart.dispatch(this.sprite, pointer); + } /** @@ -612,7 +614,7 @@ module Phaser.Components.Sprite { this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY; } - //pointer.draggedObject = null; + this.sprite.events.onDragStop.dispatch(this.sprite, pointer); } /** diff --git a/Phaser/core/Group.ts b/Phaser/core/Group.ts index 8d1633ce..65a87030 100644 --- a/Phaser/core/Group.ts +++ b/Phaser/core/Group.ts @@ -618,17 +618,58 @@ module Phaser { public bringToTop(child): bool { + //console.log('bringToTop', child.name,'current z', child.z); + var oldZ = child.z; + // If child not in this group, or is already at the top of the group, return false - if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) + //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) + if (!child || child.group == null || child.group.ID != this.ID) + { + //console.log('If child not in this group, or is already at the top of the group, return false'); + return false; + } + + // Find out the largest z index + var topZ: number = -1; + + for (var i = 0; i < this.length; i++) + { + if (this.members[i] && this.members[i].z > topZ) + { + topZ = this.members[i].z; + } + } + + // Child is already at the top + if (child.z == topZ) { return false; } + child.z = topZ + 1; + + // Sort them out based on the current z indexes this.sort(); + // Now tidy-up the z indexes, removing gaps, etc + for (var i = 0; i < this.length; i++) + { + if (this.members[i]) + { + this.members[i].z = i; + } + } + + //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z); + + return true; + // What's the z index of the top most child? + /* var childIndex: number = this._zCounter; + console.log('childIndex', childIndex); + this._i = 0; while (this._i < this.length) @@ -649,10 +690,13 @@ module Phaser { } } + console.log('child inserted at index', child.z); + // Maybe redundant? this.sort(); return true; + */ } diff --git a/Phaser/gameobjects/IGameObject.ts b/Phaser/gameobjects/IGameObject.ts index 26784eb7..c5fbce2d 100644 --- a/Phaser/gameobjects/IGameObject.ts +++ b/Phaser/gameobjects/IGameObject.ts @@ -19,6 +19,11 @@ module Phaser { */ group: Group; + /** + * The name of the Game Object. Typically not set by Phaser, but extremely useful for debugging / logic. + */ + name: string; + /** * x value of the object. */ diff --git a/Phaser/gameobjects/Sprite.ts b/Phaser/gameobjects/Sprite.ts index 524c4009..7bc25302 100644 --- a/Phaser/gameobjects/Sprite.ts +++ b/Phaser/gameobjects/Sprite.ts @@ -23,7 +23,7 @@ module Phaser { * @param [x] {number} the initial x position of the sprite. * @param [y] {number} the initial y position of the sprite. * @param [key] {string} Key of the graphic you want to load for this sprite. - * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED) + * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics) * @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape) */ constructor(game: Game, x?: number = 0, y?: number = 0, key?: string = null, frame? = null, bodyType?: number = Phaser.Types.BODY_DISABLED, shapeType?:number = 0) { @@ -40,6 +40,7 @@ module Phaser { this.y = y; this.z = -1; this.group = null; + this.name = ''; this.animations = new Phaser.Components.AnimationManager(this); this.input = new Phaser.Components.Sprite.Input(this); @@ -97,6 +98,11 @@ module Phaser { */ public type: number; + /** + * The name of game object. + */ + public name: string; + /** * The Group this Sprite belongs to. */ @@ -183,7 +189,7 @@ module Phaser { /** * z order value of the object. */ - public z: number = 0; + public z: number = -1; /** * Render iteration counter @@ -202,7 +208,14 @@ module Phaser { * The value is automatically wrapped to be between 0 and 360. */ public set rotation(value: number) { + this.transform.rotation = this.game.math.wrap(value, 360, 0); + + if (this.body) + { + this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + } + } /** diff --git a/Phaser/gameobjects/Tilemap.ts b/Phaser/gameobjects/Tilemap.ts index 14408fb6..d128b396 100644 --- a/Phaser/gameobjects/Tilemap.ts +++ b/Phaser/gameobjects/Tilemap.ts @@ -35,9 +35,15 @@ module Phaser { this.visible = true; this.alive = true; + this.z = -1; + this.group = null; + this.name = ''; + + this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.Transform(this); + this.tiles = []; this.layers = []; - this.cameraBlacklist = []; this.mapFormat = format; @@ -71,6 +77,16 @@ module Phaser { */ public type: number; + /** + * The name of game object. + */ + public name: string; + + /** + * The Group this Sprite belongs to. + */ + public group: Group; + /** * Controls if both update and render are called by the core game loop. */ @@ -87,10 +103,44 @@ module Phaser { public visible: bool; /** - * + * A useful state for many game objects. Kill and revive both flip this switch. */ public alive: bool; + /** + * The texture used to render the Sprite. + */ + public texture: Phaser.Components.Texture; + + /** + * The Sprite transform component. + */ + public transform: Phaser.Components.Transform; + + /** + * The Input component + */ + //public input: Phaser.Components.Sprite.Input; + + /** + * The Events component + */ + //public events: Phaser.Components.Sprite.Events; + + /** + * z order value of the object. + */ + public z: number = -1; + + /** + * Render iteration counter + */ + public renderOrderID: number = 0; + + + + + /** * Tilemap data format enum: CSV. * @type {number} @@ -145,34 +195,15 @@ module Phaser { public mapFormat: number; /** - * An Array of Cameras to which this GameObject won't render - * @type {Array} + * Inherited methods for overriding. */ - public cameraBlacklist: number[]; - - /** - * Inherited update method. - */ - public update() { + public preUpdate() { } - /** - * Render this tilemap to a specific camera with specific offset. - * @param camera {Camera} The camera this tilemap will be rendered to. - * @param cameraOffsetX {number} X offset of the camera. - * @param cameraOffsetY {number} Y offset of the camera. - */ - public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number) { - - if (this.cameraBlacklist.indexOf(camera.ID) == -1) - { - // Loop through the layers - for (var i = 0; i < this.layers.length; i++) - { - this.layers[i].render(camera, cameraOffsetX, cameraOffsetY); - } - } - + public update() { + } + + public postUpdate() { } /** @@ -202,6 +233,7 @@ module Phaser { } layer.updateBounds(); + var tileQuantity = layer.parseTileOffsets(); this.currentLayer = layer; diff --git a/Phaser/phaser.js b/Phaser/phaser.js index ec56656e..7b20a194 100644 --- a/Phaser/phaser.js +++ b/Phaser/phaser.js @@ -1,3 +1,19 @@ +/** +* Phaser +* +* v1.0.0 - June XX 2013 +* +* A small and feature-packed 2D canvas game framework born from the firey pits of Flixel and Kiwi. +* +* Richard Davey (@photonstorm) +* +* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser +* and my love of game development took a lot of inspiration. +* +* "If you want your children to be intelligent, read them fairy tales." +* "If you want them to be more intelligent, read them more fairy tales." +* -- Albert Einstein +*/ var Phaser; (function (Phaser) { Phaser.VERSION = 'Phaser version 1.0.0'; diff --git a/Phaser/physics/Body.ts b/Phaser/physics/Body.ts index 0e65ebab..c4758a03 100644 --- a/Phaser/physics/Body.ts +++ b/Phaser/physics/Body.ts @@ -35,7 +35,7 @@ module Phaser.Physics { this.sprite = sprite; this.game = sprite.game; this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y)); - this.angle = sprite.rotation; + this.angle = this.game.math.degreesToRadians(sprite.rotation); } else { @@ -61,7 +61,6 @@ module Phaser.Physics { this.bounds = new Bounds; this.allowCollisions = Phaser.Types.ANY; - this.fixedRotation = false; this.categoryBits = 0x0001; this.maskBits = 0xFFFF; @@ -82,11 +81,8 @@ module Phaser.Physics { } - public toString(): string { - return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; - } - private _tempVec2: Phaser.Vec2 = new Phaser.Vec2; + private _fixedRotation: bool = false; /** * Reference to Phaser.Game @@ -118,8 +114,26 @@ module Phaser.Physics { */ public type: number; + /** + * The angle of the body in radians. Used by all of the internal physics methods. + */ public angle: number; + /** + * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + */ + public get rotation(): number { + return this.game.math.radiansToDegrees(this.angle); + } + + /** + * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + * The value is automatically wrapped to be between 0 and 360. + */ + public set rotation(value: number) { + this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + } + // Local to world transform public transform: Phaser.Transform; @@ -174,17 +188,16 @@ module Phaser.Physics { public inertia: number; public inertiaInverted: number; - public fixedRotation = false; - public categoryBits = 0x0001; - public maskBits = 0xFFFF; - public stepCount = 0; + public categoryBits: number = 0x0001; + public maskBits: number = 0xFFFF; + public stepCount: number = 0; public space: Space; public duplicate() { console.log('body duplicate called'); - //var body = new Body(this.type, this.transform.t, this.angle); + //var body = new Body(this.type, this.transform.t, this.rotation); //for (var i = 0; i < this.shapes.length; i++) //{ @@ -313,28 +326,28 @@ module Phaser.Physics { } - private setMass(mass) { + private setMass(mass:number) { this.mass = mass; this.massInverted = mass > 0 ? 1 / mass : 0; } - private setInertia(inertia) { + private setInertia(inertia:number) { this.inertia = inertia; this.inertiaInverted = inertia > 0 ? 1 / inertia : 0; } - public setTransform(pos, angle) { + public setTransform(pos:Phaser.Vec2, angle:number) { // inject the transform into this.position this.transform.setTo(pos, angle); - Manager.write('setTransform: ' + this.position.toString()); - Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('setTransform: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - Manager.write('post setTransform: ' + this.position.toString()); + //Manager.write('post setTransform: ' + this.position.toString()); //this.position.copyFrom(this.transform.transform(this.centroid)); this.angle = angle; @@ -342,17 +355,17 @@ module Phaser.Physics { public syncTransform() { - Manager.write('syncTransform:'); - Manager.write('p: ' + this.position.toString()); - Manager.write('centroid: ' + this.centroid.toString()); - Manager.write('xf: ' + this.transform.toString()); - Manager.write('a: ' + this.angle); + //Manager.write('syncTransform:'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('a: ' + this.angle); this.transform.setRotation(this.angle); // OPTIMISE: Creating new vector Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t); - Manager.write('--------------------'); - Manager.write('xf: ' + this.transform.toString()); - Manager.write('--------------------'); + //Manager.write('--------------------'); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('--------------------'); } @@ -376,9 +389,16 @@ module Phaser.Physics { return Phaser.TransformUtils.unrotate(this.transform, v); } - public setFixedRotation(flag) { - this.fixedRotation = flag; + public set fixedRotation(value:bool) { + + this._fixedRotation = value; + this.resetMassData(); + + } + + public get fixedRotation(): bool { + return this._fixedRotation; } public resetMassData() { @@ -392,7 +412,6 @@ module Phaser.Physics { if (this.isDynamic == false) { Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - //this.position.copyFrom(this.transform.transform(this.centroid)); return; } @@ -407,14 +426,11 @@ module Phaser.Physics { var mass = shape.area() * shape.density; var inertia = shape.inertia(mass); - //console.log('rmd', centroid, shape); - totalMassCentroid.multiplyAddByScalar(centroid, mass); totalMass += mass; totalInertia += inertia; } - //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass)); Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid); this.setMass(totalMass); @@ -455,9 +471,9 @@ module Phaser.Physics { public cacheData(source:string = '') { - Manager.write('cacheData -- start'); - Manager.write('p: ' + this.position.toString()); - Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- start'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); this.bounds.clear(); @@ -468,11 +484,11 @@ module Phaser.Physics { this.bounds.addBounds(shape.bounds); } - Manager.write('bounds: ' + this.bounds.toString()); + //Manager.write('bounds: ' + this.bounds.toString()); - Manager.write('p: ' + this.position.toString()); - Manager.write('xf: ' + this.transform.toString()); - Manager.write('cacheData -- stop'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- stop'); } @@ -538,15 +554,16 @@ module Phaser.Physics { { this.sprite.x = this.position.x * 50; this.sprite.y = this.position.y * 50; - // Obey fixed rotation? - this.sprite.rotation = this.game.math.radiansToDegrees(this.angle); + this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle); } } public resetForce() { + this.force.setTo(0, 0); this.torque = 0; + } public applyForce(force:Phaser.Vec2, p:Phaser.Vec2) { @@ -638,11 +655,8 @@ module Phaser.Physics { } public kineticEnergy() { - - var vsq = this.velocity.dot(this.velocity); - var wsq = this.angularVelocity * this.angularVelocity; - return 0.5 * (this.mass * vsq + this.inertia * wsq); + return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity)); } @@ -670,12 +684,7 @@ module Phaser.Physics { public isCollidable(other:Body) { - if (this == other) - { - return false; - } - - if (this.isDynamic == false && other.isDynamic == false) + if ((this.isDynamic == false && other.isDynamic == false) || this == other) { return false; } @@ -699,6 +708,10 @@ module Phaser.Physics { } + public toString(): string { + return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; + } + } } \ No newline at end of file diff --git a/Phaser/physics/ContactSolver.ts b/Phaser/physics/ContactSolver.ts index f43db61f..9db1a609 100644 --- a/Phaser/physics/ContactSolver.ts +++ b/Phaser/physics/ContactSolver.ts @@ -313,12 +313,8 @@ module Phaser.Physics { var r2 = new Phaser.Vec2; // Transformed r1, r2 - Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1); - //var r1 = vec2.rotate(con.r1_local, body1.a); - Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2); - //var r2 = vec2.rotate(con.r2_local, body2.a); Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle); Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y); @@ -330,10 +326,7 @@ module Phaser.Physics { var p2 = new Phaser.Vec2; Phaser.Vec2Utils.add(body1.position, r1, p1); - //var p1 = vec2.add(body1.p, r1); - Phaser.Vec2Utils.add(body2.position, r2, p2); - //var p2 = vec2.add(body2.p, r2); Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y); @@ -341,7 +334,6 @@ module Phaser.Physics { // Corrected delta vector var dp = new Phaser.Vec2; Phaser.Vec2Utils.subtract(p2, p1, dp); - //var dp = vec2.sub(p2, p1); // Position constraint var c = Phaser.Vec2Utils.dot(dp, n) + con.depth; @@ -368,16 +360,11 @@ module Phaser.Physics { // Apply correction impulses var impulse_dt = new Phaser.Vec2; Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt); - //var impulse_dt = vec2.scale(n, lambda_dt); body1.position.multiplyAddByScalar(impulse_dt, -m1_inv); - //body1.p.mad(impulse_dt, -m1_inv); - body1.angle -= sn1 * lambda_dt * i1_inv; body2.position.multiplyAddByScalar(impulse_dt, m2_inv); - //body2.p.mad(impulse_dt, m2_inv); - body2.angle += sn2 * lambda_dt * i2_inv; Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); diff --git a/Phaser/renderers/CanvasRenderer.ts b/Phaser/renderers/CanvasRenderer.ts index c3558af4..7aeb23a2 100644 --- a/Phaser/renderers/CanvasRenderer.ts +++ b/Phaser/renderers/CanvasRenderer.ts @@ -17,7 +17,7 @@ module Phaser { */ private _game: Phaser.Game; - // local rendering related temp vars to help avoid gc spikes with var creation + // Local rendering related temp vars to help avoid gc spikes through var creation private _ga: number = 1; private _sx: number = 0; private _sy: number = 0; @@ -29,9 +29,15 @@ module Phaser { private _dh: number = 0; private _fx: number = 1; private _fy: number = 1; + private _tx: number = 0; + private _ty: number = 0; private _sin: number = 0; private _cos: number = 1; - + private _maxX: number = 0; + private _maxY: number = 0; + private _startX: number = 0; + private _startY: number = 0; + private _columnData; private _cameraList; private _camera: Camera; private _groupLength: number; @@ -74,6 +80,10 @@ module Phaser { { this.renderScrollZone(this._camera, object); } + else if (object.type == Types.TILEMAP) + { + this.renderTilemap(this._camera, object); + } } @@ -668,6 +678,124 @@ module Phaser { } + + /** + * Render a tilemap to a specific camera. + * @param camera {Camera} The camera this tilemap will be rendered to. + */ + public renderTilemap(camera: Camera, tilemap: Tilemap): bool { + + // Loop through the layers + for (var i = 0; i < tilemap.layers.length; i++) + { + var layer: TilemapLayer = tilemap.layers[i]; + + if (layer.visible == false || layer.alpha < 0.1) + { + continue; + } + + // Work out how many tiles we can fit into our camera and round it up for the edges + this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1; + this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1; + + // And now work out where in the tilemap the camera actually is + this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth); + this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight); + + // Tilemap bounds check + if (this._startX < 0) + { + this._startX = 0; + } + + if (this._startY < 0) + { + this._startY = 0; + } + + if (this._maxX > layer.widthInTiles) + { + this._maxX = layer.widthInTiles; + } + + if (this._maxY > layer.heightInTiles) + { + this._maxY = layer.heightInTiles; + } + + if (this._startX + this._maxX > layer.widthInTiles) + { + this._startX = layer.widthInTiles - this._maxX; + } + + if (this._startY + this._maxY > layer.heightInTiles) + { + this._startY = layer.heightInTiles - this._maxY; + } + + // Finally get the offset to avoid the blocky movement + //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x); + //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y); + //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x); + //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y); + this._dx = 0; + this._dy = 0; + + this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth)); + this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight)); + + this._tx = this._dx; + this._ty = this._dy; + + // Alpha + if (layer.texture.alpha !== 1) + { + this._ga = layer.texture.context.globalAlpha; + layer.texture.context.globalAlpha = layer.texture.alpha; + } + + for (var row = this._startY; row < this._startY + this._maxY; row++) + { + this._columnData = layer.mapData[row]; + + for (var tile = this._startX; tile < this._startX + this._maxX; tile++) + { + if (layer.tileOffsets[this._columnData[tile]]) + { + layer.texture.context.drawImage( + layer.texture.texture, + layer.tileOffsets[this._columnData[tile]].x, + layer.tileOffsets[this._columnData[tile]].y, + layer.tileWidth, + layer.tileHeight, + this._tx, + this._ty, + layer.tileWidth, + layer.tileHeight + ); + + } + + this._tx += layer.tileWidth; + + } + + this._tx = this._dx; + this._ty += layer.tileHeight; + + } + + if (this._ga > -1) + { + layer.texture.context.globalAlpha = this._ga; + } + } + + return true; + + } + } } \ No newline at end of file diff --git a/Phaser/tweens/Tween.ts b/Phaser/tweens/Tween.ts index f46d500a..05b2dd8d 100644 --- a/Phaser/tweens/Tween.ts +++ b/Phaser/tweens/Tween.ts @@ -187,6 +187,8 @@ module Phaser { } + public isRunning: bool = false; + /** * Start to tween. */ @@ -205,6 +207,7 @@ module Phaser { } this._startTime = this._game.time.now + this._delayTime; + this.isRunning = true; for (var property in this._valuesEnd) { @@ -289,6 +292,8 @@ module Phaser { this._manager.remove(this); } + this.isRunning = false; + this.onComplete.dispose(); return this; @@ -432,6 +437,11 @@ module Phaser { this._chainedTweens[i].start(); } + if (this._chainedTweens.length == 0) + { + this.isRunning = false; + } + return false; } diff --git a/Phaser/utils/DebugUtils.ts b/Phaser/utils/DebugUtils.ts index a4ae9613..7ad62249 100644 --- a/Phaser/utils/DebugUtils.ts +++ b/Phaser/utils/DebugUtils.ts @@ -91,6 +91,13 @@ module Phaser { } + static renderRectangle(rect: Phaser.Rectangle, fillStyle: string = 'rgba(0,255,0,0.3)') { + + DebugUtils.context.fillStyle = fillStyle; + DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height); + + } + static renderPhysicsBody(body: Phaser.Physics.Body, lineWidth: number = 1, fillStyle: string = 'rgba(0,255,0,0.2)', sleepStyle: string = 'rgba(100,100,100,0.2)') { for (var s = 0; s < body.shapesLength; s++) diff --git a/Phaser/utils/PointUtils.ts b/Phaser/utils/PointUtils.ts index 1431f215..775da371 100644 --- a/Phaser/utils/PointUtils.ts +++ b/Phaser/utils/PointUtils.ts @@ -11,7 +11,7 @@ module Phaser { - class PointUtils { + export class PointUtils { /** * Adds the coordinates of two points together to create a new point. diff --git a/README.md b/README.md index d92e7722..d6ce2f62 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,13 @@ TODO: * See about optimising Advanced Physics a lot more, so it doesn't create lots of Vec2s everywhere. * QuadTree.physics.checkHullIntersection * Fix the Motion methods for the new physics system -* Moved findShapeByPoint etc from Space to Manager (or at least add a proxy to them) +* Move findShapeByPoint etc from Space to Manager (or at least add a proxy to them) +* Make onInput events created only if input component is started +* Add button mode linked to sprite frames +* Add visible toggle if tween property is alpha <> 01 +* Camera.isHidden uses an array and length check, faster to swap for a single counter, also try to remove indexOf check +* Tilemap.render - move layers length to var +* Camera control method (touch/keyboard) V1.0.0 @@ -126,7 +132,10 @@ V1.0.0 * Fixed issue in Tilemap.parseTiledJSON where it would accidentally think image and object layers were map data. * Fixed bug in Group.bringToTop if the child didn't have a group property yet. * Fixed bug in FrameData.checkFrameName where the first index of the _frameNames array would be skipped. - +* Added isRunning boolean property to Phaser.Tween +* Moved 'facing' property from Sprite.body to Sprite.texture (may move to Sprite core) +* Added Sprite.events.onDragStart and onDragStop +* A tilemap can now be loaded without a tile sheet, should you just want to get the tile data from it and not render. V0.9.6 diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 3af754cb..6d56ec2b 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -217,6 +217,22 @@ origin 5.ts + + + csv tilemap.ts + + + + + + map draw.ts + + + tiled layers.ts + + + tiled tilemap.ts + tween loop 1.ts diff --git a/Tests/phaser.js b/Tests/phaser.js index 0df38b19..f5d4f68f 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -3787,6 +3787,7 @@ var Phaser; if(this.bringToTop) { this.sprite.group.bringToTop(this.sprite); } + this.sprite.events.onDragStart.dispatch(this.sprite, pointer); }; Input.prototype.stopDrag = /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. @@ -3799,8 +3800,8 @@ var Phaser; this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX; this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY; } - //pointer.draggedObject = null; - }; + this.sprite.events.onDragStop.dispatch(this.sprite, pointer); + }; Input.prototype.setDragLock = /** * Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! * @@ -3913,10 +3914,13 @@ var Phaser; this.onRemovedFromGroup = new Phaser.Signal(); this.onKilled = new Phaser.Signal(); this.onRevived = new Phaser.Signal(); + // Only create these if Sprite input is enabled? this.onInputOver = new Phaser.Signal(); this.onInputOut = new Phaser.Signal(); this.onInputDown = new Phaser.Signal(); this.onInputUp = new Phaser.Signal(); + this.onDragStart = new Phaser.Signal(); + this.onDragStop = new Phaser.Signal(); } return Events; })(); @@ -5158,9 +5162,7 @@ var Phaser; var r2 = new Phaser.Vec2(); // Transformed r1, r2 Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1); - //var r1 = vec2.rotate(con.r1_local, body1.a); Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2); - //var r2 = vec2.rotate(con.r2_local, body2.a); Physics.Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle); Physics.Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y); Physics.Manager.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle); @@ -5169,15 +5171,12 @@ var Phaser; var p1 = new Phaser.Vec2(); var p2 = new Phaser.Vec2(); Phaser.Vec2Utils.add(body1.position, r1, p1); - //var p1 = vec2.add(body1.p, r1); Phaser.Vec2Utils.add(body2.position, r2, p2); - //var p2 = vec2.add(body2.p, r2); Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y); // Corrected delta vector var dp = new Phaser.Vec2(); Phaser.Vec2Utils.subtract(p2, p1, dp); - //var dp = vec2.sub(p2, p1); // Position constraint var c = Phaser.Vec2Utils.dot(dp, n) + con.depth; var correction = this.clamp(Physics.Manager.CONTACT_SOLVER_BAUMGARTE * (c + Physics.Manager.CONTACT_SOLVER_COLLISION_SLOP), -Physics.Manager.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0); @@ -5195,12 +5194,9 @@ var Phaser; // Apply correction impulses var impulse_dt = new Phaser.Vec2(); Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt); - //var impulse_dt = vec2.scale(n, lambda_dt); body1.position.multiplyAddByScalar(impulse_dt, -m1_inv); - //body1.p.mad(impulse_dt, -m1_inv); body1.angle -= sn1 * lambda_dt * i1_inv; body2.position.multiplyAddByScalar(impulse_dt, m2_inv); - //body2.p.mad(impulse_dt, m2_inv); body2.angle += sn2 * lambda_dt * i2_inv; Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y); @@ -6664,13 +6660,13 @@ var Phaser; if (typeof y === "undefined") { y = 0; } if (typeof shapeType === "undefined") { shapeType = 0; } this._tempVec2 = new Phaser.Vec2(); + this._fixedRotation = false; // Shapes this.shapes = []; // Joints this.joints = []; this.jointHash = { }; - this.fixedRotation = false; this.categoryBits = 0x0001; this.maskBits = 0xFFFF; this.stepCount = 0; @@ -6681,7 +6677,7 @@ var Phaser; this.sprite = sprite; this.game = sprite.game; this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y)); - this.angle = sprite.rotation; + this.angle = this.game.math.degreesToRadians(sprite.rotation); } else { this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y)); this.angle = 0; @@ -6702,7 +6698,6 @@ var Phaser; }; this.bounds = new Physics.Bounds(); this.allowCollisions = Phaser.Types.ANY; - this.fixedRotation = false; this.categoryBits = 0x0001; this.maskBits = 0xFFFF; this.stepCount = 0; @@ -6714,12 +6709,26 @@ var Phaser; } } } - Body.prototype.toString = function () { - return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; - }; + Object.defineProperty(Body.prototype, "rotation", { + get: /** + * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + */ + function () { + return this.game.math.radiansToDegrees(this.angle); + }, + set: /** + * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + * The value is automatically wrapped to be between 0 and 360. + */ + function (value) { + this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + }, + enumerable: true, + configurable: true + }); Body.prototype.duplicate = function () { console.log('body duplicate called'); - //var body = new Body(this.type, this.transform.t, this.angle); + //var body = new Body(this.type, this.transform.t, this.rotation); //for (var i = 0; i < this.shapes.length; i++) //{ // body.addShape(this.shapes[i].duplicate()); @@ -6842,26 +6851,26 @@ var Phaser; Body.prototype.setTransform = function (pos, angle) { // inject the transform into this.position this.transform.setTo(pos, angle); - Physics.Manager.write('setTransform: ' + this.position.toString()); - Physics.Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('setTransform: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - Physics.Manager.write('post setTransform: ' + this.position.toString()); + //Manager.write('post setTransform: ' + this.position.toString()); //this.position.copyFrom(this.transform.transform(this.centroid)); this.angle = angle; }; Body.prototype.syncTransform = function () { - Physics.Manager.write('syncTransform:'); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('centroid: ' + this.centroid.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('a: ' + this.angle); + //Manager.write('syncTransform:'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('a: ' + this.angle); this.transform.setRotation(this.angle); // OPTIMISE: Creating new vector Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t); - Physics.Manager.write('--------------------'); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('--------------------'); - }; + //Manager.write('--------------------'); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('--------------------'); + }; Body.prototype.getWorldPoint = function (p) { // OPTIMISE: Creating new vector return Phaser.TransformUtils.transform(this.transform, p); @@ -6878,10 +6887,17 @@ var Phaser; // OPTIMISE: Creating new vector return Phaser.TransformUtils.unrotate(this.transform, v); }; - Body.prototype.setFixedRotation = function (flag) { - this.fixedRotation = flag; - this.resetMassData(); - }; + Object.defineProperty(Body.prototype, "fixedRotation", { + get: function () { + return this._fixedRotation; + }, + set: function (value) { + this._fixedRotation = value; + this.resetMassData(); + }, + enumerable: true, + configurable: true + }); Body.prototype.resetMassData = function () { this.centroid.setTo(0, 0); this.mass = 0; @@ -6890,7 +6906,6 @@ var Phaser; this.inertiaInverted = 0; if(this.isDynamic == false) { Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - //this.position.copyFrom(this.transform.transform(this.centroid)); return; } var totalMassCentroid = new Phaser.Vec2(0, 0); @@ -6901,12 +6916,10 @@ var Phaser; var centroid = shape.centroid(); var mass = shape.area() * shape.density; var inertia = shape.inertia(mass); - //console.log('rmd', centroid, shape); totalMassCentroid.multiplyAddByScalar(centroid, mass); totalMass += mass; totalInertia += inertia; } - //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass)); Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid); this.setMass(totalMass); if(!this.fixedRotation) { @@ -6933,20 +6946,20 @@ var Phaser; }; Body.prototype.cacheData = function (source) { if (typeof source === "undefined") { source = ''; } - Physics.Manager.write('cacheData -- start'); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- start'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); this.bounds.clear(); for(var i = 0; i < this.shapesLength; i++) { var shape = this.shapes[i]; shape.cacheData(this.transform); this.bounds.addBounds(shape.bounds); } - Physics.Manager.write('bounds: ' + this.bounds.toString()); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('cacheData -- stop'); - }; + //Manager.write('bounds: ' + this.bounds.toString()); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- stop'); + }; Body.prototype.updateVelocity = function (gravity, dt, damping) { Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2); Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity); @@ -6987,8 +7000,7 @@ var Phaser; if(this.sprite) { this.sprite.x = this.position.x * 50; this.sprite.y = this.position.y * 50; - // Obey fixed rotation? - this.sprite.rotation = this.game.math.radiansToDegrees(this.angle); + this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle); } }; Body.prototype.resetForce = function () { @@ -7045,9 +7057,7 @@ var Phaser; this.angularVelocity += impulse * this.inertiaInverted; }; Body.prototype.kineticEnergy = function () { - var vsq = this.velocity.dot(this.velocity); - var wsq = this.angularVelocity * this.angularVelocity; - return 0.5 * (this.mass * vsq + this.inertia * wsq); + return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity)); }; Object.defineProperty(Body.prototype, "isAwake", { get: function () { @@ -7068,10 +7078,7 @@ var Phaser; } }; Body.prototype.isCollidable = function (other) { - if(this == other) { - return false; - } - if(this.isDynamic == false && other.isDynamic == false) { + if((this.isDynamic == false && other.isDynamic == false) || this == other) { return false; } if(!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits)) { @@ -7085,6 +7092,9 @@ var Phaser; } return true; }; + Body.prototype.toString = function () { + return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; + }; return Body; })(); Physics.Body = Body; @@ -7113,7 +7123,7 @@ var Phaser; * @param [x] {number} the initial x position of the sprite. * @param [y] {number} the initial y position of the sprite. * @param [key] {string} Key of the graphic you want to load for this sprite. - * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED) + * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics) * @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape) */ function Sprite(game, x, y, key, frame, bodyType, shapeType) { @@ -7142,7 +7152,7 @@ var Phaser; /** * z order value of the object. */ - this.z = 0; + this.z = -1; /** * Render iteration counter */ @@ -7157,6 +7167,7 @@ var Phaser; this.y = y; this.z = -1; this.group = null; + this.name = ''; this.animations = new Phaser.Components.AnimationManager(this); this.input = new Phaser.Components.Sprite.Input(this); this.events = new Phaser.Components.Sprite.Events(this); @@ -7200,6 +7211,9 @@ var Phaser; */ function (value) { this.transform.rotation = this.game.math.wrap(value, 360, 0); + if(this.body) { + this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + } }, enumerable: true, configurable: true @@ -8185,29 +8199,70 @@ var Phaser; return true; }; Group.prototype.bringToTop = function (child) { + //console.log('bringToTop', child.name,'current z', child.z); + var oldZ = child.z; // If child not in this group, or is already at the top of the group, return false - if(!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) { + //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) + if(!child || child.group == null || child.group.ID != this.ID) { + //console.log('If child not in this group, or is already at the top of the group, return false'); return false; } - this.sort(); - // What's the z index of the top most child? - var childIndex = this._zCounter; - this._i = 0; - while(this._i < this.length) { - this._member = this.members[this._i++]; - if(this._member) { - if(this._i > childIndex) { - this._member.z--; - } else if(this._member.z == child.z) { - childIndex = this._i; - this._member.z = this._zCounter; - } + // Find out the largest z index + var topZ = -1; + for(var i = 0; i < this.length; i++) { + if(this.members[i] && this.members[i].z > topZ) { + topZ = this.members[i].z; } } + // Child is already at the top + if(child.z == topZ) { + return false; + } + child.z = topZ + 1; + // Sort them out based on the current z indexes + this.sort(); + // Now tidy-up the z indexes, removing gaps, etc + for(var i = 0; i < this.length; i++) { + if(this.members[i]) { + this.members[i].z = i; + } + } + //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z); + return true; + // What's the z index of the top most child? + /* + var childIndex: number = this._zCounter; + + console.log('childIndex', childIndex); + + this._i = 0; + + while (this._i < this.length) + { + this._member = this.members[this._i++]; + + if (this._member) + { + if (this._i > childIndex) + { + this._member.z--; + } + else if (this._member.z == child.z) + { + childIndex = this._i; + this._member.z = this._zCounter; + } + } + } + + console.log('child inserted at index', child.z); + // Maybe redundant? this.sort(); + return true; - }; + */ + }; Group.prototype.sort = /** * Call this function to sort the group according to a particular value and order. * For example, to sort game objects for Zelda-style overlaps you might call @@ -11782,6 +11837,7 @@ var Phaser; * @type {Tweens[]} */ this._chainedTweens = []; + this.isRunning = false; this._object = object; this._game = game; this._manager = this._game.tweens; @@ -11849,6 +11905,7 @@ var Phaser; this.onStart.dispatch(this._object); } this._startTime = this._game.time.now + this._delayTime; + this.isRunning = true; for(var property in this._valuesEnd) { // This prevents the interpolation of null values or of non-existing properties if(this._object[property] === null || !(property in this._object)) { @@ -11903,6 +11960,7 @@ var Phaser; if(this._manager !== null) { this._manager.remove(this); } + this.isRunning = false; this.onComplete.dispose(); return this; }; @@ -12013,6 +12071,9 @@ var Phaser; for(var i = 0; i < this._chainedTweens.length; i++) { this._chainedTweens[i].start(); } + if(this._chainedTweens.length == 0) { + this.isRunning = false; + } return false; } } @@ -12633,21 +12694,6 @@ var Phaser; * @param tileHeight {number} Height of tiles in this map. */ function TilemapLayer(game, parent, key, mapFormat, name, tileWidth, tileHeight) { - this._startX = 0; - this._startY = 0; - this._maxX = 0; - this._maxY = 0; - this._tx = 0; - this._ty = 0; - this._dx = 0; - this._dy = 0; - this._oldCameraX = 0; - this._oldCameraY = 0; - /** - * Opacity of this layer. - * @type {number} - */ - this.alpha = 1; /** * Controls whether update() and draw() are automatically called. * @type {boolean} @@ -12690,19 +12736,24 @@ var Phaser; * @type {number} */ this.tileSpacing = 0; - this._game = game; - this._parent = parent; + this.game = game; + this.parent = parent; this.name = name; this.mapFormat = mapFormat; this.tileWidth = tileWidth; this.tileHeight = tileHeight; this.boundsInTiles = new Phaser.Rectangle(); - //this.scrollFactor = new MicroPoint(1, 1); - this.canvas = game.stage.canvas; - this.context = game.stage.context; + this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.Transform(this); + if(key !== null) { + this.texture.loadImage(key, false); + } else { + this.texture.opaque = true; + } + // Handy proxies + this.alpha = this.texture.alpha; this.mapData = []; this._tempTileBlock = []; - this._texture = this._game.cache.getImage(key); } TilemapLayer.prototype.putTile = /** * Set a specific tile with its x and y in tiles. @@ -12711,8 +12762,8 @@ var Phaser; * @param index {number} The index of this tile type in the core map data. */ function (x, y, index) { - x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; if(y >= 0 && y < this.mapData.length) { if(x >= 0 && x < this.mapData[y].length) { this.mapData[y][x] = index; @@ -12784,7 +12835,7 @@ var Phaser; if (typeof height === "undefined") { height = this.heightInTiles; } this.getTempBlock(x, y, width, height); for(var r = 0; r < this._tempTileBlock.length; r++) { - this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles); + this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles); } }; TilemapLayer.prototype.replaceTile = /** @@ -12833,8 +12884,8 @@ var Phaser; * @param x {number} Y position of the point in target tile. */ function (x, y) { - x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; return this.getTileIndex(x, y); }; TilemapLayer.prototype.getTileOverlaps = /** @@ -12848,17 +12899,17 @@ var Phaser; return; } // What tiles do we need to check against? - this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; - this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; - this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; - this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; + this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; + this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; + this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; + this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; // Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock) this._tempBlockResults = []; this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true); /* for (var r = 0; r < this._tempTileBlock.length; r++) { - if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) + if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) { this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile }); } @@ -12893,11 +12944,11 @@ var Phaser; for(var tx = x; tx < x + width; tx++) { if(collisionOnly) { // We only want to consider the tile for checking if you can actually collide with it - if(this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) { + if(this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) { this._tempTileBlock.push({ x: tx, y: ty, - tile: this._parent.tiles[this.mapData[ty][tx]] + tile: this.parent.tiles[this.mapData[ty][tx]] }); } } else { @@ -12905,7 +12956,7 @@ var Phaser; this._tempTileBlock.push({ x: tx, y: ty, - tile: this._parent.tiles[this.mapData[ty][tx]] + tile: this.parent.tiles[this.mapData[ty][tx]] }); } } @@ -12951,120 +13002,42 @@ var Phaser; }; TilemapLayer.prototype.parseTileOffsets = /** * Parse tile offsets from map data. - * @return {number} length of _tileOffsets array. + * @return {number} length of tileOffsets array. */ function () { - this._tileOffsets = []; + this.tileOffsets = []; var i = 0; if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) { // For some reason Tiled counts from 1 not 0 - this._tileOffsets[0] = null; + this.tileOffsets[0] = null; i = 1; } - for(var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) { - for(var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) { - this._tileOffsets[i] = { + for(var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing)) { + for(var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing)) { + this.tileOffsets[i] = { x: tx, y: ty }; i++; } } - return this._tileOffsets.length; - }; - TilemapLayer.prototype.renderDebugInfo = function (x, y, color) { - if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } - this.context.fillStyle = color; - this.context.fillText('TilemapLayer: ' + this.name, x, y); - this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14); - this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28); - this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42); - }; - TilemapLayer.prototype.render = /** - * Render this layer to a specific camera with offset to camera. - * @param camera {Camera} The camera the layer is going to be rendered. - * @param dx {number} X offset to the camera. - * @param dy {number} Y offset to the camera. - * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed. - */ - function (camera, dx, dy) { - if(this.visible === false || this.alpha < 0.1) { - return false; - } - // Work out how many tiles we can fit into our camera and round it up for the edges - this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1; - this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1; - // And now work out where in the tilemap the camera actually is - this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth); - this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight); - // Tilemap bounds check - if(this._startX < 0) { - this._startX = 0; - } - if(this._startY < 0) { - this._startY = 0; - } - if(this._maxX > this.widthInTiles) { - this._maxX = this.widthInTiles; - } - if(this._maxY > this.heightInTiles) { - this._maxY = this.heightInTiles; - } - if(this._startX + this._maxX > this.widthInTiles) { - this._startX = this.widthInTiles - this._maxX; - } - if(this._startY + this._maxY > this.heightInTiles) { - this._startY = this.heightInTiles - this._maxY; - } - // Finally get the offset to avoid the blocky movement - this._dx = dx; - this._dy = dy; - this._dx += -(camera.worldView.x - (this._startX * this.tileWidth)); - this._dy += -(camera.worldView.y - (this._startY * this.tileHeight)); - this._tx = this._dx; - this._ty = this._dy; - // Apply camera difference - /* - if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0) - { - this._dx -= (camera.worldView.x * this.scrollFactor.x); - this._dy -= (camera.worldView.y * this.scrollFactor.y); - } - */ - // Alpha - if(this.alpha !== 1) { - var globalAlpha = this.context.globalAlpha; - this.context.globalAlpha = this.alpha; - } - for(var row = this._startY; row < this._startY + this._maxY; row++) { - this._columnData = this.mapData[row]; - for(var tile = this._startX; tile < this._startX + this._maxX; tile++) { - if(this._tileOffsets[this._columnData[tile]]) { - this.context.drawImage(this._texture, // Source Image - this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image) - this._tileOffsets[this._columnData[tile]].y, // Source Y - this.tileWidth, // Source Width - this.tileHeight, // Source Height - this._tx, // Destination X (where on the canvas it'll be drawn) - this._ty, // Destination Y - this.tileWidth, // Destination Width (always same as Source Width unless scaled) - this.tileHeight); - // Destination Height (always same as Source Height unless scaled) - } - this._tx += this.tileWidth; - } - this._tx = this._dx; - this._ty += this.tileHeight; - } - if(globalAlpha > -1) { - this.context.globalAlpha = globalAlpha; - } - return true; + return this.tileOffsets.length; }; return TilemapLayer; })(); Phaser.TilemapLayer = TilemapLayer; -})(Phaser || (Phaser = {})); + /* + public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { + + this.context.fillStyle = color; + this.context.fillText('TilemapLayer: ' + this.name, x, y); + this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14); + this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28); + this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42); + + } + */ + })(Phaser || (Phaser = {})); /// /** * Phaser - Tile @@ -13217,6 +13190,22 @@ var Phaser; if (typeof tileWidth === "undefined") { tileWidth = 0; } if (typeof tileHeight === "undefined") { tileHeight = 0; } /** + * The Input component + */ + //public input: Phaser.Components.Sprite.Input; + /** + * The Events component + */ + //public events: Phaser.Components.Sprite.Events; + /** + * z order value of the object. + */ + this.z = -1; + /** + * Render iteration counter + */ + this.renderOrderID = 0; + /** * Tilemap collision callback. * @type {function} */ @@ -13227,9 +13216,13 @@ var Phaser; this.active = true; this.visible = true; this.alive = true; + this.z = -1; + this.group = null; + this.name = ''; + this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.Transform(this); this.tiles = []; this.layers = []; - this.cameraBlacklist = []; this.mapFormat = format; switch(format) { case Tilemap.FORMAT_CSV: @@ -13245,24 +13238,14 @@ var Phaser; } Tilemap.FORMAT_CSV = 0; Tilemap.FORMAT_TILED_JSON = 1; - Tilemap.prototype.update = /** - * Inherited update method. + Tilemap.prototype.preUpdate = /** + * Inherited methods for overriding. */ function () { }; - Tilemap.prototype.render = /** - * Render this tilemap to a specific camera with specific offset. - * @param camera {Camera} The camera this tilemap will be rendered to. - * @param cameraOffsetX {number} X offset of the camera. - * @param cameraOffsetY {number} Y offset of the camera. - */ - function (camera, cameraOffsetX, cameraOffsetY) { - if(this.cameraBlacklist.indexOf(camera.ID) == -1) { - // Loop through the layers - for(var i = 0; i < this.layers.length; i++) { - this.layers[i].render(camera, cameraOffsetX, cameraOffsetY); - } - } + Tilemap.prototype.update = function () { + }; + Tilemap.prototype.postUpdate = function () { }; Tilemap.prototype.parseCSV = /** * Parset csv map data and generate tiles. @@ -16253,7 +16236,8 @@ var Phaser; return PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance); }; return PointUtils; - })(); + })(); + Phaser.PointUtils = PointUtils; })(Phaser || (Phaser = {})); /// /// @@ -18083,7 +18067,7 @@ var Phaser; (function (Phaser) { var CanvasRenderer = (function () { function CanvasRenderer(game) { - // local rendering related temp vars to help avoid gc spikes with var creation + // Local rendering related temp vars to help avoid gc spikes through var creation this._ga = 1; this._sx = 0; this._sy = 0; @@ -18095,8 +18079,14 @@ var Phaser; this._dh = 0; this._fx = 1; this._fy = 1; + this._tx = 0; + this._ty = 0; this._sin = 0; this._cos = 1; + this._maxX = 0; + this._maxY = 0; + this._startX = 0; + this._startY = 0; this._game = game; } CanvasRenderer.prototype.render = function () { @@ -18117,6 +18107,8 @@ var Phaser; this.renderSprite(this._camera, object); } else if(object.type == Phaser.Types.SCROLLZONE) { this.renderScrollZone(this._camera, object); + } else if(object.type == Phaser.Types.TILEMAP) { + this.renderTilemap(this._camera, object); } }; CanvasRenderer.prototype.preRenderGroup = function (camera, group) { @@ -18553,6 +18545,75 @@ var Phaser; } return true; }; + CanvasRenderer.prototype.renderTilemap = /** + * Render a tilemap to a specific camera. + * @param camera {Camera} The camera this tilemap will be rendered to. + */ + function (camera, tilemap) { + // Loop through the layers + for(var i = 0; i < tilemap.layers.length; i++) { + var layer = tilemap.layers[i]; + if(layer.visible == false || layer.alpha < 0.1) { + continue; + } + // Work out how many tiles we can fit into our camera and round it up for the edges + this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1; + this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1; + // And now work out where in the tilemap the camera actually is + this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth); + this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight); + // Tilemap bounds check + if(this._startX < 0) { + this._startX = 0; + } + if(this._startY < 0) { + this._startY = 0; + } + if(this._maxX > layer.widthInTiles) { + this._maxX = layer.widthInTiles; + } + if(this._maxY > layer.heightInTiles) { + this._maxY = layer.heightInTiles; + } + if(this._startX + this._maxX > layer.widthInTiles) { + this._startX = layer.widthInTiles - this._maxX; + } + if(this._startY + this._maxY > layer.heightInTiles) { + this._startY = layer.heightInTiles - this._maxY; + } + // Finally get the offset to avoid the blocky movement + //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x); + //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y); + //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x); + //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y); + this._dx = 0; + this._dy = 0; + this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth)); + this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight)); + this._tx = this._dx; + this._ty = this._dy; + // Alpha + if(layer.texture.alpha !== 1) { + this._ga = layer.texture.context.globalAlpha; + layer.texture.context.globalAlpha = layer.texture.alpha; + } + for(var row = this._startY; row < this._startY + this._maxY; row++) { + this._columnData = layer.mapData[row]; + for(var tile = this._startX; tile < this._startX + this._maxX; tile++) { + if(layer.tileOffsets[this._columnData[tile]]) { + layer.texture.context.drawImage(layer.texture.texture, layer.tileOffsets[this._columnData[tile]].x, layer.tileOffsets[this._columnData[tile]].y, layer.tileWidth, layer.tileHeight, this._tx, this._ty, layer.tileWidth, layer.tileHeight); + } + this._tx += layer.tileWidth; + } + this._tx = this._dx; + this._ty += layer.tileHeight; + } + if(this._ga > -1) { + layer.texture.context.globalAlpha = this._ga; + } + } + return true; + }; return CanvasRenderer; })(); Phaser.CanvasRenderer = CanvasRenderer; @@ -18626,6 +18687,11 @@ var Phaser; DebugUtils.context.fillStyle = color; DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height); }; + DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) { + if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; } + DebugUtils.context.fillStyle = fillStyle; + DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height); + }; DebugUtils.renderPhysicsBody = function renderPhysicsBody(body, lineWidth, fillStyle, sleepStyle) { if (typeof lineWidth === "undefined") { lineWidth = 1; } if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; } @@ -19094,84 +19160,6 @@ var Phaser; })(); Phaser.Game = Game; })(Phaser || (Phaser = {})); -/// -/** -* Phaser - State -* -* This is a base State class which can be extended if you are creating your game using TypeScript. -*/ -var Phaser; -(function (Phaser) { - var State = (function () { - /** - * State constructor - * Create a new State. - */ - function State(game) { - this.game = game; - this.add = game.add; - this.camera = game.camera; - this.cache = game.cache; - this.input = game.input; - this.load = game.load; - this.math = game.math; - this.motion = game.motion; - this.sound = game.sound; - this.stage = game.stage; - this.time = game.time; - this.tweens = game.tweens; - this.world = game.world; - } - State.prototype.init = // Override these in your own States - /** - * Override this method to add some load operations. - * If you need to use the loader, you may need to use them here. - */ - function () { - }; - State.prototype.create = /** - * This method is called after the game engine successfully switches states. - * Feel free to add any setup code here.(Do not load anything here, override init() instead) - */ - function () { - }; - State.prototype.update = /** - * Put update logic here. - */ - function () { - }; - State.prototype.render = /** - * Put render operations here. - */ - function () { - }; - State.prototype.paused = /** - * This method will be called when game paused. - */ - function () { - }; - State.prototype.destroy = /** - * This method will be called when the state is destroyed - */ - function () { - }; - return State; - })(); - Phaser.State = State; - /** - * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. - * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. - * @param object1 The first GameObject or Group to check. If null the world.group is used. - * @param object2 The second GameObject or Group to check. - * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. - * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. - * @param context The context in which the callbacks will be called - * @returns {boolean} true if the objects overlap, otherwise false. - */ - //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool { - // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context); - //} - })(Phaser || (Phaser = {})); var Phaser; (function (Phaser) { /** @@ -19514,206 +19502,6 @@ var Phaser; Phaser.Line = Line; })(Phaser || (Phaser = {})); /// -/** -* Phaser - IntersectResult -* -* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. -*/ -var Phaser; -(function (Phaser) { - var IntersectResult = (function () { - function IntersectResult() { - /** - * Did they intersect or not? - * @property result - * @type {Boolean} - */ - this.result = false; - } - IntersectResult.prototype.setTo = /** - * - * @method setTo - * @param {Number} x1 - * @param {Number} y1 - * @param {Number} [x2] - * @param {Number} [y2] - * @param {Number} [width] - * @param {Number} [height] - */ - function (x1, y1, x2, y2, width, height) { - if (typeof x2 === "undefined") { x2 = 0; } - if (typeof y2 === "undefined") { y2 = 0; } - if (typeof width === "undefined") { width = 0; } - if (typeof height === "undefined") { height = 0; } - this.x = x1; - this.y = y1; - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - this.width = width; - this.height = height; - }; - return IntersectResult; - })(); - Phaser.IntersectResult = IntersectResult; -})(Phaser || (Phaser = {})); -/// -/// -/// -/** -* Phaser - Mat3Utils -* -* A collection of methods useful for manipulating and performing operations on Mat3 objects. -* -*/ -var Phaser; -(function (Phaser) { - var Mat3Utils = (function () { - function Mat3Utils() { } - Mat3Utils.transpose = /** - * Transpose the values of a Mat3 - **/ - function transpose(source, dest) { - if (typeof dest === "undefined") { dest = null; } - if(dest === null) { - // Transpose ourselves - var a01 = source.data[1]; - var a02 = source.data[2]; - var a12 = source.data[5]; - source.data[1] = source.data[3]; - source.data[2] = source.data[6]; - source.data[3] = a01; - source.data[5] = source.data[7]; - source.data[6] = a02; - source.data[7] = a12; - } else { - source.data[0] = dest.data[0]; - source.data[1] = dest.data[3]; - source.data[2] = dest.data[6]; - source.data[3] = dest.data[1]; - source.data[4] = dest.data[4]; - source.data[5] = dest.data[7]; - source.data[6] = dest.data[2]; - source.data[7] = dest.data[5]; - source.data[8] = dest.data[8]; - } - return source; - }; - Mat3Utils.invert = /** - * Inverts a Mat3 - **/ - function invert(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - var b01 = a22 * a11 - a12 * a21; - var b11 = -a22 * a10 + a12 * a20; - var b21 = a21 * a10 - a11 * a20; - // Determinant - var det = a00 * b01 + a01 * b11 + a02 * b21; - if(!det) { - return null; - } - det = 1.0 / det; - source.data[0] = b01 * det; - source.data[1] = (-a22 * a01 + a02 * a21) * det; - source.data[2] = (a12 * a01 - a02 * a11) * det; - source.data[3] = b11 * det; - source.data[4] = (a22 * a00 - a02 * a20) * det; - source.data[5] = (-a12 * a00 + a02 * a10) * det; - source.data[6] = b21 * det; - source.data[7] = (-a21 * a00 + a01 * a20) * det; - source.data[8] = (a11 * a00 - a01 * a10) * det; - return source; - }; - Mat3Utils.adjoint = /** - * Calculates the adjugate of a Mat3 - **/ - function adjoint(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - source.data[0] = (a11 * a22 - a12 * a21); - source.data[1] = (a02 * a21 - a01 * a22); - source.data[2] = (a01 * a12 - a02 * a11); - source.data[3] = (a12 * a20 - a10 * a22); - source.data[4] = (a00 * a22 - a02 * a20); - source.data[5] = (a02 * a10 - a00 * a12); - source.data[6] = (a10 * a21 - a11 * a20); - source.data[7] = (a01 * a20 - a00 * a21); - source.data[8] = (a00 * a11 - a01 * a10); - return source; - }; - Mat3Utils.determinant = /** - * Calculates the adjugate of a Mat3 - **/ - function determinant(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); - }; - Mat3Utils.multiply = /** - * Multiplies two Mat3s - **/ - function multiply(source, b) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - var b00 = b.data[0]; - var b01 = b.data[1]; - var b02 = b.data[2]; - var b10 = b.data[3]; - var b11 = b.data[4]; - var b12 = b.data[5]; - var b20 = b.data[6]; - var b21 = b.data[7]; - var b22 = b.data[8]; - source.data[0] = b00 * a00 + b01 * a10 + b02 * a20; - source.data[1] = b00 * a01 + b01 * a11 + b02 * a21; - source.data[2] = b00 * a02 + b01 * a12 + b02 * a22; - source.data[3] = b10 * a00 + b11 * a10 + b12 * a20; - source.data[4] = b10 * a01 + b11 * a11 + b12 * a21; - source.data[5] = b10 * a02 + b11 * a12 + b12 * a22; - source.data[6] = b20 * a00 + b21 * a10 + b22 * a20; - source.data[7] = b20 * a01 + b21 * a11 + b22 * a21; - source.data[8] = b20 * a02 + b21 * a12 + b22 * a22; - return source; - }; - Mat3Utils.fromQuaternion = function fromQuaternion() { - }; - Mat3Utils.normalFromMat4 = function normalFromMat4() { - }; - return Mat3Utils; - })(); - Phaser.Mat3Utils = Mat3Utils; -})(Phaser || (Phaser = {})); -/// /// /// /// @@ -19877,6 +19665,161 @@ var Phaser; Phaser.CircleUtils = CircleUtils; })(Phaser || (Phaser = {})); /// +/// +/// +/** +* Phaser - Mat3Utils +* +* A collection of methods useful for manipulating and performing operations on Mat3 objects. +* +*/ +var Phaser; +(function (Phaser) { + var Mat3Utils = (function () { + function Mat3Utils() { } + Mat3Utils.transpose = /** + * Transpose the values of a Mat3 + **/ + function transpose(source, dest) { + if (typeof dest === "undefined") { dest = null; } + if(dest === null) { + // Transpose ourselves + var a01 = source.data[1]; + var a02 = source.data[2]; + var a12 = source.data[5]; + source.data[1] = source.data[3]; + source.data[2] = source.data[6]; + source.data[3] = a01; + source.data[5] = source.data[7]; + source.data[6] = a02; + source.data[7] = a12; + } else { + source.data[0] = dest.data[0]; + source.data[1] = dest.data[3]; + source.data[2] = dest.data[6]; + source.data[3] = dest.data[1]; + source.data[4] = dest.data[4]; + source.data[5] = dest.data[7]; + source.data[6] = dest.data[2]; + source.data[7] = dest.data[5]; + source.data[8] = dest.data[8]; + } + return source; + }; + Mat3Utils.invert = /** + * Inverts a Mat3 + **/ + function invert(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + var b01 = a22 * a11 - a12 * a21; + var b11 = -a22 * a10 + a12 * a20; + var b21 = a21 * a10 - a11 * a20; + // Determinant + var det = a00 * b01 + a01 * b11 + a02 * b21; + if(!det) { + return null; + } + det = 1.0 / det; + source.data[0] = b01 * det; + source.data[1] = (-a22 * a01 + a02 * a21) * det; + source.data[2] = (a12 * a01 - a02 * a11) * det; + source.data[3] = b11 * det; + source.data[4] = (a22 * a00 - a02 * a20) * det; + source.data[5] = (-a12 * a00 + a02 * a10) * det; + source.data[6] = b21 * det; + source.data[7] = (-a21 * a00 + a01 * a20) * det; + source.data[8] = (a11 * a00 - a01 * a10) * det; + return source; + }; + Mat3Utils.adjoint = /** + * Calculates the adjugate of a Mat3 + **/ + function adjoint(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + source.data[0] = (a11 * a22 - a12 * a21); + source.data[1] = (a02 * a21 - a01 * a22); + source.data[2] = (a01 * a12 - a02 * a11); + source.data[3] = (a12 * a20 - a10 * a22); + source.data[4] = (a00 * a22 - a02 * a20); + source.data[5] = (a02 * a10 - a00 * a12); + source.data[6] = (a10 * a21 - a11 * a20); + source.data[7] = (a01 * a20 - a00 * a21); + source.data[8] = (a00 * a11 - a01 * a10); + return source; + }; + Mat3Utils.determinant = /** + * Calculates the adjugate of a Mat3 + **/ + function determinant(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); + }; + Mat3Utils.multiply = /** + * Multiplies two Mat3s + **/ + function multiply(source, b) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + var b00 = b.data[0]; + var b01 = b.data[1]; + var b02 = b.data[2]; + var b10 = b.data[3]; + var b11 = b.data[4]; + var b12 = b.data[5]; + var b20 = b.data[6]; + var b21 = b.data[7]; + var b22 = b.data[8]; + source.data[0] = b00 * a00 + b01 * a10 + b02 * a20; + source.data[1] = b00 * a01 + b01 * a11 + b02 * a21; + source.data[2] = b00 * a02 + b01 * a12 + b02 * a22; + source.data[3] = b10 * a00 + b11 * a10 + b12 * a20; + source.data[4] = b10 * a01 + b11 * a11 + b12 * a21; + source.data[5] = b10 * a02 + b11 * a12 + b12 * a22; + source.data[6] = b20 * a00 + b21 * a10 + b22 * a20; + source.data[7] = b20 * a01 + b21 * a11 + b22 * a21; + source.data[8] = b20 * a02 + b21 * a12 + b22 * a22; + return source; + }; + Mat3Utils.fromQuaternion = function fromQuaternion() { + }; + Mat3Utils.normalFromMat4 = function normalFromMat4() { + }; + return Mat3Utils; + })(); + Phaser.Mat3Utils = Mat3Utils; +})(Phaser || (Phaser = {})); +/// /// /// /// @@ -19904,3 +19847,126 @@ var Phaser; })(); Phaser.PixelUtils = PixelUtils; })(Phaser || (Phaser = {})); +/// +/** +* Phaser - IntersectResult +* +* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. +*/ +var Phaser; +(function (Phaser) { + var IntersectResult = (function () { + function IntersectResult() { + /** + * Did they intersect or not? + * @property result + * @type {Boolean} + */ + this.result = false; + } + IntersectResult.prototype.setTo = /** + * + * @method setTo + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} [x2] + * @param {Number} [y2] + * @param {Number} [width] + * @param {Number} [height] + */ + function (x1, y1, x2, y2, width, height) { + if (typeof x2 === "undefined") { x2 = 0; } + if (typeof y2 === "undefined") { y2 = 0; } + if (typeof width === "undefined") { width = 0; } + if (typeof height === "undefined") { height = 0; } + this.x = x1; + this.y = y1; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.width = width; + this.height = height; + }; + return IntersectResult; + })(); + Phaser.IntersectResult = IntersectResult; +})(Phaser || (Phaser = {})); +/// +/** +* Phaser - State +* +* This is a base State class which can be extended if you are creating your game using TypeScript. +*/ +var Phaser; +(function (Phaser) { + var State = (function () { + /** + * State constructor + * Create a new State. + */ + function State(game) { + this.game = game; + this.add = game.add; + this.camera = game.camera; + this.cache = game.cache; + this.input = game.input; + this.load = game.load; + this.math = game.math; + this.motion = game.motion; + this.sound = game.sound; + this.stage = game.stage; + this.time = game.time; + this.tweens = game.tweens; + this.world = game.world; + } + State.prototype.init = // Override these in your own States + /** + * Override this method to add some load operations. + * If you need to use the loader, you may need to use them here. + */ + function () { + }; + State.prototype.create = /** + * This method is called after the game engine successfully switches states. + * Feel free to add any setup code here.(Do not load anything here, override init() instead) + */ + function () { + }; + State.prototype.update = /** + * Put update logic here. + */ + function () { + }; + State.prototype.render = /** + * Put render operations here. + */ + function () { + }; + State.prototype.paused = /** + * This method will be called when game paused. + */ + function () { + }; + State.prototype.destroy = /** + * This method will be called when the state is destroyed + */ + function () { + }; + return State; + })(); + Phaser.State = State; + /** + * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. + * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. + * @param object1 The first GameObject or Group to check. If null the world.group is used. + * @param object2 The second GameObject or Group to check. + * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. + * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. + * @param context The context in which the callbacks will be called + * @returns {boolean} true if the objects overlap, otherwise false. + */ + //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool { + // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context); + //} + })(Phaser || (Phaser = {})); diff --git a/Tests/physics/simple test 1.js b/Tests/physics/simple test 1.js index 44a660aa..ca4c0736 100644 --- a/Tests/physics/simple test 1.js +++ b/Tests/physics/simple test 1.js @@ -1,6 +1,8 @@ +/// (function () { var game = new Phaser.Game(this, 'game', 800, 600, init, create, null, render); function init() { + // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('atari', 'assets/sprites/atari130xe.png'); game.load.image('ball', 'assets/sprites/shinyball.png'); game.load.start(); @@ -8,10 +10,21 @@ var atari; var ball; function create() { + // Add some gravity to the world, otherwise nothing will actually happen game.physics.gravity.setTo(0, 5); + // We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC); + //atari.rotation = 10; + //atari.body.transform.setRotation(1); + atari.body.angle = 1; + // atari = 220px width (110 = center x) + // ball = 32px width (16 = center x) + // Ball will be a dynamic body and fall based on gravity ball = game.add.physicsSprite(300 - 20, 0, 'ball'); - } + ball.body.angle = 1; + //ball.body.transform.setRotation(1); + //ball.body.fixedRotation = true; + } function render() { Phaser.DebugUtils.renderPhysicsBodyInfo(atari.body, 32, 32); Phaser.DebugUtils.renderPhysicsBodyInfo(ball.body, 320, 32); diff --git a/Tests/physics/simple test 1.ts b/Tests/physics/simple test 1.ts index aef0b341..a34964d3 100644 --- a/Tests/physics/simple test 1.ts +++ b/Tests/physics/simple test 1.ts @@ -23,12 +23,18 @@ // We'll make the atari sprite a static body, so it won't be influenced by gravity or other forces atari = game.add.physicsSprite(300, 450, 'atari', null, Phaser.Types.BODY_STATIC); + //atari.rotation = 10; + //atari.body.transform.setRotation(1); + atari.body.angle = 1; // atari = 220px width (110 = center x) // ball = 32px width (16 = center x) // Ball will be a dynamic body and fall based on gravity ball = game.add.physicsSprite(300-20, 0, 'ball'); + ball.body.angle = 1; + //ball.body.transform.setRotation(1); + //ball.body.fixedRotation = true; } diff --git a/Tests/tilemaps/csv tilemap.js b/Tests/tilemaps/csv tilemap.js new file mode 100644 index 00000000..3042fc47 --- /dev/null +++ b/Tests/tilemaps/csv tilemap.js @@ -0,0 +1,32 @@ +/// +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + function init() { + // CSV Tilemap Test + // First we load our map data (a csv file) + game.load.text('csvtest', 'assets/maps/catastrophi_level2.csv'); + // Then we load the actual tile sheet image + game.load.image('csvtiles', 'assets/tiles/catastrophi_tiles_16.png'); + game.load.start(); + } + function create() { + // This creates the tilemap using the csv and tile sheet we loaded. + // We tell it use to CSV format parser. The 16x16 are the tile sizes. + // The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not. + game.add.tilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16); + } + function update() { + // Simple camera controls + if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + game.camera.x -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + game.camera.x += 4; + } + if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + game.camera.y -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + game.camera.y += 4; + } + } +})(); diff --git a/Tests/tilemaps/csv tilemap.ts b/Tests/tilemaps/csv tilemap.ts new file mode 100644 index 00000000..a0558dd4 --- /dev/null +++ b/Tests/tilemaps/csv tilemap.ts @@ -0,0 +1,54 @@ +/// +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + function init() { + + // CSV Tilemap Test + + // First we load our map data (a csv file) + game.load.text('csvtest', 'assets/maps/catastrophi_level2.csv'); + + // Then we load the actual tile sheet image + game.load.image('csvtiles', 'assets/tiles/catastrophi_tiles_16.png'); + + game.load.start(); + + } + + function create() { + + // This creates the tilemap using the csv and tile sheet we loaded. + // We tell it use to CSV format parser. The 16x16 are the tile sizes. + // The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not. + game.add.tilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16); + + } + + function update() { + + // Simple camera controls + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + game.camera.x -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + game.camera.x += 4; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + game.camera.y -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + game.camera.y += 4; + } + + } + +})(); diff --git a/Tests/tilemaps/map draw.js b/Tests/tilemaps/map draw.js new file mode 100644 index 00000000..55107d28 --- /dev/null +++ b/Tests/tilemaps/map draw.js @@ -0,0 +1,41 @@ +/// +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + function init() { + game.load.text('platform', 'assets/maps/mapdraw.json'); + game.load.image('tiles', 'assets/tiles/platformer_tiles.png'); + game.load.image('carrot', 'assets/sprites/carrot.png'); + game.load.start(); + } + var map; + var emitter; + var marker; + function create() { + map = game.add.tilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON); + map.setCollisionRange(21, 53); + map.setCollisionRange(105, 109); + game.camera.texture.opaque = true; + game.camera.texture.backgroundColor = 'rgb(47,154,204)'; + marker = game.add.sprite(0, 0); + marker.texture.width = 16; + marker.texture.height = 16; + marker.texture.opaque = true; + marker.texture.backgroundColor = 'rgba(255,0,0,0.4)'; + //emitter = game.add.emitter(32, 80); + //emitter.width = 700; + //emitter.makeParticles('carrot', 100, false, 1); + //emitter.gravity = 150; + //emitter.bounce = 0.8; + //emitter.start(false, 20, 0.05); + } + function update() { + // Collide everything with the map + //map.collide(); + marker.x = game.math.snapToFloor(game.input.getWorldX(), 16); + marker.y = game.math.snapToFloor(game.input.getWorldY(), 16); + if(game.input.mousePointer.isDown) { + map.putTile(marker.x, marker.y, 32); + } + } +})(); diff --git a/Tests/tilemaps/map draw.ts b/Tests/tilemaps/map draw.ts new file mode 100644 index 00000000..5eae897d --- /dev/null +++ b/Tests/tilemaps/map draw.ts @@ -0,0 +1,60 @@ +/// +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + function init() { + + game.load.text('platform', 'assets/maps/mapdraw.json'); + game.load.image('tiles', 'assets/tiles/platformer_tiles.png'); + game.load.image('carrot', 'assets/sprites/carrot.png'); + + game.load.start(); + + } + + var map: Phaser.Tilemap; + var emitter: Phaser.Emitter; + var marker: Phaser.Sprite; + + function create() { + + map = game.add.tilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON); + map.setCollisionRange(21,53); + map.setCollisionRange(105,109); + + game.camera.texture.opaque = true; + game.camera.texture.backgroundColor = 'rgb(47,154,204)'; + + marker = game.add.sprite(0, 0); + marker.texture.width = 16; + marker.texture.height = 16; + marker.texture.opaque = true; + marker.texture.backgroundColor = 'rgba(255,0,0,0.4)'; + + //emitter = game.add.emitter(32, 80); + //emitter.width = 700; + //emitter.makeParticles('carrot', 100, false, 1); + //emitter.gravity = 150; + //emitter.bounce = 0.8; + //emitter.start(false, 20, 0.05); + } + + function update() { + + // Collide everything with the map + //map.collide(); + + marker.x = game.math.snapToFloor(game.input.getWorldX(), 16); + marker.y = game.math.snapToFloor(game.input.getWorldY(), 16); + + if (game.input.mousePointer.isDown) + { + map.putTile(marker.x, marker.y, 32); + } + + } + +})(); diff --git a/Tests/tilemaps/tiled layers.js b/Tests/tilemaps/tiled layers.js new file mode 100644 index 00000000..42a8af61 --- /dev/null +++ b/Tests/tilemaps/tiled layers.js @@ -0,0 +1,34 @@ +/// +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + function init() { + // Tiled Tilemap Test + // First we load our map data (a json file exported from the map editor Tiled) + // This data file has several layers within it. Phaser will render them all. + game.load.text('jsontest', 'assets/maps/multi-layer-test.json'); + // Then we load the actual tile sheet image + game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); + game.load.start(); + } + var map; + function create() { + // This creates the tilemap using the json data and tile sheet we loaded. + // We tell it to use the Tiled JSON format parser. + map = game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); + //map.currentLayer. + } + function update() { + // Simple camera controls + if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + game.camera.x -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + game.camera.x += 4; + } + if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + game.camera.y -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + game.camera.y += 4; + } + } +})(); diff --git a/Tests/tilemaps/tiled layers.ts b/Tests/tilemaps/tiled layers.ts new file mode 100644 index 00000000..4fb89db7 --- /dev/null +++ b/Tests/tilemaps/tiled layers.ts @@ -0,0 +1,58 @@ +/// +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + function init() { + + // Tiled Tilemap Test + + // First we load our map data (a json file exported from the map editor Tiled) + // This data file has several layers within it. Phaser will render them all. + game.load.text('jsontest', 'assets/maps/multi-layer-test.json'); + + // Then we load the actual tile sheet image + game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); + + game.load.start(); + + } + + var map: Phaser.Tilemap; + + function create() { + + // This creates the tilemap using the json data and tile sheet we loaded. + // We tell it to use the Tiled JSON format parser. + map = game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); + + //map.currentLayer. + + } + + function update() { + + // Simple camera controls + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + game.camera.x -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + game.camera.x += 4; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + game.camera.y -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + game.camera.y += 4; + } + + } + +})(); diff --git a/Tests/tilemaps/tiled tilemap.js b/Tests/tilemaps/tiled tilemap.js new file mode 100644 index 00000000..55447fbe --- /dev/null +++ b/Tests/tilemaps/tiled tilemap.js @@ -0,0 +1,32 @@ +/// +/// +(function () { + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + function init() { + // Tiled Tilemap Test + // First we load our map data (a json file exported from the map editor Tiled) + game.load.text('jsontest', 'assets/maps/test.json'); + //myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json'); + // Then we load the actual tile sheet image + game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); + game.load.start(); + } + function create() { + // This creates the tilemap using the json data and tile sheet we loaded. + // We tell it to use the Tiled JSON format parser. + game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); + } + function update() { + // Simple camera controls + if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + game.camera.x -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + game.camera.x += 4; + } + if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + game.camera.y -= 4; + } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + game.camera.y += 4; + } + } +})(); diff --git a/Tests/tilemaps/tiled tilemap.ts b/Tests/tilemaps/tiled tilemap.ts new file mode 100644 index 00000000..749eb47f --- /dev/null +++ b/Tests/tilemaps/tiled tilemap.ts @@ -0,0 +1,54 @@ +/// +/// + +(function () { + + var game = new Phaser.Game(this, 'game', 800, 600, init, create, update); + + function init() { + + // Tiled Tilemap Test + + // First we load our map data (a json file exported from the map editor Tiled) + game.load.text('jsontest', 'assets/maps/test.json'); + //myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json'); + + // Then we load the actual tile sheet image + game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); + + game.load.start(); + + } + + function create() { + + // This creates the tilemap using the json data and tile sheet we loaded. + // We tell it to use the Tiled JSON format parser. + game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); + + } + + function update() { + + // Simple camera controls + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) + { + game.camera.x -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) + { + game.camera.x += 4; + } + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) + { + game.camera.y -= 4; + } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + game.camera.y += 4; + } + + } + +})(); diff --git a/build/phaser.d.ts b/build/phaser.d.ts index ca875925..2db10b2e 100644 --- a/build/phaser.d.ts +++ b/build/phaser.d.ts @@ -240,6 +240,10 @@ module Phaser { */ group: Group; /** + * The name of the Game Object. Typically not set by Phaser, but extremely useful for debugging / logic. + */ + name: string; + /** * x value of the object. */ x: number; @@ -2335,6 +2339,14 @@ module Phaser.Components.Sprite { * Dispatched by the Input component when a pointer is released over an Input enabled sprite */ public onInputUp: Signal; + /** + * Dispatched by the Input component when the Sprite starts being dragged + */ + public onDragStart: Signal; + /** + * Dispatched by the Input component when the Sprite stops being dragged + */ + public onDragStop: Signal; public onOutOfBounds: Signal; } } @@ -3049,8 +3061,8 @@ module Phaser.Physics.Shapes { module Phaser.Physics { class Body { constructor(sprite: Sprite, type: number, x?: number, y?: number, shapeType?: number); - public toString(): string; private _tempVec2; + private _fixedRotation; /** * Reference to Phaser.Game */ @@ -3076,7 +3088,18 @@ module Phaser.Physics { * @type {number} */ public type: number; + /** + * The angle of the body in radians. Used by all of the internal physics methods. + */ public angle: number; + /** + * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + */ + /** + * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + * The value is automatically wrapped to be between 0 and 360. + */ + public rotation : number; public transform: Transform; public centroid: Vec2; public position: Vec2; @@ -3098,7 +3121,6 @@ module Phaser.Physics { public massInverted: number; public inertia: number; public inertiaInverted: number; - public fixedRotation: bool; public categoryBits: number; public maskBits: number; public stepCount: number; @@ -3117,13 +3139,13 @@ module Phaser.Physics { public removeShape(shape): void; private setMass(mass); private setInertia(inertia); - public setTransform(pos, angle): void; + public setTransform(pos: Vec2, angle: number): void; public syncTransform(): void; public getWorldPoint(p: Vec2): Vec2; public getWorldVector(v: Vec2): Vec2; public getLocalPoint(p: Vec2): Vec2; public getLocalVector(v: Vec2): Vec2; - public setFixedRotation(flag): void; + public fixedRotation : bool; public resetMassData(): void; public resetJointAnchors(): void; public cacheData(source?: string): void; @@ -3141,6 +3163,7 @@ module Phaser.Physics { public isAwake : bool; public awake(flag): void; public isCollidable(other: Body): bool; + public toString(): string; } } /** @@ -3155,7 +3178,7 @@ module Phaser { * @param [x] {number} the initial x position of the sprite. * @param [y] {number} the initial y position of the sprite. * @param [key] {string} Key of the graphic you want to load for this sprite. - * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED) + * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics) * @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape) */ constructor(game: Game, x?: number, y?: number, key?: string, frame?, bodyType?: number, shapeType?: number); @@ -3168,6 +3191,10 @@ module Phaser { */ public type: number; /** + * The name of game object. + */ + public name: string; + /** * The Group this Sprite belongs to. */ public group: Group; @@ -3486,6 +3513,11 @@ module Phaser.Components { */ public renderRotation: bool; /** + * The direction the animation frame is facing (can be Phaser.Types.RIGHT, LEFT, UP, DOWN). + * Very useful when hooking animation to Sprite directions. + */ + public facing: number; + /** * Flip the graphic horizontally (defaults to false) * @type {boolean} */ @@ -5661,6 +5693,7 @@ module Phaser { public to(properties, duration?: number, ease?: any, autoStart?: bool, delay?: number, loop?: bool, yoyo?: bool): Tween; public loop(value: bool): Tween; public yoyo(value: bool): Tween; + public isRunning: bool; /** * Start to tween. */ @@ -6065,31 +6098,6 @@ module Phaser { * @param tileHeight {number} Height of tiles in this map. */ constructor(game: Game, parent: Tilemap, key: string, mapFormat: number, name: string, tileWidth: number, tileHeight: number); - /** - * Local private reference to game. - */ - private _game; - /** - * The tilemap that contains this layer. - * @type {Tilemap} - */ - private _parent; - /** - * Tileset of this layer. - */ - private _texture; - private _tileOffsets; - private _startX; - private _startY; - private _maxX; - private _maxY; - private _tx; - private _ty; - private _dx; - private _dy; - private _oldCameraX; - private _oldCameraY; - private _columnData; private _tempTileX; private _tempTileY; private _tempTileW; @@ -6097,26 +6105,33 @@ module Phaser { private _tempTileBlock; private _tempBlockResults; /** + * Local private reference to game. + */ + public game: Game; + /** + * The tilemap that contains this layer. + * @type {Tilemap} + */ + public parent: Tilemap; + /** + * The texture used to render the Sprite. + */ + public texture: Components.Texture; + /** + * The Sprite transform component. + */ + public transform: Components.Transform; + public tileOffsets; + /** + * The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque. + */ + public alpha: number; + /** * Name of this layer, so you can get this layer by its name. * @type {string} */ public name: string; /** - * A reference to the Canvas this GameObject will render to - * @type {HTMLCanvasElement} - */ - public canvas: HTMLCanvasElement; - /** - * A reference to the Canvas Context2D this GameObject will render to - * @type {CanvasRenderingContext2D} - */ - public context: CanvasRenderingContext2D; - /** - * Opacity of this layer. - * @type {number} - */ - public alpha: number; - /** * Controls whether update() and draw() are automatically called. * @type {boolean} */ @@ -6127,10 +6142,6 @@ module Phaser { */ public visible: bool; /** - * @type {string} - */ - public orientation: string; - /** * Properties of this map layer. (normally set by map editors) */ public properties: {}; @@ -6282,18 +6293,9 @@ module Phaser { public updateBounds(): void; /** * Parse tile offsets from map data. - * @return {number} length of _tileOffsets array. + * @return {number} length of tileOffsets array. */ public parseTileOffsets(): number; - public renderDebugInfo(x: number, y: number, color?: string): void; - /** - * Render this layer to a specific camera with offset to camera. - * @param camera {Camera} The camera the layer is going to be rendered. - * @param dx {number} X offset to the camera. - * @param dy {number} Y offset to the camera. - * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed. - */ - public render(camera: Camera, dx, dy): bool; } } /** @@ -6439,6 +6441,14 @@ module Phaser { */ public type: number; /** + * The name of game object. + */ + public name: string; + /** + * The Group this Sprite belongs to. + */ + public group: Group; + /** * Controls if both update and render are called by the core game loop. */ public exists: bool; @@ -6451,10 +6461,26 @@ module Phaser { */ public visible: bool; /** - * + * A useful state for many game objects. Kill and revive both flip this switch. */ public alive: bool; /** + * The texture used to render the Sprite. + */ + public texture: Components.Texture; + /** + * The Sprite transform component. + */ + public transform: Components.Transform; + /** + * z order value of the object. + */ + public z: number; + /** + * Render iteration counter + */ + public renderOrderID: number; + /** * Tilemap data format enum: CSV. * @type {number} */ @@ -6499,21 +6525,11 @@ module Phaser { */ public mapFormat: number; /** - * An Array of Cameras to which this GameObject won't render - * @type {Array} - */ - public cameraBlacklist: number[]; - /** - * Inherited update method. + * Inherited methods for overriding. */ + public preUpdate(): void; public update(): void; - /** - * Render this tilemap to a specific camera with specific offset. - * @param camera {Camera} The camera this tilemap will be rendered to. - * @param cameraOffsetX {number} X offset of the camera. - * @param cameraOffsetY {number} Y offset of the camera. - */ - public render(camera: Camera, cameraOffsetX: number, cameraOffsetY: number): void; + public postUpdate(): void; /** * Parset csv map data and generate tiles. * @param data {string} CSV map data. @@ -8122,6 +8138,118 @@ module Phaser { * TODO: interpolate & polar */ module Phaser { + class PointUtils { + /** + * Adds the coordinates of two points together to create a new point. + * @method add + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created. + * @return {Point} The new Point object. + **/ + static add(a: Point, b: Point, out?: Point): Point; + /** + * Subtracts the coordinates of two points to create a new point. + * @method subtract + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created. + * @return {Point} The new Point object. + **/ + static subtract(a: Point, b: Point, out?: Point): Point; + /** + * Multiplies the coordinates of two points to create a new point. + * @method subtract + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created. + * @return {Point} The new Point object. + **/ + static multiply(a: Point, b: Point, out?: Point): Point; + /** + * Divides the coordinates of two points to create a new point. + * @method subtract + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @param {Point} out - Optional Point to store the value in, if not supplied a new Point object will be created. + * @return {Point} The new Point object. + **/ + static divide(a: Point, b: Point, out?: Point): Point; + /** + * Clamps the Point object values to be between the given min and max + * @method clamp + * @param {Point} a - The point. + * @param {number} The minimum value to clamp this Point to + * @param {number} The maximum value to clamp this Point to + * @return {Point} This Point object. + **/ + static clamp(a: Point, min: number, max: number): Point; + /** + * Clamps the x value of the given Point object to be between the min and max values. + * @method clampX + * @param {Point} a - The point. + * @param {number} The minimum value to clamp this Point to + * @param {number} The maximum value to clamp this Point to + * @return {Point} This Point object. + **/ + static clampX(a: Point, min: number, max: number): Point; + /** + * Clamps the y value of the given Point object to be between the min and max values. + * @method clampY + * @param {Point} a - The point. + * @param {number} The minimum value to clamp this Point to + * @param {number} The maximum value to clamp this Point to + * @return {Point} This Point object. + **/ + static clampY(a: Point, min: number, max: number): Point; + /** + * Creates a copy of the given Point. + * @method clone + * @param {Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. + * @return {Point} The new Point object. + **/ + static clone(a: Point, output?: Point): Point; + /** + * Returns the distance between the two given Point objects. + * @method distanceBetween + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @param {Boolean} round - Round the distance to the nearest integer (default false) + * @return {Number} The distance between the two Point objects. + **/ + static distanceBetween(a: Point, b: Point, round?: bool): number; + /** + * Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values. + * @method equals + * @param {Point} a - The first Point object. + * @param {Point} b - The second Point object. + * @return {Boolean} A value of true if the Points are equal, otherwise false. + **/ + static equals(a: Point, b: Point): bool; + /** + * Rotates a Point around the x/y coordinates given to the desired angle. + * @param a {Point} The Point object to rotate. + * @param x {number} The x coordinate of the anchor point + * @param y {number} The y coordinate of the anchor point + * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to. + * @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)? + * @param {Number} distance An optional distance constraint between the Point and the anchor. + * @return The modified point object + */ + static rotate(a: Point, x: number, y: number, angle: number, asDegrees?: bool, distance?: number): Point; + /** + * Rotates a Point around the given Point to the desired angle. + * @param a {Point} The Point object to rotate. + * @param b {Point} The Point object to serve as point of rotation. + * @param x {number} The x coordinate of the anchor point + * @param y {number} The y coordinate of the anchor point + * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to. + * @param {Boolean} asDegrees Is the given rotation in radians (false) or degrees (true)? + * @param {Number} distance An optional distance constraint between the Point and the anchor. + * @return The modified point object + */ + static rotateAroundPoint(a: Point, b: Point, angle: number, asDegrees?: bool, distance?: number): Point; + } } /** * Phaser - Pointer @@ -9246,8 +9374,15 @@ module Phaser { private _dh; private _fx; private _fy; + private _tx; + private _ty; private _sin; private _cos; + private _maxX; + private _maxY; + private _startX; + private _startY; + private _columnData; private _cameraList; private _camera; private _groupLength; @@ -9279,6 +9414,11 @@ module Phaser { */ public renderSprite(camera: Camera, sprite: Sprite): bool; public renderScrollZone(camera: Camera, scrollZone: ScrollZone): bool; + /** + * Render a tilemap to a specific camera. + * @param camera {Camera} The camera this tilemap will be rendered to. + */ + public renderTilemap(camera: Camera, tilemap: Tilemap): bool; } } /** @@ -9309,6 +9449,7 @@ module Phaser { */ static renderPhysicsBodyInfo(body: Physics.Body, x: number, y: number, color?: string): void; static renderSpriteBounds(sprite: Sprite, camera?: Camera, color?: string): void; + static renderRectangle(rect: Rectangle, fillStyle?: string): void; static renderPhysicsBody(body: Physics.Body, lineWidth?: number, fillStyle?: string, sleepStyle?: string): void; } } @@ -9551,110 +9692,6 @@ module Phaser { } } /** -* Phaser - State -* -* This is a base State class which can be extended if you are creating your game using TypeScript. -*/ -module Phaser { - class State { - /** - * State constructor - * Create a new State. - */ - constructor(game: Game); - /** - * Reference to Game. - */ - public game: Game; - /** - * Currently used camera. - * @type {Camera} - */ - public camera: Camera; - /** - * Reference to the assets cache. - * @type {Cache} - */ - public cache: Cache; - /** - * Reference to the GameObject Factory. - * @type {GameObjectFactory} - */ - public add: GameObjectFactory; - /** - * Reference to the input manager - * @type {Input} - */ - public input: Input; - /** - * Reference to the assets loader. - * @type {Loader} - */ - public load: Loader; - /** - * Reference to the math helper. - * @type {GameMath} - */ - public math: GameMath; - /** - * Reference to the motion helper. - * @type {Motion} - */ - public motion: Motion; - /** - * Reference to the sound manager. - * @type {SoundManager} - */ - public sound: SoundManager; - /** - * Reference to the stage. - * @type {Stage} - */ - public stage: Stage; - /** - * Reference to game clock. - * @type {Time} - */ - public time: Time; - /** - * Reference to the tween manager. - * @type {TweenManager} - */ - public tweens: TweenManager; - /** - * Reference to the world. - * @type {World} - */ - public world: World; - /** - * Override this method to add some load operations. - * If you need to use the loader, you may need to use them here. - */ - public init(): void; - /** - * This method is called after the game engine successfully switches states. - * Feel free to add any setup code here.(Do not load anything here, override init() instead) - */ - public create(): void; - /** - * Put update logic here. - */ - public update(): void; - /** - * Put render operations here. - */ - public render(): void; - /** - * This method will be called when game paused. - */ - public paused(): void; - /** - * This method will be called when the state is destroyed - */ - public destroy(): void; - } -} -/** * Phaser - Components - Debug * * @@ -9835,104 +9872,6 @@ module Phaser { } } /** -* Phaser - IntersectResult -* -* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. -*/ -module Phaser { - class IntersectResult { - /** - * Did they intersect or not? - * @property result - * @type {Boolean} - */ - public result: bool; - /** - * @property x - * @type {Number} - */ - public x: number; - /** - * @property y - * @type {Number} - */ - public y: number; - /** - * @property x1 - * @type {Number} - */ - public x1: number; - /** - * @property y1 - * @type {Number} - */ - public y1: number; - /** - * @property x2 - * @type {Number} - */ - public x2: number; - /** - * @property y2 - * @type {Number} - */ - public y2: number; - /** - * @property width - * @type {Number} - */ - public width: number; - /** - * @property height - * @type {Number} - */ - public height: number; - /** - * - * @method setTo - * @param {Number} x1 - * @param {Number} y1 - * @param {Number} [x2] - * @param {Number} [y2] - * @param {Number} [width] - * @param {Number} [height] - */ - public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void; - } -} -/** -* Phaser - Mat3Utils -* -* A collection of methods useful for manipulating and performing operations on Mat3 objects. -* -*/ -module Phaser { - class Mat3Utils { - /** - * Transpose the values of a Mat3 - **/ - static transpose(source: Mat3, dest?: Mat3): Mat3; - /** - * Inverts a Mat3 - **/ - static invert(source: Mat3): Mat3; - /** - * Calculates the adjugate of a Mat3 - **/ - static adjoint(source: Mat3): Mat3; - /** - * Calculates the adjugate of a Mat3 - **/ - static determinant(source: Mat3): number; - /** - * Multiplies two Mat3s - **/ - static multiply(source: Mat3, b: Mat3): Mat3; - static fromQuaternion(): void; - static normalFromMat4(): void; - } -} -/** * Phaser - CircleUtils * * A collection of methods useful for manipulating and comparing Circle objects. @@ -10016,6 +9955,38 @@ module Phaser { } } /** +* Phaser - Mat3Utils +* +* A collection of methods useful for manipulating and performing operations on Mat3 objects. +* +*/ +module Phaser { + class Mat3Utils { + /** + * Transpose the values of a Mat3 + **/ + static transpose(source: Mat3, dest?: Mat3): Mat3; + /** + * Inverts a Mat3 + **/ + static invert(source: Mat3): Mat3; + /** + * Calculates the adjugate of a Mat3 + **/ + static adjoint(source: Mat3): Mat3; + /** + * Calculates the adjugate of a Mat3 + **/ + static determinant(source: Mat3): number; + /** + * Multiplies two Mat3s + **/ + static multiply(source: Mat3, b: Mat3): Mat3; + static fromQuaternion(): void; + static normalFromMat4(): void; + } +} +/** * Phaser - PixelUtils * * A collection of methods useful for manipulating pixels. @@ -10036,3 +10007,173 @@ module Phaser { static getPixel(key: string, x: number, y: number): number; } } +/** +* Phaser - IntersectResult +* +* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. +*/ +module Phaser { + class IntersectResult { + /** + * Did they intersect or not? + * @property result + * @type {Boolean} + */ + public result: bool; + /** + * @property x + * @type {Number} + */ + public x: number; + /** + * @property y + * @type {Number} + */ + public y: number; + /** + * @property x1 + * @type {Number} + */ + public x1: number; + /** + * @property y1 + * @type {Number} + */ + public y1: number; + /** + * @property x2 + * @type {Number} + */ + public x2: number; + /** + * @property y2 + * @type {Number} + */ + public y2: number; + /** + * @property width + * @type {Number} + */ + public width: number; + /** + * @property height + * @type {Number} + */ + public height: number; + /** + * + * @method setTo + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} [x2] + * @param {Number} [y2] + * @param {Number} [width] + * @param {Number} [height] + */ + public setTo(x1: number, y1: number, x2?: number, y2?: number, width?: number, height?: number): void; + } +} +/** +* Phaser - State +* +* This is a base State class which can be extended if you are creating your game using TypeScript. +*/ +module Phaser { + class State { + /** + * State constructor + * Create a new State. + */ + constructor(game: Game); + /** + * Reference to Game. + */ + public game: Game; + /** + * Currently used camera. + * @type {Camera} + */ + public camera: Camera; + /** + * Reference to the assets cache. + * @type {Cache} + */ + public cache: Cache; + /** + * Reference to the GameObject Factory. + * @type {GameObjectFactory} + */ + public add: GameObjectFactory; + /** + * Reference to the input manager + * @type {Input} + */ + public input: Input; + /** + * Reference to the assets loader. + * @type {Loader} + */ + public load: Loader; + /** + * Reference to the math helper. + * @type {GameMath} + */ + public math: GameMath; + /** + * Reference to the motion helper. + * @type {Motion} + */ + public motion: Motion; + /** + * Reference to the sound manager. + * @type {SoundManager} + */ + public sound: SoundManager; + /** + * Reference to the stage. + * @type {Stage} + */ + public stage: Stage; + /** + * Reference to game clock. + * @type {Time} + */ + public time: Time; + /** + * Reference to the tween manager. + * @type {TweenManager} + */ + public tweens: TweenManager; + /** + * Reference to the world. + * @type {World} + */ + public world: World; + /** + * Override this method to add some load operations. + * If you need to use the loader, you may need to use them here. + */ + public init(): void; + /** + * This method is called after the game engine successfully switches states. + * Feel free to add any setup code here.(Do not load anything here, override init() instead) + */ + public create(): void; + /** + * Put update logic here. + */ + public update(): void; + /** + * Put render operations here. + */ + public render(): void; + /** + * This method will be called when game paused. + */ + public paused(): void; + /** + * This method will be called when the state is destroyed + */ + public destroy(): void; + } +} diff --git a/build/phaser.js b/build/phaser.js index 0df38b19..f5d4f68f 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -3787,6 +3787,7 @@ var Phaser; if(this.bringToTop) { this.sprite.group.bringToTop(this.sprite); } + this.sprite.events.onDragStart.dispatch(this.sprite, pointer); }; Input.prototype.stopDrag = /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. @@ -3799,8 +3800,8 @@ var Phaser; this.sprite.x = Math.floor(this.sprite.x / this.snapX) * this.snapX; this.sprite.y = Math.floor(this.sprite.y / this.snapY) * this.snapY; } - //pointer.draggedObject = null; - }; + this.sprite.events.onDragStop.dispatch(this.sprite, pointer); + }; Input.prototype.setDragLock = /** * Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! * @@ -3913,10 +3914,13 @@ var Phaser; this.onRemovedFromGroup = new Phaser.Signal(); this.onKilled = new Phaser.Signal(); this.onRevived = new Phaser.Signal(); + // Only create these if Sprite input is enabled? this.onInputOver = new Phaser.Signal(); this.onInputOut = new Phaser.Signal(); this.onInputDown = new Phaser.Signal(); this.onInputUp = new Phaser.Signal(); + this.onDragStart = new Phaser.Signal(); + this.onDragStop = new Phaser.Signal(); } return Events; })(); @@ -5158,9 +5162,7 @@ var Phaser; var r2 = new Phaser.Vec2(); // Transformed r1, r2 Phaser.Vec2Utils.rotate(con.r1_local, body1.angle, r1); - //var r1 = vec2.rotate(con.r1_local, body1.a); Phaser.Vec2Utils.rotate(con.r2_local, body2.angle, r2); - //var r2 = vec2.rotate(con.r2_local, body2.a); Physics.Manager.write('r1_local.x = ' + con.r1_local.x + ' r1_local.y = ' + con.r1_local.y + ' angle: ' + body1.angle); Physics.Manager.write('r1 rotated: r1.x = ' + r1.x + ' r1.y = ' + r1.y); Physics.Manager.write('r2_local.x = ' + con.r2_local.x + ' r2_local.y = ' + con.r2_local.y + ' angle: ' + body2.angle); @@ -5169,15 +5171,12 @@ var Phaser; var p1 = new Phaser.Vec2(); var p2 = new Phaser.Vec2(); Phaser.Vec2Utils.add(body1.position, r1, p1); - //var p1 = vec2.add(body1.p, r1); Phaser.Vec2Utils.add(body2.position, r2, p2); - //var p2 = vec2.add(body2.p, r2); Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y); // Corrected delta vector var dp = new Phaser.Vec2(); Phaser.Vec2Utils.subtract(p2, p1, dp); - //var dp = vec2.sub(p2, p1); // Position constraint var c = Phaser.Vec2Utils.dot(dp, n) + con.depth; var correction = this.clamp(Physics.Manager.CONTACT_SOLVER_BAUMGARTE * (c + Physics.Manager.CONTACT_SOLVER_COLLISION_SLOP), -Physics.Manager.CONTACT_SOLVER_MAX_LINEAR_CORRECTION, 0); @@ -5195,12 +5194,9 @@ var Phaser; // Apply correction impulses var impulse_dt = new Phaser.Vec2(); Phaser.Vec2Utils.scale(n, lambda_dt, impulse_dt); - //var impulse_dt = vec2.scale(n, lambda_dt); body1.position.multiplyAddByScalar(impulse_dt, -m1_inv); - //body1.p.mad(impulse_dt, -m1_inv); body1.angle -= sn1 * lambda_dt * i1_inv; body2.position.multiplyAddByScalar(impulse_dt, m2_inv); - //body2.p.mad(impulse_dt, m2_inv); body2.angle += sn2 * lambda_dt * i2_inv; Physics.Manager.write('body1.pos.x=' + body1.position.x + ' y=' + body1.position.y); Physics.Manager.write('body2.pos.x=' + body2.position.x + ' y=' + body2.position.y); @@ -6664,13 +6660,13 @@ var Phaser; if (typeof y === "undefined") { y = 0; } if (typeof shapeType === "undefined") { shapeType = 0; } this._tempVec2 = new Phaser.Vec2(); + this._fixedRotation = false; // Shapes this.shapes = []; // Joints this.joints = []; this.jointHash = { }; - this.fixedRotation = false; this.categoryBits = 0x0001; this.maskBits = 0xFFFF; this.stepCount = 0; @@ -6681,7 +6677,7 @@ var Phaser; this.sprite = sprite; this.game = sprite.game; this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(sprite.x), Phaser.Physics.Manager.pixelsToMeters(sprite.y)); - this.angle = sprite.rotation; + this.angle = this.game.math.degreesToRadians(sprite.rotation); } else { this.position = new Phaser.Vec2(Phaser.Physics.Manager.pixelsToMeters(x), Phaser.Physics.Manager.pixelsToMeters(y)); this.angle = 0; @@ -6702,7 +6698,6 @@ var Phaser; }; this.bounds = new Physics.Bounds(); this.allowCollisions = Phaser.Types.ANY; - this.fixedRotation = false; this.categoryBits = 0x0001; this.maskBits = 0xFFFF; this.stepCount = 0; @@ -6714,12 +6709,26 @@ var Phaser; } } } - Body.prototype.toString = function () { - return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; - }; + Object.defineProperty(Body.prototype, "rotation", { + get: /** + * The rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + */ + function () { + return this.game.math.radiansToDegrees(this.angle); + }, + set: /** + * Set the rotation of the body in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right. + * The value is automatically wrapped to be between 0 and 360. + */ + function (value) { + this.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + }, + enumerable: true, + configurable: true + }); Body.prototype.duplicate = function () { console.log('body duplicate called'); - //var body = new Body(this.type, this.transform.t, this.angle); + //var body = new Body(this.type, this.transform.t, this.rotation); //for (var i = 0; i < this.shapes.length; i++) //{ // body.addShape(this.shapes[i].duplicate()); @@ -6842,26 +6851,26 @@ var Phaser; Body.prototype.setTransform = function (pos, angle) { // inject the transform into this.position this.transform.setTo(pos, angle); - Physics.Manager.write('setTransform: ' + this.position.toString()); - Physics.Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('setTransform: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - Physics.Manager.write('post setTransform: ' + this.position.toString()); + //Manager.write('post setTransform: ' + this.position.toString()); //this.position.copyFrom(this.transform.transform(this.centroid)); this.angle = angle; }; Body.prototype.syncTransform = function () { - Physics.Manager.write('syncTransform:'); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('centroid: ' + this.centroid.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('a: ' + this.angle); + //Manager.write('syncTransform:'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('centroid: ' + this.centroid.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('a: ' + this.angle); this.transform.setRotation(this.angle); // OPTIMISE: Creating new vector Phaser.Vec2Utils.subtract(this.position, Phaser.TransformUtils.rotate(this.transform, this.centroid), this.transform.t); - Physics.Manager.write('--------------------'); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('--------------------'); - }; + //Manager.write('--------------------'); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('--------------------'); + }; Body.prototype.getWorldPoint = function (p) { // OPTIMISE: Creating new vector return Phaser.TransformUtils.transform(this.transform, p); @@ -6878,10 +6887,17 @@ var Phaser; // OPTIMISE: Creating new vector return Phaser.TransformUtils.unrotate(this.transform, v); }; - Body.prototype.setFixedRotation = function (flag) { - this.fixedRotation = flag; - this.resetMassData(); - }; + Object.defineProperty(Body.prototype, "fixedRotation", { + get: function () { + return this._fixedRotation; + }, + set: function (value) { + this._fixedRotation = value; + this.resetMassData(); + }, + enumerable: true, + configurable: true + }); Body.prototype.resetMassData = function () { this.centroid.setTo(0, 0); this.mass = 0; @@ -6890,7 +6906,6 @@ var Phaser; this.inertiaInverted = 0; if(this.isDynamic == false) { Phaser.TransformUtils.transform(this.transform, this.centroid, this.position); - //this.position.copyFrom(this.transform.transform(this.centroid)); return; } var totalMassCentroid = new Phaser.Vec2(0, 0); @@ -6901,12 +6916,10 @@ var Phaser; var centroid = shape.centroid(); var mass = shape.area() * shape.density; var inertia = shape.inertia(mass); - //console.log('rmd', centroid, shape); totalMassCentroid.multiplyAddByScalar(centroid, mass); totalMass += mass; totalInertia += inertia; } - //this.centroid.copy(vec2.scale(totalMassCentroid, 1 / totalMass)); Phaser.Vec2Utils.scale(totalMassCentroid, 1 / totalMass, this.centroid); this.setMass(totalMass); if(!this.fixedRotation) { @@ -6933,20 +6946,20 @@ var Phaser; }; Body.prototype.cacheData = function (source) { if (typeof source === "undefined") { source = ''; } - Physics.Manager.write('cacheData -- start'); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- start'); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); this.bounds.clear(); for(var i = 0; i < this.shapesLength; i++) { var shape = this.shapes[i]; shape.cacheData(this.transform); this.bounds.addBounds(shape.bounds); } - Physics.Manager.write('bounds: ' + this.bounds.toString()); - Physics.Manager.write('p: ' + this.position.toString()); - Physics.Manager.write('xf: ' + this.transform.toString()); - Physics.Manager.write('cacheData -- stop'); - }; + //Manager.write('bounds: ' + this.bounds.toString()); + //Manager.write('p: ' + this.position.toString()); + //Manager.write('xf: ' + this.transform.toString()); + //Manager.write('cacheData -- stop'); + }; Body.prototype.updateVelocity = function (gravity, dt, damping) { Phaser.Vec2Utils.multiplyAdd(gravity, this.force, this.massInverted, this._tempVec2); Phaser.Vec2Utils.multiplyAdd(this.velocity, this._tempVec2, dt, this.velocity); @@ -6987,8 +7000,7 @@ var Phaser; if(this.sprite) { this.sprite.x = this.position.x * 50; this.sprite.y = this.position.y * 50; - // Obey fixed rotation? - this.sprite.rotation = this.game.math.radiansToDegrees(this.angle); + this.sprite.transform.rotation = this.game.math.radiansToDegrees(this.angle); } }; Body.prototype.resetForce = function () { @@ -7045,9 +7057,7 @@ var Phaser; this.angularVelocity += impulse * this.inertiaInverted; }; Body.prototype.kineticEnergy = function () { - var vsq = this.velocity.dot(this.velocity); - var wsq = this.angularVelocity * this.angularVelocity; - return 0.5 * (this.mass * vsq + this.inertia * wsq); + return 0.5 * (this.mass * this.velocity.dot(this.velocity) + this.inertia * (this.angularVelocity * this.angularVelocity)); }; Object.defineProperty(Body.prototype, "isAwake", { get: function () { @@ -7068,10 +7078,7 @@ var Phaser; } }; Body.prototype.isCollidable = function (other) { - if(this == other) { - return false; - } - if(this.isDynamic == false && other.isDynamic == false) { + if((this.isDynamic == false && other.isDynamic == false) || this == other) { return false; } if(!(this.maskBits & other.categoryBits) || !(other.maskBits & this.categoryBits)) { @@ -7085,6 +7092,9 @@ var Phaser; } return true; }; + Body.prototype.toString = function () { + return "[{Body (name=" + this.name + " velocity=" + this.velocity.toString() + " angularVelocity: " + this.angularVelocity + ")}]"; + }; return Body; })(); Physics.Body = Body; @@ -7113,7 +7123,7 @@ var Phaser; * @param [x] {number} the initial x position of the sprite. * @param [y] {number} the initial y position of the sprite. * @param [key] {string} Key of the graphic you want to load for this sprite. - * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED) + * @param [bodyType] {number} The physics body type of the object (defaults to BODY_DISABLED, i.e. no physics) * @param [shapeType] {number} The physics shape the body will consist of (either Box (0) or Circle (1), for custom types see body.addShape) */ function Sprite(game, x, y, key, frame, bodyType, shapeType) { @@ -7142,7 +7152,7 @@ var Phaser; /** * z order value of the object. */ - this.z = 0; + this.z = -1; /** * Render iteration counter */ @@ -7157,6 +7167,7 @@ var Phaser; this.y = y; this.z = -1; this.group = null; + this.name = ''; this.animations = new Phaser.Components.AnimationManager(this); this.input = new Phaser.Components.Sprite.Input(this); this.events = new Phaser.Components.Sprite.Events(this); @@ -7200,6 +7211,9 @@ var Phaser; */ function (value) { this.transform.rotation = this.game.math.wrap(value, 360, 0); + if(this.body) { + this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0)); + } }, enumerable: true, configurable: true @@ -8185,29 +8199,70 @@ var Phaser; return true; }; Group.prototype.bringToTop = function (child) { + //console.log('bringToTop', child.name,'current z', child.z); + var oldZ = child.z; // If child not in this group, or is already at the top of the group, return false - if(!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) { + //if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter) + if(!child || child.group == null || child.group.ID != this.ID) { + //console.log('If child not in this group, or is already at the top of the group, return false'); return false; } - this.sort(); - // What's the z index of the top most child? - var childIndex = this._zCounter; - this._i = 0; - while(this._i < this.length) { - this._member = this.members[this._i++]; - if(this._member) { - if(this._i > childIndex) { - this._member.z--; - } else if(this._member.z == child.z) { - childIndex = this._i; - this._member.z = this._zCounter; - } + // Find out the largest z index + var topZ = -1; + for(var i = 0; i < this.length; i++) { + if(this.members[i] && this.members[i].z > topZ) { + topZ = this.members[i].z; } } + // Child is already at the top + if(child.z == topZ) { + return false; + } + child.z = topZ + 1; + // Sort them out based on the current z indexes + this.sort(); + // Now tidy-up the z indexes, removing gaps, etc + for(var i = 0; i < this.length; i++) { + if(this.members[i]) { + this.members[i].z = i; + } + } + //console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z); + return true; + // What's the z index of the top most child? + /* + var childIndex: number = this._zCounter; + + console.log('childIndex', childIndex); + + this._i = 0; + + while (this._i < this.length) + { + this._member = this.members[this._i++]; + + if (this._member) + { + if (this._i > childIndex) + { + this._member.z--; + } + else if (this._member.z == child.z) + { + childIndex = this._i; + this._member.z = this._zCounter; + } + } + } + + console.log('child inserted at index', child.z); + // Maybe redundant? this.sort(); + return true; - }; + */ + }; Group.prototype.sort = /** * Call this function to sort the group according to a particular value and order. * For example, to sort game objects for Zelda-style overlaps you might call @@ -11782,6 +11837,7 @@ var Phaser; * @type {Tweens[]} */ this._chainedTweens = []; + this.isRunning = false; this._object = object; this._game = game; this._manager = this._game.tweens; @@ -11849,6 +11905,7 @@ var Phaser; this.onStart.dispatch(this._object); } this._startTime = this._game.time.now + this._delayTime; + this.isRunning = true; for(var property in this._valuesEnd) { // This prevents the interpolation of null values or of non-existing properties if(this._object[property] === null || !(property in this._object)) { @@ -11903,6 +11960,7 @@ var Phaser; if(this._manager !== null) { this._manager.remove(this); } + this.isRunning = false; this.onComplete.dispose(); return this; }; @@ -12013,6 +12071,9 @@ var Phaser; for(var i = 0; i < this._chainedTweens.length; i++) { this._chainedTweens[i].start(); } + if(this._chainedTweens.length == 0) { + this.isRunning = false; + } return false; } } @@ -12633,21 +12694,6 @@ var Phaser; * @param tileHeight {number} Height of tiles in this map. */ function TilemapLayer(game, parent, key, mapFormat, name, tileWidth, tileHeight) { - this._startX = 0; - this._startY = 0; - this._maxX = 0; - this._maxY = 0; - this._tx = 0; - this._ty = 0; - this._dx = 0; - this._dy = 0; - this._oldCameraX = 0; - this._oldCameraY = 0; - /** - * Opacity of this layer. - * @type {number} - */ - this.alpha = 1; /** * Controls whether update() and draw() are automatically called. * @type {boolean} @@ -12690,19 +12736,24 @@ var Phaser; * @type {number} */ this.tileSpacing = 0; - this._game = game; - this._parent = parent; + this.game = game; + this.parent = parent; this.name = name; this.mapFormat = mapFormat; this.tileWidth = tileWidth; this.tileHeight = tileHeight; this.boundsInTiles = new Phaser.Rectangle(); - //this.scrollFactor = new MicroPoint(1, 1); - this.canvas = game.stage.canvas; - this.context = game.stage.context; + this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.Transform(this); + if(key !== null) { + this.texture.loadImage(key, false); + } else { + this.texture.opaque = true; + } + // Handy proxies + this.alpha = this.texture.alpha; this.mapData = []; this._tempTileBlock = []; - this._texture = this._game.cache.getImage(key); } TilemapLayer.prototype.putTile = /** * Set a specific tile with its x and y in tiles. @@ -12711,8 +12762,8 @@ var Phaser; * @param index {number} The index of this tile type in the core map data. */ function (x, y, index) { - x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; if(y >= 0 && y < this.mapData.length) { if(x >= 0 && x < this.mapData[y].length) { this.mapData[y][x] = index; @@ -12784,7 +12835,7 @@ var Phaser; if (typeof height === "undefined") { height = this.heightInTiles; } this.getTempBlock(x, y, width, height); for(var r = 0; r < this._tempTileBlock.length; r++) { - this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this._game.math.getRandom(tiles); + this.mapData[this._tempTileBlock[r].y][this._tempTileBlock[r].x] = this.game.math.getRandom(tiles); } }; TilemapLayer.prototype.replaceTile = /** @@ -12833,8 +12884,8 @@ var Phaser; * @param x {number} Y position of the point in target tile. */ function (x, y) { - x = this._game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - y = this._game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; return this.getTileIndex(x, y); }; TilemapLayer.prototype.getTileOverlaps = /** @@ -12848,17 +12899,17 @@ var Phaser; return; } // What tiles do we need to check against? - this._tempTileX = this._game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; - this._tempTileY = this._game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; - this._tempTileW = (this._game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; - this._tempTileH = (this._game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; + this._tempTileX = this.game.math.snapToFloor(object.body.bounds.x, this.tileWidth) / this.tileWidth; + this._tempTileY = this.game.math.snapToFloor(object.body.bounds.y, this.tileHeight) / this.tileHeight; + this._tempTileW = (this.game.math.snapToCeil(object.body.bounds.width, this.tileWidth) + this.tileWidth) / this.tileWidth; + this._tempTileH = (this.game.math.snapToCeil(object.body.bounds.height, this.tileHeight) + this.tileHeight) / this.tileHeight; // Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock) this._tempBlockResults = []; this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true); /* for (var r = 0; r < this._tempTileBlock.length; r++) { - if (this._game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) + if (this.game.world.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY) == true) { this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile }); } @@ -12893,11 +12944,11 @@ var Phaser; for(var tx = x; tx < x + width; tx++) { if(collisionOnly) { // We only want to consider the tile for checking if you can actually collide with it - if(this.mapData[ty] && this.mapData[ty][tx] && this._parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) { + if(this.mapData[ty] && this.mapData[ty][tx] && this.parent.tiles[this.mapData[ty][tx]].allowCollisions != Phaser.Types.NONE) { this._tempTileBlock.push({ x: tx, y: ty, - tile: this._parent.tiles[this.mapData[ty][tx]] + tile: this.parent.tiles[this.mapData[ty][tx]] }); } } else { @@ -12905,7 +12956,7 @@ var Phaser; this._tempTileBlock.push({ x: tx, y: ty, - tile: this._parent.tiles[this.mapData[ty][tx]] + tile: this.parent.tiles[this.mapData[ty][tx]] }); } } @@ -12951,120 +13002,42 @@ var Phaser; }; TilemapLayer.prototype.parseTileOffsets = /** * Parse tile offsets from map data. - * @return {number} length of _tileOffsets array. + * @return {number} length of tileOffsets array. */ function () { - this._tileOffsets = []; + this.tileOffsets = []; var i = 0; if(this.mapFormat == Phaser.Tilemap.FORMAT_TILED_JSON) { // For some reason Tiled counts from 1 not 0 - this._tileOffsets[0] = null; + this.tileOffsets[0] = null; i = 1; } - for(var ty = this.tileMargin; ty < this._texture.height; ty += (this.tileHeight + this.tileSpacing)) { - for(var tx = this.tileMargin; tx < this._texture.width; tx += (this.tileWidth + this.tileSpacing)) { - this._tileOffsets[i] = { + for(var ty = this.tileMargin; ty < this.texture.height; ty += (this.tileHeight + this.tileSpacing)) { + for(var tx = this.tileMargin; tx < this.texture.width; tx += (this.tileWidth + this.tileSpacing)) { + this.tileOffsets[i] = { x: tx, y: ty }; i++; } } - return this._tileOffsets.length; - }; - TilemapLayer.prototype.renderDebugInfo = function (x, y, color) { - if (typeof color === "undefined") { color = 'rgb(255,255,255)'; } - this.context.fillStyle = color; - this.context.fillText('TilemapLayer: ' + this.name, x, y); - this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14); - this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28); - this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42); - }; - TilemapLayer.prototype.render = /** - * Render this layer to a specific camera with offset to camera. - * @param camera {Camera} The camera the layer is going to be rendered. - * @param dx {number} X offset to the camera. - * @param dy {number} Y offset to the camera. - * @return {boolean} Return false if layer is invisible or has a too low opacity(will stop rendering), return true if succeed. - */ - function (camera, dx, dy) { - if(this.visible === false || this.alpha < 0.1) { - return false; - } - // Work out how many tiles we can fit into our camera and round it up for the edges - this._maxX = this._game.math.ceil(camera.width / this.tileWidth) + 1; - this._maxY = this._game.math.ceil(camera.height / this.tileHeight) + 1; - // And now work out where in the tilemap the camera actually is - this._startX = this._game.math.floor(camera.worldView.x / this.tileWidth); - this._startY = this._game.math.floor(camera.worldView.y / this.tileHeight); - // Tilemap bounds check - if(this._startX < 0) { - this._startX = 0; - } - if(this._startY < 0) { - this._startY = 0; - } - if(this._maxX > this.widthInTiles) { - this._maxX = this.widthInTiles; - } - if(this._maxY > this.heightInTiles) { - this._maxY = this.heightInTiles; - } - if(this._startX + this._maxX > this.widthInTiles) { - this._startX = this.widthInTiles - this._maxX; - } - if(this._startY + this._maxY > this.heightInTiles) { - this._startY = this.heightInTiles - this._maxY; - } - // Finally get the offset to avoid the blocky movement - this._dx = dx; - this._dy = dy; - this._dx += -(camera.worldView.x - (this._startX * this.tileWidth)); - this._dy += -(camera.worldView.y - (this._startY * this.tileHeight)); - this._tx = this._dx; - this._ty = this._dy; - // Apply camera difference - /* - if (this.scrollFactor.x !== 1.0 || this.scrollFactor.y !== 1.0) - { - this._dx -= (camera.worldView.x * this.scrollFactor.x); - this._dy -= (camera.worldView.y * this.scrollFactor.y); - } - */ - // Alpha - if(this.alpha !== 1) { - var globalAlpha = this.context.globalAlpha; - this.context.globalAlpha = this.alpha; - } - for(var row = this._startY; row < this._startY + this._maxY; row++) { - this._columnData = this.mapData[row]; - for(var tile = this._startX; tile < this._startX + this._maxX; tile++) { - if(this._tileOffsets[this._columnData[tile]]) { - this.context.drawImage(this._texture, // Source Image - this._tileOffsets[this._columnData[tile]].x, // Source X (location within the source image) - this._tileOffsets[this._columnData[tile]].y, // Source Y - this.tileWidth, // Source Width - this.tileHeight, // Source Height - this._tx, // Destination X (where on the canvas it'll be drawn) - this._ty, // Destination Y - this.tileWidth, // Destination Width (always same as Source Width unless scaled) - this.tileHeight); - // Destination Height (always same as Source Height unless scaled) - } - this._tx += this.tileWidth; - } - this._tx = this._dx; - this._ty += this.tileHeight; - } - if(globalAlpha > -1) { - this.context.globalAlpha = globalAlpha; - } - return true; + return this.tileOffsets.length; }; return TilemapLayer; })(); Phaser.TilemapLayer = TilemapLayer; -})(Phaser || (Phaser = {})); + /* + public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') { + + this.context.fillStyle = color; + this.context.fillText('TilemapLayer: ' + this.name, x, y); + this.context.fillText('startX: ' + this._startX + ' endX: ' + this._maxX, x, y + 14); + this.context.fillText('startY: ' + this._startY + ' endY: ' + this._maxY, x, y + 28); + this.context.fillText('dx: ' + this._dx + ' dy: ' + this._dy, x, y + 42); + + } + */ + })(Phaser || (Phaser = {})); /// /** * Phaser - Tile @@ -13217,6 +13190,22 @@ var Phaser; if (typeof tileWidth === "undefined") { tileWidth = 0; } if (typeof tileHeight === "undefined") { tileHeight = 0; } /** + * The Input component + */ + //public input: Phaser.Components.Sprite.Input; + /** + * The Events component + */ + //public events: Phaser.Components.Sprite.Events; + /** + * z order value of the object. + */ + this.z = -1; + /** + * Render iteration counter + */ + this.renderOrderID = 0; + /** * Tilemap collision callback. * @type {function} */ @@ -13227,9 +13216,13 @@ var Phaser; this.active = true; this.visible = true; this.alive = true; + this.z = -1; + this.group = null; + this.name = ''; + this.texture = new Phaser.Components.Texture(this); + this.transform = new Phaser.Components.Transform(this); this.tiles = []; this.layers = []; - this.cameraBlacklist = []; this.mapFormat = format; switch(format) { case Tilemap.FORMAT_CSV: @@ -13245,24 +13238,14 @@ var Phaser; } Tilemap.FORMAT_CSV = 0; Tilemap.FORMAT_TILED_JSON = 1; - Tilemap.prototype.update = /** - * Inherited update method. + Tilemap.prototype.preUpdate = /** + * Inherited methods for overriding. */ function () { }; - Tilemap.prototype.render = /** - * Render this tilemap to a specific camera with specific offset. - * @param camera {Camera} The camera this tilemap will be rendered to. - * @param cameraOffsetX {number} X offset of the camera. - * @param cameraOffsetY {number} Y offset of the camera. - */ - function (camera, cameraOffsetX, cameraOffsetY) { - if(this.cameraBlacklist.indexOf(camera.ID) == -1) { - // Loop through the layers - for(var i = 0; i < this.layers.length; i++) { - this.layers[i].render(camera, cameraOffsetX, cameraOffsetY); - } - } + Tilemap.prototype.update = function () { + }; + Tilemap.prototype.postUpdate = function () { }; Tilemap.prototype.parseCSV = /** * Parset csv map data and generate tiles. @@ -16253,7 +16236,8 @@ var Phaser; return PointUtils.rotate(a, b.x, b.y, angle, asDegrees, distance); }; return PointUtils; - })(); + })(); + Phaser.PointUtils = PointUtils; })(Phaser || (Phaser = {})); /// /// @@ -18083,7 +18067,7 @@ var Phaser; (function (Phaser) { var CanvasRenderer = (function () { function CanvasRenderer(game) { - // local rendering related temp vars to help avoid gc spikes with var creation + // Local rendering related temp vars to help avoid gc spikes through var creation this._ga = 1; this._sx = 0; this._sy = 0; @@ -18095,8 +18079,14 @@ var Phaser; this._dh = 0; this._fx = 1; this._fy = 1; + this._tx = 0; + this._ty = 0; this._sin = 0; this._cos = 1; + this._maxX = 0; + this._maxY = 0; + this._startX = 0; + this._startY = 0; this._game = game; } CanvasRenderer.prototype.render = function () { @@ -18117,6 +18107,8 @@ var Phaser; this.renderSprite(this._camera, object); } else if(object.type == Phaser.Types.SCROLLZONE) { this.renderScrollZone(this._camera, object); + } else if(object.type == Phaser.Types.TILEMAP) { + this.renderTilemap(this._camera, object); } }; CanvasRenderer.prototype.preRenderGroup = function (camera, group) { @@ -18553,6 +18545,75 @@ var Phaser; } return true; }; + CanvasRenderer.prototype.renderTilemap = /** + * Render a tilemap to a specific camera. + * @param camera {Camera} The camera this tilemap will be rendered to. + */ + function (camera, tilemap) { + // Loop through the layers + for(var i = 0; i < tilemap.layers.length; i++) { + var layer = tilemap.layers[i]; + if(layer.visible == false || layer.alpha < 0.1) { + continue; + } + // Work out how many tiles we can fit into our camera and round it up for the edges + this._maxX = this._game.math.ceil(camera.width / layer.tileWidth) + 1; + this._maxY = this._game.math.ceil(camera.height / layer.tileHeight) + 1; + // And now work out where in the tilemap the camera actually is + this._startX = this._game.math.floor(camera.worldView.x / layer.tileWidth); + this._startY = this._game.math.floor(camera.worldView.y / layer.tileHeight); + // Tilemap bounds check + if(this._startX < 0) { + this._startX = 0; + } + if(this._startY < 0) { + this._startY = 0; + } + if(this._maxX > layer.widthInTiles) { + this._maxX = layer.widthInTiles; + } + if(this._maxY > layer.heightInTiles) { + this._maxY = layer.heightInTiles; + } + if(this._startX + this._maxX > layer.widthInTiles) { + this._startX = layer.widthInTiles - this._maxX; + } + if(this._startY + this._maxY > layer.heightInTiles) { + this._startY = layer.heightInTiles - this._maxY; + } + // Finally get the offset to avoid the blocky movement + //this._dx = (camera.screenView.x * layer.transform.scrollFactor.x) - (camera.worldView.x * layer.transform.scrollFactor.x); + //this._dy = (camera.screenView.y * layer.transform.scrollFactor.y) - (camera.worldView.y * layer.transform.scrollFactor.y); + //this._dx = (camera.screenView.x * this.scrollFactor.x) + this.x - (camera.worldView.x * this.scrollFactor.x); + //this._dy = (camera.screenView.y * this.scrollFactor.y) + this.y - (camera.worldView.y * this.scrollFactor.y); + this._dx = 0; + this._dy = 0; + this._dx += -(camera.worldView.x - (this._startX * layer.tileWidth)); + this._dy += -(camera.worldView.y - (this._startY * layer.tileHeight)); + this._tx = this._dx; + this._ty = this._dy; + // Alpha + if(layer.texture.alpha !== 1) { + this._ga = layer.texture.context.globalAlpha; + layer.texture.context.globalAlpha = layer.texture.alpha; + } + for(var row = this._startY; row < this._startY + this._maxY; row++) { + this._columnData = layer.mapData[row]; + for(var tile = this._startX; tile < this._startX + this._maxX; tile++) { + if(layer.tileOffsets[this._columnData[tile]]) { + layer.texture.context.drawImage(layer.texture.texture, layer.tileOffsets[this._columnData[tile]].x, layer.tileOffsets[this._columnData[tile]].y, layer.tileWidth, layer.tileHeight, this._tx, this._ty, layer.tileWidth, layer.tileHeight); + } + this._tx += layer.tileWidth; + } + this._tx = this._dx; + this._ty += layer.tileHeight; + } + if(this._ga > -1) { + layer.texture.context.globalAlpha = this._ga; + } + } + return true; + }; return CanvasRenderer; })(); Phaser.CanvasRenderer = CanvasRenderer; @@ -18626,6 +18687,11 @@ var Phaser; DebugUtils.context.fillStyle = color; DebugUtils.context.fillRect(dx, dy, sprite.width, sprite.height); }; + DebugUtils.renderRectangle = function renderRectangle(rect, fillStyle) { + if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.3)'; } + DebugUtils.context.fillStyle = fillStyle; + DebugUtils.context.fillRect(rect.x, rect.y, rect.width, rect.height); + }; DebugUtils.renderPhysicsBody = function renderPhysicsBody(body, lineWidth, fillStyle, sleepStyle) { if (typeof lineWidth === "undefined") { lineWidth = 1; } if (typeof fillStyle === "undefined") { fillStyle = 'rgba(0,255,0,0.2)'; } @@ -19094,84 +19160,6 @@ var Phaser; })(); Phaser.Game = Game; })(Phaser || (Phaser = {})); -/// -/** -* Phaser - State -* -* This is a base State class which can be extended if you are creating your game using TypeScript. -*/ -var Phaser; -(function (Phaser) { - var State = (function () { - /** - * State constructor - * Create a new State. - */ - function State(game) { - this.game = game; - this.add = game.add; - this.camera = game.camera; - this.cache = game.cache; - this.input = game.input; - this.load = game.load; - this.math = game.math; - this.motion = game.motion; - this.sound = game.sound; - this.stage = game.stage; - this.time = game.time; - this.tweens = game.tweens; - this.world = game.world; - } - State.prototype.init = // Override these in your own States - /** - * Override this method to add some load operations. - * If you need to use the loader, you may need to use them here. - */ - function () { - }; - State.prototype.create = /** - * This method is called after the game engine successfully switches states. - * Feel free to add any setup code here.(Do not load anything here, override init() instead) - */ - function () { - }; - State.prototype.update = /** - * Put update logic here. - */ - function () { - }; - State.prototype.render = /** - * Put render operations here. - */ - function () { - }; - State.prototype.paused = /** - * This method will be called when game paused. - */ - function () { - }; - State.prototype.destroy = /** - * This method will be called when the state is destroyed - */ - function () { - }; - return State; - })(); - Phaser.State = State; - /** - * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. - * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. - * @param object1 The first GameObject or Group to check. If null the world.group is used. - * @param object2 The second GameObject or Group to check. - * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. - * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. - * @param context The context in which the callbacks will be called - * @returns {boolean} true if the objects overlap, otherwise false. - */ - //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool { - // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context); - //} - })(Phaser || (Phaser = {})); var Phaser; (function (Phaser) { /** @@ -19514,206 +19502,6 @@ var Phaser; Phaser.Line = Line; })(Phaser || (Phaser = {})); /// -/** -* Phaser - IntersectResult -* -* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. -*/ -var Phaser; -(function (Phaser) { - var IntersectResult = (function () { - function IntersectResult() { - /** - * Did they intersect or not? - * @property result - * @type {Boolean} - */ - this.result = false; - } - IntersectResult.prototype.setTo = /** - * - * @method setTo - * @param {Number} x1 - * @param {Number} y1 - * @param {Number} [x2] - * @param {Number} [y2] - * @param {Number} [width] - * @param {Number} [height] - */ - function (x1, y1, x2, y2, width, height) { - if (typeof x2 === "undefined") { x2 = 0; } - if (typeof y2 === "undefined") { y2 = 0; } - if (typeof width === "undefined") { width = 0; } - if (typeof height === "undefined") { height = 0; } - this.x = x1; - this.y = y1; - this.x1 = x1; - this.y1 = y1; - this.x2 = x2; - this.y2 = y2; - this.width = width; - this.height = height; - }; - return IntersectResult; - })(); - Phaser.IntersectResult = IntersectResult; -})(Phaser || (Phaser = {})); -/// -/// -/// -/** -* Phaser - Mat3Utils -* -* A collection of methods useful for manipulating and performing operations on Mat3 objects. -* -*/ -var Phaser; -(function (Phaser) { - var Mat3Utils = (function () { - function Mat3Utils() { } - Mat3Utils.transpose = /** - * Transpose the values of a Mat3 - **/ - function transpose(source, dest) { - if (typeof dest === "undefined") { dest = null; } - if(dest === null) { - // Transpose ourselves - var a01 = source.data[1]; - var a02 = source.data[2]; - var a12 = source.data[5]; - source.data[1] = source.data[3]; - source.data[2] = source.data[6]; - source.data[3] = a01; - source.data[5] = source.data[7]; - source.data[6] = a02; - source.data[7] = a12; - } else { - source.data[0] = dest.data[0]; - source.data[1] = dest.data[3]; - source.data[2] = dest.data[6]; - source.data[3] = dest.data[1]; - source.data[4] = dest.data[4]; - source.data[5] = dest.data[7]; - source.data[6] = dest.data[2]; - source.data[7] = dest.data[5]; - source.data[8] = dest.data[8]; - } - return source; - }; - Mat3Utils.invert = /** - * Inverts a Mat3 - **/ - function invert(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - var b01 = a22 * a11 - a12 * a21; - var b11 = -a22 * a10 + a12 * a20; - var b21 = a21 * a10 - a11 * a20; - // Determinant - var det = a00 * b01 + a01 * b11 + a02 * b21; - if(!det) { - return null; - } - det = 1.0 / det; - source.data[0] = b01 * det; - source.data[1] = (-a22 * a01 + a02 * a21) * det; - source.data[2] = (a12 * a01 - a02 * a11) * det; - source.data[3] = b11 * det; - source.data[4] = (a22 * a00 - a02 * a20) * det; - source.data[5] = (-a12 * a00 + a02 * a10) * det; - source.data[6] = b21 * det; - source.data[7] = (-a21 * a00 + a01 * a20) * det; - source.data[8] = (a11 * a00 - a01 * a10) * det; - return source; - }; - Mat3Utils.adjoint = /** - * Calculates the adjugate of a Mat3 - **/ - function adjoint(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - source.data[0] = (a11 * a22 - a12 * a21); - source.data[1] = (a02 * a21 - a01 * a22); - source.data[2] = (a01 * a12 - a02 * a11); - source.data[3] = (a12 * a20 - a10 * a22); - source.data[4] = (a00 * a22 - a02 * a20); - source.data[5] = (a02 * a10 - a00 * a12); - source.data[6] = (a10 * a21 - a11 * a20); - source.data[7] = (a01 * a20 - a00 * a21); - source.data[8] = (a00 * a11 - a01 * a10); - return source; - }; - Mat3Utils.determinant = /** - * Calculates the adjugate of a Mat3 - **/ - function determinant(source) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); - }; - Mat3Utils.multiply = /** - * Multiplies two Mat3s - **/ - function multiply(source, b) { - var a00 = source.data[0]; - var a01 = source.data[1]; - var a02 = source.data[2]; - var a10 = source.data[3]; - var a11 = source.data[4]; - var a12 = source.data[5]; - var a20 = source.data[6]; - var a21 = source.data[7]; - var a22 = source.data[8]; - var b00 = b.data[0]; - var b01 = b.data[1]; - var b02 = b.data[2]; - var b10 = b.data[3]; - var b11 = b.data[4]; - var b12 = b.data[5]; - var b20 = b.data[6]; - var b21 = b.data[7]; - var b22 = b.data[8]; - source.data[0] = b00 * a00 + b01 * a10 + b02 * a20; - source.data[1] = b00 * a01 + b01 * a11 + b02 * a21; - source.data[2] = b00 * a02 + b01 * a12 + b02 * a22; - source.data[3] = b10 * a00 + b11 * a10 + b12 * a20; - source.data[4] = b10 * a01 + b11 * a11 + b12 * a21; - source.data[5] = b10 * a02 + b11 * a12 + b12 * a22; - source.data[6] = b20 * a00 + b21 * a10 + b22 * a20; - source.data[7] = b20 * a01 + b21 * a11 + b22 * a21; - source.data[8] = b20 * a02 + b21 * a12 + b22 * a22; - return source; - }; - Mat3Utils.fromQuaternion = function fromQuaternion() { - }; - Mat3Utils.normalFromMat4 = function normalFromMat4() { - }; - return Mat3Utils; - })(); - Phaser.Mat3Utils = Mat3Utils; -})(Phaser || (Phaser = {})); -/// /// /// /// @@ -19877,6 +19665,161 @@ var Phaser; Phaser.CircleUtils = CircleUtils; })(Phaser || (Phaser = {})); /// +/// +/// +/** +* Phaser - Mat3Utils +* +* A collection of methods useful for manipulating and performing operations on Mat3 objects. +* +*/ +var Phaser; +(function (Phaser) { + var Mat3Utils = (function () { + function Mat3Utils() { } + Mat3Utils.transpose = /** + * Transpose the values of a Mat3 + **/ + function transpose(source, dest) { + if (typeof dest === "undefined") { dest = null; } + if(dest === null) { + // Transpose ourselves + var a01 = source.data[1]; + var a02 = source.data[2]; + var a12 = source.data[5]; + source.data[1] = source.data[3]; + source.data[2] = source.data[6]; + source.data[3] = a01; + source.data[5] = source.data[7]; + source.data[6] = a02; + source.data[7] = a12; + } else { + source.data[0] = dest.data[0]; + source.data[1] = dest.data[3]; + source.data[2] = dest.data[6]; + source.data[3] = dest.data[1]; + source.data[4] = dest.data[4]; + source.data[5] = dest.data[7]; + source.data[6] = dest.data[2]; + source.data[7] = dest.data[5]; + source.data[8] = dest.data[8]; + } + return source; + }; + Mat3Utils.invert = /** + * Inverts a Mat3 + **/ + function invert(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + var b01 = a22 * a11 - a12 * a21; + var b11 = -a22 * a10 + a12 * a20; + var b21 = a21 * a10 - a11 * a20; + // Determinant + var det = a00 * b01 + a01 * b11 + a02 * b21; + if(!det) { + return null; + } + det = 1.0 / det; + source.data[0] = b01 * det; + source.data[1] = (-a22 * a01 + a02 * a21) * det; + source.data[2] = (a12 * a01 - a02 * a11) * det; + source.data[3] = b11 * det; + source.data[4] = (a22 * a00 - a02 * a20) * det; + source.data[5] = (-a12 * a00 + a02 * a10) * det; + source.data[6] = b21 * det; + source.data[7] = (-a21 * a00 + a01 * a20) * det; + source.data[8] = (a11 * a00 - a01 * a10) * det; + return source; + }; + Mat3Utils.adjoint = /** + * Calculates the adjugate of a Mat3 + **/ + function adjoint(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + source.data[0] = (a11 * a22 - a12 * a21); + source.data[1] = (a02 * a21 - a01 * a22); + source.data[2] = (a01 * a12 - a02 * a11); + source.data[3] = (a12 * a20 - a10 * a22); + source.data[4] = (a00 * a22 - a02 * a20); + source.data[5] = (a02 * a10 - a00 * a12); + source.data[6] = (a10 * a21 - a11 * a20); + source.data[7] = (a01 * a20 - a00 * a21); + source.data[8] = (a00 * a11 - a01 * a10); + return source; + }; + Mat3Utils.determinant = /** + * Calculates the adjugate of a Mat3 + **/ + function determinant(source) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20); + }; + Mat3Utils.multiply = /** + * Multiplies two Mat3s + **/ + function multiply(source, b) { + var a00 = source.data[0]; + var a01 = source.data[1]; + var a02 = source.data[2]; + var a10 = source.data[3]; + var a11 = source.data[4]; + var a12 = source.data[5]; + var a20 = source.data[6]; + var a21 = source.data[7]; + var a22 = source.data[8]; + var b00 = b.data[0]; + var b01 = b.data[1]; + var b02 = b.data[2]; + var b10 = b.data[3]; + var b11 = b.data[4]; + var b12 = b.data[5]; + var b20 = b.data[6]; + var b21 = b.data[7]; + var b22 = b.data[8]; + source.data[0] = b00 * a00 + b01 * a10 + b02 * a20; + source.data[1] = b00 * a01 + b01 * a11 + b02 * a21; + source.data[2] = b00 * a02 + b01 * a12 + b02 * a22; + source.data[3] = b10 * a00 + b11 * a10 + b12 * a20; + source.data[4] = b10 * a01 + b11 * a11 + b12 * a21; + source.data[5] = b10 * a02 + b11 * a12 + b12 * a22; + source.data[6] = b20 * a00 + b21 * a10 + b22 * a20; + source.data[7] = b20 * a01 + b21 * a11 + b22 * a21; + source.data[8] = b20 * a02 + b21 * a12 + b22 * a22; + return source; + }; + Mat3Utils.fromQuaternion = function fromQuaternion() { + }; + Mat3Utils.normalFromMat4 = function normalFromMat4() { + }; + return Mat3Utils; + })(); + Phaser.Mat3Utils = Mat3Utils; +})(Phaser || (Phaser = {})); +/// /// /// /// @@ -19904,3 +19847,126 @@ var Phaser; })(); Phaser.PixelUtils = PixelUtils; })(Phaser || (Phaser = {})); +/// +/** +* Phaser - IntersectResult +* +* A light-weight result object to hold the results of an intersection. For when you need more than just true/false. +*/ +var Phaser; +(function (Phaser) { + var IntersectResult = (function () { + function IntersectResult() { + /** + * Did they intersect or not? + * @property result + * @type {Boolean} + */ + this.result = false; + } + IntersectResult.prototype.setTo = /** + * + * @method setTo + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} [x2] + * @param {Number} [y2] + * @param {Number} [width] + * @param {Number} [height] + */ + function (x1, y1, x2, y2, width, height) { + if (typeof x2 === "undefined") { x2 = 0; } + if (typeof y2 === "undefined") { y2 = 0; } + if (typeof width === "undefined") { width = 0; } + if (typeof height === "undefined") { height = 0; } + this.x = x1; + this.y = y1; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.width = width; + this.height = height; + }; + return IntersectResult; + })(); + Phaser.IntersectResult = IntersectResult; +})(Phaser || (Phaser = {})); +/// +/** +* Phaser - State +* +* This is a base State class which can be extended if you are creating your game using TypeScript. +*/ +var Phaser; +(function (Phaser) { + var State = (function () { + /** + * State constructor + * Create a new State. + */ + function State(game) { + this.game = game; + this.add = game.add; + this.camera = game.camera; + this.cache = game.cache; + this.input = game.input; + this.load = game.load; + this.math = game.math; + this.motion = game.motion; + this.sound = game.sound; + this.stage = game.stage; + this.time = game.time; + this.tweens = game.tweens; + this.world = game.world; + } + State.prototype.init = // Override these in your own States + /** + * Override this method to add some load operations. + * If you need to use the loader, you may need to use them here. + */ + function () { + }; + State.prototype.create = /** + * This method is called after the game engine successfully switches states. + * Feel free to add any setup code here.(Do not load anything here, override init() instead) + */ + function () { + }; + State.prototype.update = /** + * Put update logic here. + */ + function () { + }; + State.prototype.render = /** + * Put render operations here. + */ + function () { + }; + State.prototype.paused = /** + * This method will be called when game paused. + */ + function () { + }; + State.prototype.destroy = /** + * This method will be called when the state is destroyed + */ + function () { + }; + return State; + })(); + Phaser.State = State; + /** + * Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group. + * Note: Does not take the objects scrollFactor into account. All overlaps are check in world space. + * @param object1 The first GameObject or Group to check. If null the world.group is used. + * @param object2 The second GameObject or Group to check. + * @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap. + * @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true. + * @param context The context in which the callbacks will be called + * @returns {boolean} true if the objects overlap, otherwise false. + */ + //public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool { + // return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context); + //} + })(Phaser || (Phaser = {}));