From 8668b82ef6b5fa8af8c0c2ebfd64ab8a2040e145 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 1 Oct 2013 01:18:29 +0100 Subject: [PATCH] * Fixed issue causing Keyboard.justPressed to always fire (thanks stemkoski) * Added Keyboard.addKey() which creates a new Phaser.Key object that can be polled for updates, pressed states, etc. See the 2 new examples showing use. --- README.md | 3 + build/phaser.js | 2 +- examples/assets/skies/cavern1.png | Bin 0 -> 1809 bytes examples/assets/skies/cavern2.png | Bin 0 -> 1809 bytes examples/assets/skies/chrome.png | Bin 0 -> 1809 bytes examples/assets/skies/fire.png | Bin 0 -> 1809 bytes examples/assets/skies/fog.png | Bin 0 -> 1809 bytes examples/assets/skies/sky1.png | Bin 0 -> 1809 bytes examples/assets/skies/sky2.png | Bin 0 -> 1809 bytes examples/assets/skies/sky3.png | Bin 0 -> 1809 bytes examples/assets/skies/sky4.png | Bin 0 -> 1809 bytes examples/assets/skies/sky5.png | Bin 0 -> 1809 bytes examples/assets/skies/space1.png | Bin 0 -> 1809 bytes examples/assets/skies/space2.png | Bin 0 -> 1809 bytes examples/assets/skies/sunorbit.png | Bin 0 -> 1809 bytes examples/assets/skies/sunset.png | Bin 0 -> 1809 bytes examples/assets/skies/toxic.png | Bin 0 -> 1809 bytes examples/assets/skies/underwater1.png | Bin 0 -> 1809 bytes examples/assets/skies/underwater2.png | Bin 0 -> 1809 bytes examples/assets/skies/underwater3.png | Bin 0 -> 1809 bytes examples/assets/skies/wtf.png | Bin 0 -> 1809 bytes examples/input/key.php | 67 +++++++++++ examples/input/keyboard hotkeys.php | 58 ++++++++++ examples/input/keyboard justpressed.php | 47 ++++++++ examples/js.php | 1 + src/input/Input.js | 1 + src/input/Key.js | 142 ++++++++++++++++++++++++ src/input/Keyboard.js | 99 +++++++++++++---- 28 files changed, 397 insertions(+), 23 deletions(-) create mode 100644 examples/assets/skies/cavern1.png create mode 100644 examples/assets/skies/cavern2.png create mode 100644 examples/assets/skies/chrome.png create mode 100644 examples/assets/skies/fire.png create mode 100644 examples/assets/skies/fog.png create mode 100644 examples/assets/skies/sky1.png create mode 100644 examples/assets/skies/sky2.png create mode 100644 examples/assets/skies/sky3.png create mode 100644 examples/assets/skies/sky4.png create mode 100644 examples/assets/skies/sky5.png create mode 100644 examples/assets/skies/space1.png create mode 100644 examples/assets/skies/space2.png create mode 100644 examples/assets/skies/sunorbit.png create mode 100644 examples/assets/skies/sunset.png create mode 100644 examples/assets/skies/toxic.png create mode 100644 examples/assets/skies/underwater1.png create mode 100644 examples/assets/skies/underwater2.png create mode 100644 examples/assets/skies/underwater3.png create mode 100644 examples/assets/skies/wtf.png create mode 100644 examples/input/key.php create mode 100644 examples/input/keyboard hotkeys.php create mode 100644 examples/input/keyboard justpressed.php create mode 100644 src/input/Key.js diff --git a/README.md b/README.md index c414119e..5126296a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ Version 1.0.7 (in progress in the dev branch) * Added Canvas.setUserSelect() to disable touchCallouts and user selections within the canvas. * When the game boots it will now by default disable user-select and touch action events on the game canvas. * Loaded.setPreloadSprite now rounds the width/height values and starts from 1. This fixes canvas draw errors in IE9/10 and Firefox. +* Fixed issue causing Keyboard.justPressed to always fire (thanks stemkoski) +* Added Keyboard.addKey() which creates a new Phaser.Key object that can be polled for updates, pressed states, etc. See the 2 new examples showing use. + diff --git a/build/phaser.js b/build/phaser.js index 2c1f1254..27401015 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -1,7 +1,7 @@ /** * Phaser - http://www.phaser.io * -* v1.0.7 - Built at: Mon, 30 Sep 2013 18:13:41 +0000 +* v1.0.7 - Built at: Mon, 30 Sep 2013 21:50:07 +0000 * * @author Richard Davey http://www.photonstorm.com @photonstorm * diff --git a/examples/assets/skies/cavern1.png b/examples/assets/skies/cavern1.png new file mode 100644 index 0000000000000000000000000000000000000000..9002fae23e78d65cec7ac706f2681a65f860bd67 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z;bvjvWntuFVH9Fv6k}zSWM`1$U{>X3(c@z?6J&J|VRIK}3sqoA(Pb>M1}Yx~qaiTl zL%_qtrMNQx%JmIa7S&>N;f=rGA%m*bS);-PmzxS!4@|Tk)3m08$ zTcpa!cBCP}fro=6YQy(?ubEtdS|kK`Iv5XWC0?E-2tRFDv0ZX$_FIlxS|PH7QI z0p=tJ0|hn~lBg36gTe~DWM4f@T~iV literal 0 HcmV?d00001 diff --git a/examples/assets/skies/cavern2.png b/examples/assets/skies/cavern2.png new file mode 100644 index 0000000000000000000000000000000000000000..c20943de1c666c6728fbacdfe54e8906e8d5fd4e GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z;bvjvWntuFVH9Fv6k}zSWM`1(WRvCLmf`1@78I5e5tkH`mXuPIl-H0_(Fdv@1*0J_ z)I-3-#HF}0|H}0ZHr9O{z`W4y>EaktaqG>clY&f+0?Y>`Bi235_`mn5qVkuMCJPr` zYg?qs$abV5!GVW^Bx=L=d#{;Xfm$R4csdvll0+Fj5bXkLGE|TdU~VFbN;$wxwoYjg zNde|02LlB*7LuqF4dog}3M2&%G&CnL$_J!4kQ_Wf4T{Wm3r_&Ul*HfxYH(t!ahwPY zQxZK143!q13MX=P{%BJIhAD|j2oy?^ADGEbMB-#81$nZQ0=ceDOM7O|(6+5fXWCok QCk#N~>FVdQ&MBb@07=~XqW}N^ literal 0 HcmV?d00001 diff --git a/examples/assets/skies/chrome.png b/examples/assets/skies/chrome.png new file mode 100644 index 0000000000000000000000000000000000000000..414f578e90a4f03fc5c2c662a760c8e9a3d99559 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z=|B9xcIW?`4gaH-|M#5t-+bzSwVwZ?&Hq!vbp746tSr=3G*zVJWCVmoSUGrr>PNw7 z2n_WQ@Gx;HuFSu3eZ#J^`BlKY(Cz8s7*cWT&83rqOpXG~2PGrcJ=d#Wzp$PyH&I|Pb literal 0 HcmV?d00001 diff --git a/examples/assets/skies/fire.png b/examples/assets/skies/fire.png new file mode 100644 index 0000000000000000000000000000000000000000..759fac2b7e9d75f58c2ef6d201505c196f9e70ca GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z0Rnk8CVL*%cp>(B39k8ay!%!7?`sMDHxT{jBlI_e|4$3g?**K{_OSi90kVG-jE2Ba z4}sFSq6JH4fBJN}AXM=jFfVj_x;TbZ+gh{_lONsQl%m$-+g~ z+7_uYvK?tiaNyw}iQ4e}-fJdTpcV-Mo({%?BvD2WM7w~R3>72*~2WGMpkvQ2&L7wcSK(1@k(w^Bfv~6qBnf6xs Q2?G##y85}Sb4q9e06+)`=>Px# literal 0 HcmV?d00001 diff --git a/examples/assets/skies/fog.png b/examples/assets/skies/fog.png new file mode 100644 index 0000000000000000000000000000000000000000..76c7386ca1e92de32a62ceb0e06256f489d87045 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zQJXSbt-D9PsYatRN24G{Gu=lk)mdKI;Vst02fOF^Z)<= literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sky1.png b/examples/assets/skies/sky1.png new file mode 100644 index 0000000000000000000000000000000000000000..18a30759a8195436cf3470bc5fb0f6839be72cb3 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zG3Z~Y+dfCDZn|38B<0**`P6oqm?nvkT2b!`A?IQ~t6XlQ40g?A7R5LQi3p(jQ7{?; zLp=maY0Wvzhn=fJ$s?djqeQgQ3erIUh8jsnaFB_q~7&G^6fsiN|ilO_un zU29vU%E)%4A;E!%gCuIh_j|9IT!C671b8|a50XR~JrL~zYBE%i5MXX1iAp)ZOtwyG z5lI2&BnJZpHWreo6Ak4WMhYYa4m30;Fv=fj2YUbj literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sky2.png b/examples/assets/skies/sky2.png new file mode 100644 index 0000000000000000000000000000000000000000..10a85c76a15900c57f5a57e5f88f7fdcc94069f4 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z0Rm=54t8ciZdOTtb|qmBEpaYmX&xInJ{KhcUp2u{E#Wvl(KI9Rd^5=ki26}-Gz5lp z2$aSZEm$)9)2GYE51#M=(|@<8i(^Q|tv8oW3NkqgFdvkRSobvJ|K6vH%3n^JEL?Q0 zZILP?+mVI@2ObWRs14umy=HO+YLO7&>0mra5@qy2v4T{NTNXOE PFaUw4tDnm{r-UW|i1Yum literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sky3.png b/examples/assets/skies/sky3.png new file mode 100644 index 0000000000000000000000000000000000000000..26714fafa9cd46c0968461324945cd0059b387f5 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zF|1f+UcK6`eywZsdY|?U!QGpp`nM!b-j+UXd)};_rSo>zEZWn&Y+u)^0~6OB0;(Sc zqaiTVL!dOSXu*=%pFUmQurP5IFfVj_x;TbZ+gh{_lONsQl%m z$-+g~+7_uYvK?tiaNyw}iQ4e}-fJdTpcV-Mo({%?BvD2WM7w~R3>72*~2WGMpkvQ2&L7wcSK(1@k(w^Bfv~6qB Unf6xs2?G##y85}Sb4q9e068`jI{*Lx literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sky4.png b/examples/assets/skies/sky4.png new file mode 100644 index 0000000000000000000000000000000000000000..a2989c3eef15569ed1f59c1abc99c2fb45e4d784 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z5u0^Xe%=X<#ixx{oU>kg$#vsZzil@ncHc=na6jwlqmq+PYtOxGzx-yxjrX(eeg>)^ z1*0J_)I*>&u4uuM*`GdLmVaBD4$KSPo-U3d6}R48Iw{EHD8PJBGGg7+jQ@L|Dk^_D zX|iz9wYEj7jBH055*&CqNTN1;zxSHS6{tl*fTx4;AW4+b1JN#^CPM`Y0p=!>sFVZD zWb2d`krZG~axhR}Vhw6tgT3~k$* Ubf&#ke!>6*p00i_>zopr081?v;Q#;t literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sky5.png b/examples/assets/skies/sky5.png new file mode 100644 index 0000000000000000000000000000000000000000..58db4343c8dc16f399bb7f02da7ffc98e10877c9 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zQIeEXl2uVu)KXM6P|!3}FtC@i^p$mulL^R^im8{%Xp}B(mT78}?eCDA(+yNV3PwX< zsE2@uiA!;1{*~(+g3sxG2j+!tPZ!6Kid%0kofKqp6kt9m8L{qZ#{a!f6_vl7G+DUl zTH7L3Mz$jj2@X6QBvBi_-+RsE3e+MYz|+BakR;0JfoK;{lc9oy0CN*bRLTKnvUN&} zND43~IT$Fgv5-WaXeie(QXnaCprJW|Q9dBWf#l!;YEWdhTX+H(rX&UrP=ga&jpIaM zn3Cv8V5qe4R5+2V^GBN!Fic5ILZDER{J>0hA`&M%DaezZ6v%aLTG}&vhPG`@I@8`N QKVbj@Pgg&ebxsLQ0A9@mZ2$lO literal 0 HcmV?d00001 diff --git a/examples/assets/skies/space1.png b/examples/assets/skies/space1.png new file mode 100644 index 0000000000000000000000000000000000000000..9d7643f1a0b1bc5c8f56dd2eeefaf903836e9a8b GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z0RmA&04#WAGf)|*Qw1(_TLm=8)utb3aAfA3R8ND3TiXii|14@hw!Ie35?6q)T7o&bg^iNOQZ;KWwrI1w18 zBzh7UDlI$}PUPzR(WV3pQxcO9D3l~WFq55##K}$y@?<9ka$TF2_ROB4ZCjJhw71Gn P7=Xaj)z4*}Q$iB}$A|on literal 0 HcmV?d00001 diff --git a/examples/assets/skies/space2.png b/examples/assets/skies/space2.png new file mode 100644 index 0000000000000000000000000000000000000000..2198cd4d760041e1d78b6317dc5c3e736b13398d GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z0RlD#HVy_3ZU$~X23|o%0TD)FQASa5CJ6~9X(?toDHcUZR%J;xH3<$)i26}-Gz5lp z2zZ#d6j$b7xxS&;qkT0nFLZmlIEGZ*dUNTdAd{m2^Fhgobx$+??|rJM{N<#{!bR8G z7O66_9cf5#;Nc*N+VK6}YbIBq76}2K4#tBdQAQ6$yMUSu6(j_hn@FNk4lt9gQ(8n) zfH}#*K!J^gB0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_A( zBq+iyCc!H$Bc!ToXrvfmC!6ObIXg<=L?*|V3Wjgpf35|wg*nQWcX zB9a2kNe%`IY%C;ECmPB%j1));9B61xV3ZF?aUeN(fEpB;?G~N@hAD}`1JvNeR^vDk z7^Wn85*R8iJQYsl>ip5B1PoIWlMpDBBtI~doruKAP73m5Ck1j{o0j&>o}q19lg_la R%1;=8z|+;wWt~$(69AT}3LpRg literal 0 HcmV?d00001 diff --git a/examples/assets/skies/sunset.png b/examples/assets/skies/sunset.png new file mode 100644 index 0000000000000000000000000000000000000000..18f5212bab9c575f84c71ff537de341fd2a85371 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zQDPR>U>4J3mNaFSv1XQcWL9!xRP|w23}lrFW0Q#H5RT{KPvPduCk2@t1(**?Myz|9@qh1AMddFiO%^V? z*0xBMk?lxBf&&i+Nz{h#_g*u(0<}m8@N_U9B#AP5Ale1gWT+q^z}!Rh{VZG3i4zp1#(@RmiEk^p>11}&a}76 QPZ)r})78&qol`;+0ITi&;Q#;t literal 0 HcmV?d00001 diff --git a/examples/assets/skies/toxic.png b/examples/assets/skies/toxic.png new file mode 100644 index 0000000000000000000000000000000000000000..8bfb378d079ea6ff211ce0f60ebddece650e913e GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zVHRU$Rb^*4<>GYZ;R)sEP2=S&=i%?*;-AT>zKX+PH(SIR*225Yo$r_y{Rb)^1*0J_ z8k!Rr<1M*si- literal 0 HcmV?d00001 diff --git a/examples/assets/skies/underwater1.png b/examples/assets/skies/underwater1.png new file mode 100644 index 0000000000000000000000000000000000000000..c1ee99001d2a56867f1f3ba6e1f62987e8670400 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zFgQtX~zG(PZgEFoHSXu z=vvz%RYtZW4G9iB93)X2zTbPzu(6OtooFc6Fj62XaG;?%fl)pn#ewAD0cucWwp(}t7^Wl!4^V>>TaDvH zV3?BVNnoh7@KiXFtMf;j5-?0jOhTYglKj9-b|MldJ1NMMofOD*ZCcthdxo}cO*+%w RDnDTW0#8>zmvv4FO#u1>3uFKQ literal 0 HcmV?d00001 diff --git a/examples/assets/skies/underwater2.png b/examples/assets/skies/underwater2.png new file mode 100644 index 0000000000000000000000000000000000000000..0af1808a116d12a6ddfc04fff3fea859e2c506f3 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zkuLL-D)N)e^OMN(6HD_GP4W|o^An2l7Yy?k2=eFm^XK*Q=W+ArcJk-63jnGg1*0J_ z)I*>&u4uuM*`GdLPSrFw1?GirPZ!6Kid%0kofKqp6kt9m8L{qZ#{a!f6_vl7G+DUl zTH7L3Mz$jj2@X6QBvBi_-+RsE3e+MYz|+BakR;0JfoK;{lc9oy0CN*bRLTKnvUN&} zND43~IT$Fgv5-WaXeie(QXnaCprJW|Q9dBWf#l!;YEWdhTX+H(rX&UrP=ga&jpIaM zn3Cv8V5qe4R5+2V^GBN!Fic5ILZDER{J>0hA`&M%DaezZ6v%aLTG}&vhPG`@I@8`N QKVbj@Pgg&ebxsLQ01t`->Hq)$ literal 0 HcmV?d00001 diff --git a/examples/assets/skies/underwater3.png b/examples/assets/skies/underwater3.png new file mode 100644 index 0000000000000000000000000000000000000000..d4ff8955007fec572a7662de08931b90ead83393 GIT binary patch literal 1809 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A3>0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL z0Rmvi{{dar1IEGZ*dUNTdAd{m2^Fhgobx$+??|rJM{N<#{!bR8G z7O66_9cf5#;Nc*N+VK6}YbIBq76}2K4#tBdQAQ6$yMUSu6(j_hn@FNk4lt9gQ(8n) zfH}#*K!J^gB0DF*SQ9yI14-?iy0WWg+Z8+Vb&Z8 zprAssN02WALzOxMLqjtI!><$|eTjjgtc`);%}WLb%Xth8qW_N7UAAIiU}gyL32_DL zS=A{zty!h9);PD!DWV|IB{M-kIbSNKUOF&e#w}jf%1>V3PC;2$Nm5Qq7--oj7!83T z9|9gGF2$AkSFUepSmFH(m>0S|T^vIyZoRp5Qjp0}fccX~BPY2^ck|?7GqFq2uh6)k_%uOUwDF>Lz)+sF_ zDZrfMV4%RpLK1bNp + + + + \ No newline at end of file diff --git a/examples/input/keyboard hotkeys.php b/examples/input/keyboard hotkeys.php new file mode 100644 index 00000000..94e162f6 --- /dev/null +++ b/examples/input/keyboard hotkeys.php @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file diff --git a/examples/input/keyboard justpressed.php b/examples/input/keyboard justpressed.php new file mode 100644 index 00000000..afddd675 --- /dev/null +++ b/examples/input/keyboard justpressed.php @@ -0,0 +1,47 @@ + + + + + \ No newline at end of file diff --git a/examples/js.php b/examples/js.php index bbf12080..32e1a272 100644 --- a/examples/js.php +++ b/examples/js.php @@ -52,6 +52,7 @@ + diff --git a/src/input/Input.js b/src/input/Input.js index f9df0d7a..a4075192 100644 --- a/src/input/Input.js +++ b/src/input/Input.js @@ -361,6 +361,7 @@ Phaser.Input.prototype = { if (this.pointer10) { this.pointer10.update(); } this._pollCounter = 0; + }, /** diff --git a/src/input/Key.js b/src/input/Key.js new file mode 100644 index 00000000..519b4e23 --- /dev/null +++ b/src/input/Key.js @@ -0,0 +1,142 @@ +Phaser.Key = function (game, keycode) { + + this.game = game; + + /** + * + * @property isDown + * @type Boolean + **/ + this.isDown = false; + + /** + * + * @property isUp + * @type Boolean + **/ + this.isUp = false; + + /** + * + * @property altKey + * @type Boolean + **/ + this.altKey = false; + + /** + * + * @property ctrlKey + * @type Boolean + **/ + this.ctrlKey = false; + + /** + * + * @property shiftKey + * @type Boolean + **/ + this.shiftKey = false; + + /** + * + * @property timeDown + * @type Number + **/ + this.timeDown = 0; + + /** + * + * @property duration + * @type Number + **/ + this.duration = 0; + + /** + * + * @property timeUp + * @type Number + **/ + this.timeUp = 0; + + /** + * + * @property repeats + * @type Number + **/ + this.repeats = 0; + + this.keyCode = keycode; + + this.onDown = new Phaser.Signal(); + this.onUp = new Phaser.Signal(); + +}; + +Phaser.Key.prototype = { + + /** + * + * @method update + * @param {KeyboardEvent} event. + * @return {} + */ + processKeyDown: function (event) { + + this.altKey = event.altKey; + this.ctrlKey = event.ctrlKey; + this.shiftKey = event.shiftKey; + + if (this.isDown) + { + // Key was already held down, this must be a repeat rate based event + this.duration = event.timeStamp - this.timeDown; + this.repeats++; + } + else + { + this.isDown = true; + this.isUp = false; + this.timeDown = event.timeStamp; + this.duration = 0; + this.repeats = 0; + + this.onDown.dispatch(this); + } + + }, + + processKeyUp: function (event) { + + this.isDown = false; + this.isUp = true; + this.timeUp = event.timeStamp; + + this.onUp.dispatch(this); + + }, + + /** + * @param {Number} [duration] + * @return {bool} + */ + justPressed: function (duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this.isDown && this.duration < duration); + + }, + + /** + * @param {Number} [duration] + * @return {bool} + */ + justReleased: function (duration) { + + if (typeof duration === "undefined") { duration = 250; } + + return (this.isDown == false && (this.game.time.now - this.timeUp < duration)); + + } + +}; \ No newline at end of file diff --git a/src/input/Keyboard.js b/src/input/Keyboard.js index 1096a9a1..c19ad892 100644 --- a/src/input/Keyboard.js +++ b/src/input/Keyboard.js @@ -2,7 +2,15 @@ Phaser.Keyboard = function (game) { this.game = game; this._keys = {}; + this._hotkeys = {}; this._capture = {}; + + this.callbackContext = this; + this.onDownCallback = null; + this.onUpCallback = null; + + this.onDown = new Phaser.Signal(); + this.onUp = new Phaser.Signal(); }; @@ -19,16 +27,41 @@ Phaser.Keyboard.prototype = { _onKeyDown: null, _onKeyUp: null, + addCallbacks: function (context, onDown, onUp) { + + this.callbackContext = context; + this.onDownCallback = onDown; + + if (typeof onUp !== 'undefined') + { + this.onUpCallback = onUp; + } + + }, + + addKey: function (keycode) { + + this._hotkeys[keycode] = new Phaser.Key(this.game, keycode); + return this._hotkeys[keycode]; + + }, + + removeKey: function (keycode) { + + delete (this._hotkeys[keycode]); + + }, + start: function () { var _this = this; this._onKeyDown = function (event) { - return _this.onKeyDown(event); + return _this.processKeyDown(event); }; this._onKeyUp = function (event) { - return _this.onKeyUp(event); + return _this.processKeyUp(event); }; document.body.addEventListener('keydown', this._onKeyDown, false); @@ -80,10 +113,11 @@ Phaser.Keyboard.prototype = { }, + /** * @param {KeyboardEvent} event */ - onKeyDown: function (event) { + processKeyDown: function (event) { if (this.game.input.disabled || this.disabled) { @@ -95,18 +129,40 @@ Phaser.Keyboard.prototype = { event.preventDefault(); } - if (!this._keys[event.keyCode]) + if (this.onDownCallback) { - this._keys[event.keyCode] = { - isDown: true, - timeDown: this.game.time.now, - timeUp: 0 - }; + this.onDownCallback.call(this.callbackContext, event); + } + + if (this._keys[event.keyCode] && this._keys[event.keyCode].isDown) + { + // Key already down and still down, so update + this._keys[event.keyCode].duration = this.game.time.now - this._keys[event.keyCode].timeDown; } else { - this._keys[event.keyCode].isDown = true; - this._keys[event.keyCode].timeDown = this.game.time.now; + if (!this._keys[event.keyCode]) + { + // Not used this key before, so register it + this._keys[event.keyCode] = { + isDown: true, + timeDown: this.game.time.now, + timeUp: 0, + duration: 0 + }; + } + else + { + // Key used before but freshly down + this._keys[event.keyCode].isDown = true; + this._keys[event.keyCode].timeDown = this.game.time.now; + this._keys[event.keyCode].duration = 0; + } + } + + if (this._hotkeys[event.keyCode]) + { + this._hotkeys[event.keyCode].processKeyDown(event); } }, @@ -114,7 +170,7 @@ Phaser.Keyboard.prototype = { /** * @param {KeyboardEvent} event */ - onKeyUp: function (event) { + processKeyUp: function (event) { if (this.game.input.disabled || this.disabled) { @@ -126,20 +182,19 @@ Phaser.Keyboard.prototype = { event.preventDefault(); } - if (!this._keys[event.keyCode]) + if (this.onUpCallback) { - this._keys[event.keyCode] = { - isDown: false, - timeDown: 0, - timeUp: this.game.time.now - }; + this.onUpCallback.call(this.callbackContext, event); } - else + + if (this._hotkeys[event.keyCode]) { - this._keys[event.keyCode].isDown = false; - this._keys[event.keyCode].timeUp = this.game.time.now; + this._hotkeys[event.keyCode].processKeyUp(event); } + this._keys[event.keyCode].isDown = false; + this._keys[event.keyCode].timeUp = this.game.time.now; + }, reset: function () { @@ -160,7 +215,7 @@ Phaser.Keyboard.prototype = { if (typeof duration === "undefined") { duration = 250; } - if (this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) + if (this._keys[keycode] && this._keys[keycode].isDown && this._keys[keycode].duration < duration) { return true; }