Skip to content

Commit e119e3a

Browse files
committed
Huge update to move all classes to common Phaser Class format. Tidying up lots. Removing un-needed files.
1 parent 03f217a commit e119e3a

45 files changed

Lines changed: 1047 additions & 1194 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

v3/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ node_modules/
1212
# Build
1313
dist/
1414
/npm-debug.log
15-
out/
15+
out/
16+
src/checksum.js
Lines changed: 71 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var Class = require('../../utils/Class');
12
var GetValue = require('../../utils/object/GetValue');
23
var GetFrames = require('./GetFrames');
34

@@ -8,97 +9,97 @@ var GetFrames = require('./GetFrames');
89
// Game Objects have the Animation Component, which are like playheads to global Animations (these objects)
910
// So multiple Game Objects can have playheads all pointing to this one Animation instance
1011

11-
var Animation = function (manager, key, config)
12-
{
13-
this.manager = manager;
12+
var Animation = new Class({
1413

15-
this.key = key;
14+
initialize:
1615

17-
// A frame based animation (as opposed to a bone based animation)
18-
this.type = 'frame';
16+
function Animation (manager, key, config)
17+
{
18+
this.manager = manager;
1919

20-
// Extract all the frame data into the frames array
21-
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []));
20+
this.key = key;
2221

23-
// The frame rate of playback in frames per second (default 24 if duration is null)
24-
this.frameRate = GetValue(config, 'framerate', null);
22+
// A frame based animation (as opposed to a bone based animation)
23+
this.type = 'frame';
2524

26-
// How long the animation should play for. If frameRate is set it overrides this value
27-
// otherwise frameRate is derived from duration
28-
this.duration = GetValue(config, 'duration', null);
25+
// Extract all the frame data into the frames array
26+
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []));
2927

30-
if (this.duration === null && this.frameRate === null)
31-
{
32-
// No duration or frameRate given, use default frameRate of 24fps
33-
this.frameRate = 24;
34-
this.duration = this.frameRate / this.frames.length;
35-
}
36-
else if (this.duration && this.frameRate === null)
37-
{
38-
// Duration given but no frameRate, so set the frameRate based on duration
39-
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
40-
// So frameRate is 12 / 4 = 3 fps
41-
this.frameRate = this.frames.length / this.duration;
42-
}
43-
else
44-
{
45-
// frameRate given, derive duration from it (even if duration also specified)
46-
// I.e. 15 frames in the animation, frameRate = 30 fps
47-
// So duration is 15 / 30 = 0.5 (half a second)
48-
this.duration = this.frames.length / this.frameRate;
49-
}
28+
// The frame rate of playback in frames per second (default 24 if duration is null)
29+
this.frameRate = GetValue(config, 'framerate', null);
5030

51-
// ms per frame (without including frame specific modifiers)
52-
this.msPerFrame = 1000 / this.frameRate;
31+
// How long the animation should play for. If frameRate is set it overrides this value
32+
// otherwise frameRate is derived from duration
33+
this.duration = GetValue(config, 'duration', null);
5334

54-
// Skip frames if the time lags, or always advanced anyway?
55-
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
35+
if (this.duration === null && this.frameRate === null)
36+
{
37+
// No duration or frameRate given, use default frameRate of 24fps
38+
this.frameRate = 24;
39+
this.duration = this.frameRate / this.frames.length;
40+
}
41+
else if (this.duration && this.frameRate === null)
42+
{
43+
// Duration given but no frameRate, so set the frameRate based on duration
44+
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
45+
// So frameRate is 12 / 4 = 3 fps
46+
this.frameRate = this.frames.length / this.duration;
47+
}
48+
else
49+
{
50+
// frameRate given, derive duration from it (even if duration also specified)
51+
// I.e. 15 frames in the animation, frameRate = 30 fps
52+
// So duration is 15 / 30 = 0.5 (half a second)
53+
this.duration = this.frames.length / this.frameRate;
54+
}
5655

57-
// Delay before starting playback (in seconds)
58-
this.delay = GetValue(config, 'delay', 0);
56+
// ms per frame (without including frame specific modifiers)
57+
this.msPerFrame = 1000 / this.frameRate;
5958

60-
// Number of times to repeat the animation (-1 for infinity)
61-
this.repeat = GetValue(config, 'repeat', 0);
59+
// Skip frames if the time lags, or always advanced anyway?
60+
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
6261

63-
// Delay before the repeat starts (in seconds)
64-
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
62+
// Delay before starting playback (in seconds)
63+
this.delay = GetValue(config, 'delay', 0);
6564

66-
// Should the animation yoyo? (reverse back down to the start) before repeating?
67-
this.yoyo = GetValue(config, 'yoyo', false);
65+
// Number of times to repeat the animation (-1 for infinity)
66+
this.repeat = GetValue(config, 'repeat', 0);
6867

