diff --git a/resources/tutorials/02 Making your first game/part8.html b/resources/tutorials/02 Making your first game/part8.html index beec56ffa..99ba7bea6 100644 --- a/resources/tutorials/02 Making your first game/part8.html +++ b/resources/tutorials/02 Making your first game/part8.html @@ -103,7 +103,7 @@ function create() { function update() { // Collide the player and the stars with the platforms - game.physics.arcade.collide(player, platforms); + var hitPlatform = game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(stars, platforms); // Checks to see if the player overlaps with any of the stars, if he does call the collectStar function @@ -135,7 +135,7 @@ function update() { } // Allow the player to jump if they are touching the ground. - if (cursors.up.isDown && player.body.touching.down) + if (cursors.up.isDown && player.body.touching.down && hitPlatform) { player.body.velocity.y = -350; } diff --git a/resources/tutorials/02 Making your first game/part9.html b/resources/tutorials/02 Making your first game/part9.html index 32700bef8..53f0d4c0a 100644 --- a/resources/tutorials/02 Making your first game/part9.html +++ b/resources/tutorials/02 Making your first game/part9.html @@ -108,7 +108,7 @@ function create() { function update() { // Collide the player and the stars with the platforms - game.physics.arcade.collide(player, platforms); + var hitPlatform = game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(stars, platforms); // Checks to see if the player overlaps with any of the stars, if he does call the collectStar function @@ -140,7 +140,7 @@ function update() { } // Allow the player to jump if they are touching the ground. - if (cursors.up.isDown && player.body.touching.down) + if (cursors.up.isDown && player.body.touching.down && hitPlatform) { player.body.velocity.y = -350; } diff --git a/resources/tutorials/02 Making your first game/phaser_1x_tutorial_02.zip b/resources/tutorials/02 Making your first game/phaser_1x_tutorial_02.zip deleted file mode 100644 index d28335e99..000000000 Binary files a/resources/tutorials/02 Making your first game/phaser_1x_tutorial_02.zip and /dev/null differ diff --git a/resources/tutorials/02 Making your first game/phaser_tutorial_02.zip b/resources/tutorials/02 Making your first game/phaser_tutorial_02.zip index bb8544fe8..2b1bcad73 100644 Binary files a/resources/tutorials/02 Making your first game/phaser_tutorial_02.zip and b/resources/tutorials/02 Making your first game/phaser_tutorial_02.zip differ diff --git a/src/animation/AnimationParser.js b/src/animation/AnimationParser.js index c263721a5..31a35f54e 100644 --- a/src/animation/AnimationParser.js +++ b/src/animation/AnimationParser.js @@ -24,12 +24,16 @@ Phaser.AnimationParser = { * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here. * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. * @param {number} [skipFrames=0] - Skip a number of frames. Useful when there are multiple sprite sheets in one image. + * @param {Phaser.Frame} [frame] - Optional Frame, if this font is embedded in a texture atlas. * @return {Phaser.FrameData} A FrameData object containing the parsed frames. */ - spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing, skipFrames) { + spriteSheet: function (game, key, frameWidth, frameHeight, frameMax, margin, spacing, skipFrames, frame) { var img = key; + var frameX = (frame) ? frame.x : 0; + var frameY = (frame) ? frame.y : 0; + if (typeof key === 'string') { img = game.cache.getImage(key); @@ -91,7 +95,7 @@ Phaser.AnimationParser = { for (var i = 0; i < total; i++) { - data.addFrame(new Phaser.Frame(i, x, y, frameWidth, frameHeight, '')); + data.addFrame(new Phaser.Frame(i, x + frameX, y + frameY, frameWidth, frameHeight, '')); x += frameWidth + spacing; diff --git a/src/loader/Cache.js b/src/loader/Cache.js index 9edf365dd..7977cff5e 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -710,6 +710,60 @@ Phaser.Cache.prototype = { }, + /** + * Add a new Sprite Sheet to the Cache, where the sheet is part of a Texture Atlas. + * + * The atlas must already exist in the cache, and be available based on the given `atlasKey`. + * + * The `atlasFrame` specifies the name of the frame within the atlas that the Sprite Sheet is + * stored in. + * + * @method Phaser.Cache#addSpriteSheetFromAtlas + * @param {string} key - The key that this asset will be stored in the cache under. This should be unique within this cache. + * @param {string} atlasKey - The key of the Texture Atlas in the Cache. + * @param {string} atlasFrame - The frame of the Texture Atlas that the Sprite Sheet is in. + * @param {number} frameWidth - Width of the sprite sheet. + * @param {number} frameHeight - Height of the sprite sheet. + * @param {number} [frameMax=-1] - How many frames stored in the sprite sheet. If -1 then it divides the whole sheet evenly. + * @param {number} [margin=0] - If the frames have been drawn with a margin, specify the amount here. + * @param {number} [spacing=0] - If the frames have been drawn with spacing between them, specify the amount here. + * @param {number} [skipFrames=0] - Skip a number of frames. Useful when there are multiple sprite sheets in one image. + */ + addSpriteSheetFromAtlas: function (key, atlasKey, atlasFrame, frameWidth, frameHeight, frameMax, margin, spacing, skipFrames) { + + if (frameMax === undefined) { frameMax = -1; } + if (margin === undefined) { margin = 0; } + if (spacing === undefined) { spacing = 0; } + + var frame = this.getFrameByName(atlasKey, atlasFrame); + + if (!frame) + { + return; + } + + var obj = { + font: null, + base: this.getBaseTexture(atlasKey), + frame: frame + }; + + + var obj = { + key: key, + frameWidth: frameWidth, + frameHeight: frameHeight, + margin: margin, + spacing: spacing, + base: this.getBaseTexture(atlasKey), + frame: frame, + frameData: Phaser.AnimationParser.spriteSheet(this.game, data, frameWidth, frameHeight, frameMax, margin, spacing, skipFrames, frame) + }; + + this._cache.image[key] = obj; + + }, + /** * Add a new texture atlas to the Cache. *