Skip to content

Commit 902ffee

Browse files
committed
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.
1 parent d1cd1df commit 902ffee

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ New features:
7474
* 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'.
7575
* Buttons now properly use their upFrame if set.
7676
* InputHandler now has snapOffsetX and snapOffsetY properties so your snap grid doesn't have to be 0,0 aligned (thanks srmeier)
77+
* 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.
7778

7879

7980
New Examples:

examples/wip/demo worm.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('ball', 'assets/sprites/shinyball.png');
7+
8+
}
9+
10+
var sprite;
11+
var particles = [];
12+
var bmd;
13+
14+
var u = 0;
15+
var n = 0;
16+
var oldn = 0;
17+
var ad = 0;
18+
19+
function create() {
20+
21+
bmd = game.add.bitmapData(640, 480);
22+
23+
for (var i = 0; i < 30; i++)
24+
{
25+
particles.push(new Phaser.Point(0, 0));
26+
}
27+
28+
sprite = game.add.sprite(0, 0, bmd);
29+
30+
}
31+
32+
function mycircle(context, x, y, R, color) {
33+
34+
context.fillStyle = color;
35+
context.beginPath();
36+
context.arc(x, y, R, 0, Math.PI * 2, true);
37+
context.closePath();
38+
context.fill();
39+
40+
}
41+
42+
function update() {
43+
44+
bmd.clear();
45+
46+
oldn = n;
47+
48+
for (var t = 0; t < particles.length; t++)
49+
{
50+
var p = particles[t];
51+
52+
p.x = Math.sin(n) * 50 + Math.cos(n * 1.5) * 200;
53+
p.y = Math.sin(n / 2) * 20 + Math.sin(n * 2) * 150;
54+
55+
var tx = p.x;
56+
var ty = p.y;
57+
58+
bmd.context.globalCompositeOperation = 'xor';
59+
60+
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)');
61+
62+
n += 0.1;
63+
64+
bmd.context.globalCompositeOperation = 'source-over';
65+
}
66+
67+
n = oldn + 0.03;
68+
69+
}
70+
71+
function render() {
72+
73+
}

src/loader/Loader.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Phaser.Loader = function (game) {
3434
this._fileIndex = 0;
3535

3636
/**
37-
* @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100)
37+
* @property {number} _progressChunk - Indicates the size of 1 file in terms of a percentage out of 100.
3838
* @private
3939
* @default
4040
*/
@@ -59,11 +59,17 @@ Phaser.Loader = function (game) {
5959
this.hasLoaded = false;
6060

6161
/**
62-
* @property {number} progress - The Load progress percentage value (from 0 to 100)
62+
* @property {number} progress - The rounded load progress percentage value (from 0 to 100)
6363
* @default
6464
*/
6565
this.progress = 0;
6666

67+
/**
68+
* @property {number} progressFloat - The non-rounded load progress value (from 0.0 to 100.0)
69+
* @default
70+
*/
71+
this.progressFloat = 0;
72+
6773
/**
6874
* You can optionally link a sprite to the preloader.
6975
* 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 = {
713719
}
714720

715721
this.progress = 0;
722+
this.progressFloat = 0;
716723
this.hasLoaded = false;
717724
this.isLoading = true;
718725

@@ -727,6 +734,7 @@ Phaser.Loader.prototype = {
727734
else
728735
{
729736
this.progress = 100;
737+
this.progressFloat = 100;
730738
this.hasLoaded = true;
731739
this.onLoadComplete.dispatch();
732740
}
@@ -1217,7 +1225,8 @@ Phaser.Loader.prototype = {
12171225
*/
12181226
nextFile: function (previousIndex, success) {
12191227

1220-
this.progress = Math.round(this.progress + this._progressChunk);
1228+
this.progressFloat += this._progressChunk;
1229+
this.progress = Math.round(this.progressFloat);
12211230

12221231
if (this.progress > 100)
12231232
{

0 commit comments

Comments
 (0)