69-
// Should sprite.visible = true when the animation starts to play?
70-
this.showOnStart = GetValue(config, 'showOnStart', false);
68+
// Delay before the repeat starts (in seconds)
69+
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
7170

72-
// Should sprite.visible = false when the animation finishes?
73-
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
71+
// Should the animation yoyo? (reverse back down to the start) before repeating?
72+
this.yoyo = GetValue(config, 'yoyo', false);
7473

75-
// Callbacks
76-
this.callbackScope = GetValue(config, 'callbackScope', this);
74+
// Should sprite.visible = true when the animation starts to play?
75+
this.showOnStart = GetValue(config, 'showOnStart', false);
7776

78-
this.onStart = GetValue(config, 'onStart', false);
79-
this.onStartParams = GetValue(config, 'onStartParams', []);
77+
// Should sprite.visible = false when the animation finishes?
78+
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
8079

81-
this.onRepeat = GetValue(config, 'onRepeat', false);
82-
this.onRepeatParams = GetValue(config, 'onRepeatParams', []);
80+
// Callbacks
81+
this.callbackScope = GetValue(config, 'callbackScope', this);
8382

84-
// Called for EVERY frame of the animation.
85-
// See AnimationFrame.onUpdate for a frame specific callback.
86-
this.onUpdate = GetValue(config, 'onUpdate', false);
87-
this.onUpdateParams = GetValue(config, 'onUpdateParams', []);
83+
this.onStart = GetValue(config, 'onStart', false);
84+
this.onStartParams = GetValue(config, 'onStartParams', []);
8885

89-
this.onComplete = GetValue(config, 'onComplete', false);
90-
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
86+
this.onRepeat = GetValue(config, 'onRepeat', false);
87+
this.onRepeatParams = GetValue(config, 'onRepeatParams', []);
9188

92-
// Global pause, effects all Game Objects using this Animation instance
93-
this.paused = false;
89+
// Called for EVERY frame of the animation.
90+
// See AnimationFrame.onUpdate for a frame specific callback.
91+
this.onUpdate = GetValue(config, 'onUpdate', false);
92+
this.onUpdateParams = GetValue(config, 'onUpdateParams', []);
9493

95-
this.manager.events.on('PAUSE_ALL_ANIMATION_EVENT', this.pause.bind(this));
96-
this.manager.events.on('RESUME_ALL_ANIMATION_EVENT', this.resume.bind(this));
97-
};
94+
this.onComplete = GetValue(config, 'onComplete', false);
95+
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
9896

99-
Animation.prototype.constructor = Animation;
97+
// Global pause, effects all Game Objects using this Animation instance
98+
this.paused = false;
10099

101-
Animation.prototype = {
100+
this.manager.events.on('PAUSE_ALL_ANIMATION_EVENT', this.pause.bind(this));
101+
this.manager.events.on('RESUME_ALL_ANIMATION_EVENT', this.resume.bind(this));
102+
},
102103

103104
addFrame: require('./AddFrame'),
104105
addFrameAt: require('./AddFrameAt'),
@@ -131,6 +132,7 @@ Animation.prototype = {
131132
{
132133

133134
}
134-
};
135+
136+
});
135137

136138
module.exports = Animation;

v3/src/animation/manager/AnimationManager.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7-
var Map = require('../../structs/Map');
7+
var Class = require('../../utils/Class');
88
var Components = require('./components/');
99
var EventDispatcher = require('../../events/EventDispatcher');
10-
var Event = require('./events');
10+
var Map = require('../../structs/Map');
1111

1212
/**
1313
* Animations are managed by the global AnimationManager. This is a singleton class that is
@@ -20,24 +20,24 @@ var Event = require('./events');
2020
* @class Phaser.AnimationManager
2121
* @constructor
2222
*/
23-
var AnimationManager = function (game)
24-
{
25-
this.game = game;
23+
var AnimationManager = new Class({
2624

27-
this.textureManager = null;
25+
initialize:
2826

29-
this.events = new EventDispatcher();
27+
function AnimationManager (game)
28+
{
29+
this.game = game;
3030

31-
this.globalTimeScale = 1;
31+
this.textureManager = null;
3232

33-
this.anims = new Map();
33+
this.events = new EventDispatcher();
3434

35-
this.paused = false;
36-
};
35+
this.globalTimeScale = 1;
3736

38-
AnimationManager.prototype.constructor = AnimationManager;
37+
this.anims = new Map();
3938

40-
AnimationManager.prototype = {
39+
this.paused = false;
40+
},
4141

4242
boot: function (textureManager)
4343
{
@@ -62,6 +62,7 @@ AnimationManager.prototype = {
6262
{
6363
// TODO
6464
}
65-
};
65+
66+
});
6667

6768
module.exports = AnimationManager;

0 commit comments

Comments
 (0)