From 15ad941908696e64e5b7910a94abe260d6b95c5e Mon Sep 17 00:00:00 2001 From: TheJare Date: Sat, 21 Sep 2013 19:23:25 +0200 Subject: [PATCH] Alternative way to specify tile size in spritesheets: negative means how many tiles there are --- src/animation/Parser.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/animation/Parser.js b/src/animation/Parser.js index a711c202..0c420392 100644 --- a/src/animation/Parser.js +++ b/src/animation/Parser.js @@ -15,8 +15,8 @@ Phaser.Animation.Parser = { * @method spriteSheet * @param {Phaser.Game} game A reference to the currently running game. * @param {String} key The Game.Cache asset key of the Sprite Sheet image. - * @param {Number} frameWidth The fixed width of each frame of the animation. - * @param {Number} frameHeight The fixed height of each frame of the animation. + * @param {Number} frameWidth The fixed width of each frame of the animation. If negative, indicates how many columns there are. + * @param {Number} frameHeight The fixed height of each frame of the animation. If negative, indicates how many rows there are. * @param {Number} [frameMax=-1] The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames". * @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames. */ @@ -32,6 +32,14 @@ Phaser.Animation.Parser = { var width = img.width; var height = img.height; + if (frameWidth <= 0) + { + frameWidth = Math.floor(-width/Math.min(-1, frameWidth)); + } + if (frameHeight <= 0) + { + frameHeight = Math.floor(-height/Math.min(-1, frameHeight)); + } var row = Math.round(width / frameWidth); var column = Math.round(height / frameHeight); var total = row * column;