Skip to content

Commit 7ceb11a

Browse files
committed
New: You'll now find a complete Basic project Template in the resources/Project Templates folder. Will add more complex ones soon.
1 parent 2b40d2f commit 7ceb11a

9 files changed

Lines changed: 231 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ Change Log
3939

4040
Version 1.1.2
4141

42+
* New: You'll now find a complete Basic project Template in the resources/Project Templates folder. Will add more complex ones soon.
4243
* Fixed issue 135 - Added typeof checks into most ArcadePhysics functions to avoid errors with zero values.
4344
* Fixed issue 136 - distanceTo using worldX/Y instead of x/y.
45+
* Added init method to plugins, to be called as they are added to the PluginManager (thanks beeglebug)
46+
* If you pause an Animation, when you next play it it'll resume (un-pause itself).
47+
4448

4549

4650

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
BasicGame.Boot = function (game) {
3+
4+
};
5+
6+
BasicGame.Boot.prototype = {
7+
8+
preload: function () {
9+
10+
// Here we load the assets required for our preloader (in this case a background and a loading bar)
11+
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
12+
this.load.image('preloaderBar', 'images/preloadr_bar.png');
13+
14+
},
15+
16+
create: function () {
17+
18+
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
19+
this.game.input.maxPointers = 1;
20+
21+
// Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:
22+
this.game.stage.disableVisibilityChange = true;
23+
24+
if (this.game.device.desktop)
25+
{
26+
// If you have any desktop specific settings, they can go in here
27+
this.game.stage.scale.pageAlignHorizontally = true;
28+
}
29+
else
30+
{
31+
// Same goes for mobile settings.
32+
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
33+
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
34+
this.game.stage.scale.minWidth = 480;
35+
this.game.stage.scale.minHeight = 260;
36+
this.game.stage.scale.maxWidth = 1024;
37+
this.game.stage.scale.maxHeight = 768;
38+
this.game.stage.scale.forceLandscape = true;
39+
this.game.stage.scale.pageAlignHorizontally = true;
40+
this.game.stage.scale.setScreenSize(true);
41+
}
42+
43+
// By this point the preloader assets have loaded to the cache, we've set the game settings
44+
// So now let's start the real preloader going
45+
this.game.state.start('Preloader');
46+
47+
}
48+
49+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BasicGame.Game = function (game) {
2+
3+
// Honestly, just about anything could go here.
4+
5+
};
6+
7+
BasicGame.Game.prototype = {
8+
9+
create: function () {
10+
11+
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
12+
13+
},
14+
15+
update: function () {
16+
17+
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
18+
19+
},
20+
21+
quitGame: function (pointer) {
22+
23+
// Here you should destroy anything you no longer need.
24+
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
25+
26+
// Then let's go back to the main menu.
27+
this.game.state.start('MainMenu');
28+
29+
}
30+
31+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
BasicGame.MainMenu = function (game) {
2+
3+
this.music = null;
4+
this.playButton = null;
5+
6+
};
7+
8+
BasicGame.MainMenu.prototype = {
9+
10+
create: function () {
11+
12+
// We've already preloaded our assets, so let's kick right into the Main Menu itself
13+
// Here all we're doing is playing some music and adding a picture and button
14+
// Naturally I expect you to do something significantly better :)
15+
16+
this.music = this.add.audio('titleMusic');
17+
this.music.play();
18+
19+
this.add.sprite(0, 0, 'titlepage');
20+
21+
this.playButton = this.add.button(400, 600, 'playButton', this.startGame, this, 'buttonOver', 'buttonOut', 'buttonOver');
22+
23+
},
24+
25+
update: function () {
26+
27+
// Do some nice funky main menu effect here
28+
29+
},
30+
31+
startGame: function (pointer) {
32+
33+
// Ok, the Play Button has been clicked or touched, so let's stop the music (otherwise it'll carry on playing)
34+
this.music.stop();
35+
36+
// And start the actual game
37+
this.game.state.start('Game');
38+
39+
}
40+
41+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
BasicGame.Preloader = function (game) {
3+
4+
this.background = null;
5+
this.preloadBar = null;
6+
7+
this.ready = false;
8+
9+
};
10+
11+
BasicGame.Preloader.prototype = {
12+
13+
preload: function () {
14+
15+
// These are the assets we loaded in Boot.js
16+
// A nice sparkly background and a loading progress bar
17+
this.background = this.add.sprite(0, 0, 'preloaderBackground');
18+
this.preloadBar = this.add.sprite(300, 400, 'preloaderBar');
19+
20+
// This sets the preloadBar sprite as a loader sprite, basically
21+
// what that does is automatically crop the sprite from 0 to full-width
22+
// as the files below are loaded in.
23+
this.load.setPreloadSprite(this.preloadBar);
24+
25+
// Here we load most of the assets our game needs
26+
this.load.image('titlepage', 'images/title.jpg');
27+
this.load.atlas('playButton', 'images/play_button.png', 'images/play_button.json');
28+
this.load.audio('titleMusic', ['audio/main_menu.mp3']);
29+
this.load.bitmapFont('caslon', 'fonts/caslon.png', 'fonts/caslon.xml');
30+
// + lots of other required assets here
31+
32+
},
33+
34+
create: function () {
35+
36+
// Once the load has finished we disable the crop because we're going to sit in the update loop for a short while
37+
this.preloadBar.cropEnabled = false;
38+
39+
},
40+
41+
update: function () {
42+
43+
// You don't actually need to do this, but I find it gives a much smoother game experience.
44+
// Basically it will wait for our audio file to be decoded before proceeding to the MainMenu.
45+
// You can jump right into the menu if you want and still play the music, but you'll have a few
46+
// seconds of delay while the mp3 decodes - so if you need your music to be in-sync with your menu
47+
// it's best to wait for it to decode here first, then carry on.
48+
49+
// If you don't have any music in your game then put the game.state.start line into the create function and delete
50+
// the update function completely.
51+
52+
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
53+
{
54+
this.ready = false;
55+
this.game.state.start('MainMenu');
56+
}
57+
58+
}
59+
60+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Phaser Basic Project Template</title>
6+
<script src="Boot.js"></script>
7+
<script src="Preloader.js"></script>
8+
<script src="MainMenu.js"></script>
9+
<script src="Game.js"></script>
10+
</head>
11+
<body>
12+
13+
<div id="gameContainer"></div>
14+
15+
<script type="text/javascript">
16+
17+
window.onload = function() {
18+
19+
// Create your Phaser game and inject it into the gameContainer div.
20+
// We did it in a window.onload event, but you can do it anywhere (requireJS load, anonymous function, jQuery dom ready, etc - whatever floats your boat)
21+
var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'gameContainer');
22+
23+
// Add the States your game has.
24+
// You don't have to do this in the html, it could be done in your Boot state too, but for simplicity I'll keep it here.
25+
game.state.add('Boot', BasicGame.Boot);
26+
game.state.add('Preloader', BasicGame.Preloader);
27+
game.state.add('MainMenu', BasicGame.MainMenu);
28+
game.state.add('Game', BasicGame.Game);
29+
30+
// Now start the Boot state.
31+
game.state.start('Boot');
32+
33+
};
34+
35+
</script>
36+
37+
</body>
38+
</html>

src/animation/Animation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Phaser.Animation.prototype = {
151151

152152
this.isPlaying = true;
153153
this.isFinished = false;
154+
this.paused = false;
154155

155156
this._timeLastFrame = this.game.time.now;
156157
this._timeNextFrame = this.game.time.now + this.delay;
@@ -179,6 +180,7 @@ Phaser.Animation.prototype = {
179180

180181
this.isPlaying = true;
181182
this.isFinished = false;
183+
this.paused = false;
182184

183185
this._timeLastFrame = this.game.time.now;
184186
this._timeNextFrame = this.game.time.now + this.delay;
@@ -202,6 +204,7 @@ Phaser.Animation.prototype = {
202204

203205
this.isPlaying = false;
204206
this.isFinished = true;
207+
this.paused = false;
205208

206209
if (resetFrame)
207210
{
@@ -304,6 +307,7 @@ Phaser.Animation.prototype = {
304307

305308
this.isPlaying = false;
306309
this.isFinished = true;
310+
this.paused = false;
307311

308312
if (this._parent.events)
309313
{

src/animation/AnimationManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,14 @@ Phaser.AnimationManager.prototype = {
192192
{
193193
if (this.currentAnim.isPlaying == false)
194194
{
195+
this.currentAnim.paused = false;
195196
return this.currentAnim.play(frameRate, loop, killOnComplete);
196197
}
197198
}
198199
else
199200
{
200201
this.currentAnim = this._anims[name];
202+
this.currentAnim.paused = false;
201203
return this.currentAnim.play(frameRate, loop, killOnComplete);
202204
}
203205
}

src/tween/Tween.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ Phaser.Tween.prototype = {
298298
*/
299299
stop: function () {
300300

301-
this._manager.remove(this);
302301
this.isRunning = false;
303302

303+
this._manager.remove(this);
304+
304305
return this;
305306

306307
},

0 commit comments

Comments
 (0)