From fc584cf6bc2e939d786e74ff97e2d12021b53eb8 Mon Sep 17 00:00:00 2001 From: Webeled Date: Mon, 16 Sep 2013 16:37:30 +0200 Subject: [PATCH] Examples (audio, button,camera), and docs Created some examples (audio, button,camera), and documented the source code along the way --- examples/assets/audio/SoundEffects/squit.mp3 | Bin 0 -> 4997 bytes examples/assets/audio/SoundEffects/squit.ogg | Bin 0 -> 5450 bytes examples/audio/loop.php | 51 ++++++++++++ examples/buttons/action on click.php | 48 +++++++++++ examples/buttons/changing the frames.php | 55 +++++++++++++ examples/buttons/rotated buttons.php | 56 +++++++++++++ examples/camera/basic follow.php | 76 ++++++++++++++++++ examples/camera/moving the game camera.php | 60 ++++++++++++++ examples/sprites/sprite4.php | 2 - .../sprites/{sprite2.php => spritesheet.php} | 0 src/core/Camera.js | 9 +++ src/core/Stage.js | 7 ++ src/core/World.js | 7 +- src/gameobjects/Button.js | 12 ++- src/sound/Sound.js | 18 ++++- 15 files changed, 393 insertions(+), 8 deletions(-) create mode 100644 examples/assets/audio/SoundEffects/squit.mp3 create mode 100644 examples/assets/audio/SoundEffects/squit.ogg create mode 100644 examples/audio/loop.php create mode 100644 examples/buttons/action on click.php create mode 100644 examples/buttons/changing the frames.php create mode 100644 examples/buttons/rotated buttons.php create mode 100644 examples/camera/basic follow.php create mode 100644 examples/camera/moving the game camera.php rename examples/sprites/{sprite2.php => spritesheet.php} (100%) diff --git a/examples/assets/audio/SoundEffects/squit.mp3 b/examples/assets/audio/SoundEffects/squit.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..24a6d7e9c292d128be2fb6ce4cf89dd3ead2ae66 GIT binary patch literal 4997 zcmezWd%_V0bP$o5mkt!;2Vx}#2H{o)Jv~=fS8s3cz`(%p@bK8!*rcSSjEs!Dyu6Z< zlB%kzhK7dL*4FOs?uip8PM5CUH zUcY|*?%lhO9zA;T;>Ejn@4kHb^6S^H|Nnt@1^77nx*F?QS{AYFggMDnL4{4tk%936 z$Q@57shPqgMhgA^_XS`Caou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/audio/SoundEffects/squit.ogg new file mode 100644 index 0000000000000000000000000000000000000000..e28915bac9d0e186209cc4bfc3d063ceea95aa6d GIT binary patch literal 5450 zcmcIodpy)x|NpwqupUhejg}fkjHreYRLjYTt8$y+H~(z#n=t3c-=7Om&h!7L zjVLT^L;!rp&9>N(SYOr_Y>@dnJboR)oDhsP4h>;4!mzP1SpSGUyVh)u4>w|BcSnS7 zk;%uwLgbVd_P~*xw#Y$9FoWNOZRB+1(I5x~K|2g^>IFN=I3cgxc;7Le8%#B>%Q(i% zXvEO7@#1d-mJp@|L5dK^SS9z=C^=F>496Jd#+MNzJgrY-5t-gki7IzLtfI$MUapLa zk>CuG{|ZoofP);|^i$DPcnD3`Ps4!Wux@;_{%JwHs>zwMWL5KKY|19{@rnXZoAEQJ za&0DzFL#i>GrQbH*@W-eLa(`@9DI-|A&v>Y4k|J`us|1*vQ8L^goL+G$5kGS2U{(e zg@ri4Ovv>JntTD>dO^3n(_r&EQ*TYnP74%yg_ARJM}He}+4`V(H1>h$j`eY3JmjFxVwnmHZXB{8Qx0 zosl&W#dW*R)X){#V}_z-Rn(ci7cz0yzL*HpS^S#TmFz z4VvOj5i$=qLm;LORMW8;ec&1R7QXg1aR;&p<43_m4N09q%Y&O2}$O!UbxdMlqtgste5N zj0x1mIw4?PL{|}_s^1^H8_-cSdZr!?s0?1QQEk2N!hT<2QMFAVxkDTVZ)7|wj;dD) z2GnerV5(gOp8Gp|96;Pc`Y_^>WGp*ZITWp5sb8=x;b--NGJG?xVp&e^MoLwR7gfhd zn2;>991B5Qlnlk+1{stWP+XCpX>#BAQk!|JDLkBOkl0NA(tvVO!vhqXS^^a3)Q+BD z))3vIgtgMZ)j}SXf)g%e6bLFdEYDF{N0uaM$KvnfPJ^uYYvA4(JXoyP`Ir9St**C* zA?TgvWs zDhmPrmN{|grX#v7M-1FA8hCV>w!b56o+fl^x_A>je6)f)wOHNS44?JE-Ik1Q8lxwX z(O<_1y21{q`!DiqP|aw*_WwI$0Jn$W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lMjX+Erg4mnX%mJ-XH_IY+vqY@uIf-$c$-=1$quONUMgo^jUb z+09xw?R_X3oK5msb2m2g%B2UN1$#EfJu9;=WAu3EKrId)?PnE>|FaD4>((JLm_oUaZrO(>B$FF@xiH*Ki+q%q8kGR5K zfBwM4&D29ze2(mwhtv)!4K>{16*=zYB!%1aVp}k3R?p_VN2=#L_ToH8#{H$XH=c5{ z9myTE7`A=!p`D+GZYs)IJ%939y!_oW!^#ZzGFnSI{Qdcti8Y0{ z+iJ=>o>@UQORj$|K$UHI^}_U)Wk5u^Xv+H8ld%hP6Q$?PIMPoWGwZ@L0w7iBm(lqH zRYx`1*J~aq&y`gpZhaiv`ejezy_Rz3>mPspqw5yydB9%QaXcUV|KePc(;y)_j}(n2 zDz;7uET3N!O<-DQYxT1VmhV?tcHUzp0csv77%Um&Uo$i$wtVsT+GK{=e`zB*CsOT` z?Vj2g(y9@Y$g5Y@o>kmy#X`iV3>m3bmL9HZ@a%Y#JbJoZD5y=S1lNUk1KHZfYsR&& zr^_D?*#R#4Kg?ZXf)l#zQ(e@dMP}RH&O3ra=^zcfl{TXQZFBvUBuTQY$8r=Lur?8y zkOg3_QpL<2zPrupou_we1MZzXr}WkI4zm+MySIu1rghkMT3OZK&xUM0Ar;-SDc%ru jWnxp(mZ^KTIndK#OqKoZ9*#w1I2!6JJ);My|8x5{c@zXx literal 0 HcmV?d00001 diff --git a/examples/audio/loop.php b/examples/audio/loop.php new file mode 100644 index 000000000..cfbc76de4 --- /dev/null +++ b/examples/audio/loop.php @@ -0,0 +1,51 @@ + + + + + diff --git a/examples/buttons/action on click.php b/examples/buttons/action on click.php new file mode 100644 index 000000000..ad4e34444 --- /dev/null +++ b/examples/buttons/action on click.php @@ -0,0 +1,48 @@ + + + + + diff --git a/examples/buttons/changing the frames.php b/examples/buttons/changing the frames.php new file mode 100644 index 000000000..f61316c4d --- /dev/null +++ b/examples/buttons/changing the frames.php @@ -0,0 +1,55 @@ + + + + + diff --git a/examples/buttons/rotated buttons.php b/examples/buttons/rotated buttons.php new file mode 100644 index 000000000..44d333697 --- /dev/null +++ b/examples/buttons/rotated buttons.php @@ -0,0 +1,56 @@ + + + + + diff --git a/examples/camera/basic follow.php b/examples/camera/basic follow.php new file mode 100644 index 000000000..c44fa5606 --- /dev/null +++ b/examples/camera/basic follow.php @@ -0,0 +1,76 @@ + + + + + + diff --git a/examples/camera/moving the game camera.php b/examples/camera/moving the game camera.php new file mode 100644 index 000000000..d1dcb921b --- /dev/null +++ b/examples/camera/moving the game camera.php @@ -0,0 +1,60 @@ + + + + + + diff --git a/examples/sprites/sprite4.php b/examples/sprites/sprite4.php index fbbc121ad..161c1830a 100644 --- a/examples/sprites/sprite4.php +++ b/examples/sprites/sprite4.php @@ -17,8 +17,6 @@ function create() { - // game.world._stage.backgroundColorString = '#182d3b'; - s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot'); // s.anchor.setTo(0.5, 0.5); s.scale.setTo(2, 2); diff --git a/examples/sprites/sprite2.php b/examples/sprites/spritesheet.php similarity index 100% rename from examples/sprites/sprite2.php rename to examples/sprites/spritesheet.php diff --git a/src/core/Camera.js b/src/core/Camera.js index 4d0cf1c19..b738e5f52 100644 --- a/src/core/Camera.js +++ b/src/core/Camera.js @@ -3,6 +3,15 @@ * * A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. * The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y +* +* @class Phaser.Camera +* @constructor +* @param game {Phaser.Game} game reference to the currently running game. +* @param id {number} not being used at the moment, will be when Phaser supports multiple camera +* @param x {number} position of the camera on the X axis +* @param y {number} position of the camera on the Y axis +* @param width {number} the width of the view rectangle +* @param height {number} the height of the view rectangle */ Phaser.Camera = function (game, id, x, y, width, height) { diff --git a/src/core/Stage.js b/src/core/Stage.js index bbdf967b1..12859f869 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -8,6 +8,13 @@ * @author Richard Davey * @copyright 2013 Photon Storm Ltd. * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License + + +* @class Phaser.Camera +* @constructor +* @param game {Phaser.Game} game reference to the currently running game. +* @param width {number} width of the canvas element +* @param height {number} height of the canvas element */ Phaser.Stage = function (game, width, height) { diff --git a/src/core/World.js b/src/core/World.js index 92c153e0d..9fb89b6eb 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -11,6 +11,10 @@ * @author Richard Davey * @copyright 2013 Photon Storm Ltd. * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License + + * @class World + * @constructor + * @param game {Phaser.Game} reference to the current game instance. */ Phaser.World = function (game) { @@ -91,7 +95,7 @@ Phaser.World.prototype = { /** * Updates the size of this world. - * + * @method setSize * @param width {number} New width of the world. * @param height {number} New height of the world. */ @@ -111,6 +115,7 @@ Phaser.World.prototype = { /** * Destroyer of worlds. + * @method setSize */ destroy: function () { diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index 5a063fe71..9aea56349 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -1,5 +1,7 @@ /** * Create a new Button object. +* @class Button +* @constructor * * @param game {Phaser.Game} Current game instance. * @param [x] {number} X position of the button. @@ -58,7 +60,15 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, Phaser.Button.prototype = Phaser.Utils.extend(true, Phaser.Sprite.prototype, PIXI.Sprite.prototype); Phaser.Button.prototype.constructor = Phaser.Button; -// Add our own custom methods +/** +* Used to manually set the frames that will be used for the different states of the button +* exactly like setting them in the constructor +* +* @method setFrames +* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. +* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. +* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. +*/ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { diff --git a/src/sound/Sound.js b/src/sound/Sound.js index 9774fbb0d..3f685c20f 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -1,7 +1,17 @@ +/** +* The Sound class +* +* @class Sound +* @constructor +* @param game {Phaser.Game} reference to the current game instance. +* @param key {string} Asset key for the sound. +* @param volume {number} default value for the volume. +* @param loop {bool} Whether or not the sound will loop. +*/ Phaser.Sound = function (game, key, volume, loop) { volume = volume || 1; - loop = loop || false; + if (typeof loop == 'undefined') { loop = false; } this.game = game; this.name = ''; @@ -187,8 +197,8 @@ Phaser.Sound.prototype = { marker = marker || ''; position = position || 0; volume = volume || 1; - loop = loop || false; - forceRestart = forceRestart || false; + if (typeof loop == 'undefined') { loop = false; } + if (typeof forceRestart == 'undefined') { forceRestart = false; } // console.log('play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop); @@ -356,7 +366,7 @@ Phaser.Sound.prototype = { marker = marker || ''; position = position || 0; volume = volume || 1; - loop = loop || false; + if (typeof loop == 'undefined') { loop = false; } this.play(marker, position, volume, loop, true);