mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
New: You'll now find a complete Basic project Template in the resources/Project Templates folder. Will add more complex ones soon.
This commit is contained in:
@@ -39,8 +39,12 @@ Change Log
|
||||
|
||||
Version 1.1.2
|
||||
|
||||
* New: You'll now find a complete Basic project Template in the resources/Project Templates folder. Will add more complex ones soon.
|
||||
* Fixed issue 135 - Added typeof checks into most ArcadePhysics functions to avoid errors with zero values.
|
||||
* Fixed issue 136 - distanceTo using worldX/Y instead of x/y.
|
||||
* Added init method to plugins, to be called as they are added to the PluginManager (thanks beeglebug)
|
||||
* If you pause an Animation, when you next play it it'll resume (un-pause itself).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
BasicGame.Boot = function (game) {
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Boot.prototype = {
|
||||
|
||||
preload: function () {
|
||||
|
||||
// Here we load the assets required for our preloader (in this case a background and a loading bar)
|
||||
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
|
||||
this.load.image('preloaderBar', 'images/preloadr_bar.png');
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
|
||||
this.game.input.maxPointers = 1;
|
||||
|
||||
// Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:
|
||||
this.game.stage.disableVisibilityChange = true;
|
||||
|
||||
if (this.game.device.desktop)
|
||||
{
|
||||
// If you have any desktop specific settings, they can go in here
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Same goes for mobile settings.
|
||||
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
|
||||
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
|
||||
this.game.stage.scale.minWidth = 480;
|
||||
this.game.stage.scale.minHeight = 260;
|
||||
this.game.stage.scale.maxWidth = 1024;
|
||||
this.game.stage.scale.maxHeight = 768;
|
||||
this.game.stage.scale.forceLandscape = true;
|
||||
this.game.stage.scale.pageAlignHorizontally = true;
|
||||
this.game.stage.scale.setScreenSize(true);
|
||||
}
|
||||
|
||||
// By this point the preloader assets have loaded to the cache, we've set the game settings
|
||||
// So now let's start the real preloader going
|
||||
this.game.state.start('Preloader');
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
BasicGame.Game = function (game) {
|
||||
|
||||
// Honestly, just about anything could go here.
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Game.prototype = {
|
||||
|
||||
create: function () {
|
||||
|
||||
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
|
||||
|
||||
},
|
||||
|
||||
quitGame: function (pointer) {
|
||||
|
||||
// Here you should destroy anything you no longer need.
|
||||
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
|
||||
|
||||
// Then let's go back to the main menu.
|
||||
this.game.state.start('MainMenu');
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
BasicGame.MainMenu = function (game) {
|
||||
|
||||
this.music = null;
|
||||
this.playButton = null;
|
||||
|
||||
};
|
||||
|
||||
BasicGame.MainMenu.prototype = {
|
||||
|
||||
create: function () {
|
||||
|
||||
// We've already preloaded our assets, so let's kick right into the Main Menu itself
|
||||
// Here all we're doing is playing some music and adding a picture and button
|
||||
// Naturally I expect you to do something significantly better :)
|
||||
|
||||
this.music = this.add.audio('titleMusic');
|
||||
this.music.play();
|
||||
|
||||
this.add.sprite(0, 0, 'titlepage');
|
||||
|
||||
this.playButton = this.add.button(400, 600, 'playButton', this.startGame, this, 'buttonOver', 'buttonOut', 'buttonOver');
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
// Do some nice funky main menu effect here
|
||||
|
||||
},
|
||||
|
||||
startGame: function (pointer) {
|
||||
|
||||
// Ok, the Play Button has been clicked or touched, so let's stop the music (otherwise it'll carry on playing)
|
||||
this.music.stop();
|
||||
|
||||
// And start the actual game
|
||||
this.game.state.start('Game');
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
|
||||
BasicGame.Preloader = function (game) {
|
||||
|
||||
this.background = null;
|
||||
this.preloadBar = null;
|
||||
|
||||
this.ready = false;
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Preloader.prototype = {
|
||||
|
||||
preload: function () {
|
||||
|
||||
// These are the assets we loaded in Boot.js
|
||||
// A nice sparkly background and a loading progress bar
|
||||
this.background = this.add.sprite(0, 0, 'preloaderBackground');
|
||||
this.preloadBar = this.add.sprite(300, 400, 'preloaderBar');
|
||||
|
||||
// This sets the preloadBar sprite as a loader sprite, basically
|
||||
// what that does is automatically crop the sprite from 0 to full-width
|
||||
// as the files below are loaded in.
|
||||
this.load.setPreloadSprite(this.preloadBar);
|
||||
|
||||
// Here we load most of the assets our game needs
|
||||
this.load.image('titlepage', 'images/title.jpg');
|
||||
this.load.atlas('playButton', 'images/play_button.png', 'images/play_button.json');
|
||||
this.load.audio('titleMusic', ['audio/main_menu.mp3']);
|
||||
this.load.bitmapFont('caslon', 'fonts/caslon.png', 'fonts/caslon.xml');
|
||||
// + lots of other required assets here
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
// Once the load has finished we disable the crop because we're going to sit in the update loop for a short while
|
||||
this.preloadBar.cropEnabled = false;
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
// You don't actually need to do this, but I find it gives a much smoother game experience.
|
||||
// Basically it will wait for our audio file to be decoded before proceeding to the MainMenu.
|
||||
// You can jump right into the menu if you want and still play the music, but you'll have a few
|
||||
// seconds of delay while the mp3 decodes - so if you need your music to be in-sync with your menu
|
||||
// it's best to wait for it to decode here first, then carry on.
|
||||
|
||||
// If you don't have any music in your game then put the game.state.start line into the create function and delete
|
||||
// the update function completely.
|
||||
|
||||
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
|
||||
{
|
||||
this.ready = false;
|
||||
this.game.state.start('MainMenu');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Phaser Basic Project Template</title>
|
||||
<script src="Boot.js"></script>
|
||||
<script src="Preloader.js"></script>
|
||||
<script src="MainMenu.js"></script>
|
||||
<script src="Game.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="gameContainer"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
window.onload = function() {
|
||||
|
||||
// Create your Phaser game and inject it into the gameContainer div.
|
||||
// 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)
|
||||
var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'gameContainer');
|
||||
|
||||
// Add the States your game has.
|
||||
// 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.
|
||||
game.state.add('Boot', BasicGame.Boot);
|
||||
game.state.add('Preloader', BasicGame.Preloader);
|
||||
game.state.add('MainMenu', BasicGame.MainMenu);
|
||||
game.state.add('Game', BasicGame.Game);
|
||||
|
||||
// Now start the Boot state.
|
||||
game.state.start('Boot');
|
||||
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -151,6 +151,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this.paused = false;
|
||||
|
||||
this._timeLastFrame = this.game.time.now;
|
||||
this._timeNextFrame = this.game.time.now + this.delay;
|
||||
@@ -179,6 +180,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this.paused = false;
|
||||
|
||||
this._timeLastFrame = this.game.time.now;
|
||||
this._timeNextFrame = this.game.time.now + this.delay;
|
||||
@@ -202,6 +204,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this.paused = false;
|
||||
|
||||
if (resetFrame)
|
||||
{
|
||||
@@ -304,6 +307,7 @@ Phaser.Animation.prototype = {
|
||||
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this.paused = false;
|
||||
|
||||
if (this._parent.events)
|
||||
{
|
||||
|
||||
@@ -192,12 +192,14 @@ Phaser.AnimationManager.prototype = {
|
||||
{
|
||||
if (this.currentAnim.isPlaying == false)
|
||||
{
|
||||
this.currentAnim.paused = false;
|
||||
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentAnim.paused = false;
|
||||
return this.currentAnim.play(frameRate, loop, killOnComplete);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -298,9 +298,10 @@ Phaser.Tween.prototype = {
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
this._manager.remove(this);
|
||||
this.isRunning = false;
|
||||
|
||||
this._manager.remove(this);
|
||||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user