From 902ffee80869799d10a84ca268592a74bdc49fb0 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Tue, 31 Dec 2013 17:35:40 +0000 Subject: [PATCH] Loader.progressFloat contains the actual non-rounded progress value, where-as Loader.progress contains a rounded value. Use progressFloat if you've > 100 files to load. --- README.md | 1 + examples/wip/demo worm.js | 73 +++++++++++++++++++++++++++++++++++++++ src/loader/Loader.js | 15 ++++++-- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 examples/wip/demo worm.js diff --git a/README.md b/README.md index 1d826d0d..eebfdf13 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ New features: * Tweens can now work with relative + and - values. You can do: `tween(sprite).to( { x: '+400' })` and it will add 400 to the current sprite.x value, or '-400'. * Buttons now properly use their upFrame if set. * InputHandler now has snapOffsetX and snapOffsetY properties so your snap grid doesn't have to be 0,0 aligned (thanks srmeier) +* Loader.progressFloat contains the actual non-rounded progress value, where-as Loader.progress contains a rounded value. Use progressFloat if you've > 100 files to load. New Examples: diff --git a/examples/wip/demo worm.js b/examples/wip/demo worm.js new file mode 100644 index 00000000..e5878e54 --- /dev/null +++ b/examples/wip/demo worm.js @@ -0,0 +1,73 @@ + +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); + +function preload() { + + game.load.image('ball', 'assets/sprites/shinyball.png'); + +} + +var sprite; +var particles = []; +var bmd; + +var u = 0; +var n = 0; +var oldn = 0; +var ad = 0; + +function create() { + + bmd = game.add.bitmapData(640, 480); + + for (var i = 0; i < 30; i++) + { + particles.push(new Phaser.Point(0, 0)); + } + + sprite = game.add.sprite(0, 0, bmd); + +} + +function mycircle(context, x, y, R, color) { + + context.fillStyle = color; + context.beginPath(); + context.arc(x, y, R, 0, Math.PI * 2, true); + context.closePath(); + context.fill(); + +} + +function update() { + + bmd.clear(); + + oldn = n; + + for (var t = 0; t < particles.length; t++) + { + var p = particles[t]; + + p.x = Math.sin(n) * 50 + Math.cos(n * 1.5) * 200; + p.y = Math.sin(n / 2) * 20 + Math.sin(n * 2) * 150; + + var tx = p.x; + var ty = p.y; + + bmd.context.globalCompositeOperation = 'xor'; + + mycircle(bmd.context, p.x + 320, p.y + 240, Math.sin(t * 360 / particles.length / 2 * Math.PI / 180) * 60, 'rgba(255, 255, 255, 1)'); + + n += 0.1; + + bmd.context.globalCompositeOperation = 'source-over'; + } + + n = oldn + 0.03; + +} + +function render() { + +} diff --git a/src/loader/Loader.js b/src/loader/Loader.js index 03c5784c..0fc5ac00 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -34,7 +34,7 @@ Phaser.Loader = function (game) { this._fileIndex = 0; /** - * @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100) + * @property {number} _progressChunk - Indicates the size of 1 file in terms of a percentage out of 100. * @private * @default */ @@ -59,11 +59,17 @@ Phaser.Loader = function (game) { this.hasLoaded = false; /** - * @property {number} progress - The Load progress percentage value (from 0 to 100) + * @property {number} progress - The rounded load progress percentage value (from 0 to 100) * @default */ this.progress = 0; + /** + * @property {number} progressFloat - The non-rounded load progress value (from 0.0 to 100.0) + * @default + */ + this.progressFloat = 0; + /** * You can optionally link a sprite to the preloader. * If you do so the Sprite's width or height will be cropped based on the percentage loaded. @@ -713,6 +719,7 @@ Phaser.Loader.prototype = { } this.progress = 0; + this.progressFloat = 0; this.hasLoaded = false; this.isLoading = true; @@ -727,6 +734,7 @@ Phaser.Loader.prototype = { else { this.progress = 100; + this.progressFloat = 100; this.hasLoaded = true; this.onLoadComplete.dispatch(); } @@ -1217,7 +1225,8 @@ Phaser.Loader.prototype = { */ nextFile: function (previousIndex, success) { - this.progress = Math.round(this.progress + this._progressChunk); + this.progressFloat += this._progressChunk; + this.progress = Math.round(this.progressFloat); if (this.progress > 100) {