Skip to content

Commit b1b7414

Browse files
committed
New mini responsive template.
1 parent 33d9b19 commit b1b7414

5 files changed

Lines changed: 232 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var BasicGame = {};
2+
3+
BasicGame.Boot = function (game) {
4+
5+
};
6+
7+
BasicGame.Boot.prototype = {
8+
9+
init: function () {
10+
11+
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
12+
this.input.maxPointers = 1;
13+
14+
// Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:
15+
this.stage.disableVisibilityChange = true;
16+
17+
// This tells the game to resize the renderer to match the game dimensions (i.e. 100% browser width / height)
18+
this.scale.scaleMode = Phaser.ScaleManager.RESIZE;
19+
20+
},
21+
22+
preload: function () {
23+
24+
// Here we load the assets required for our preloader (in this case a background and a loading bar)
25+
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
26+
this.load.image('preloaderBar', 'images/preloadr_bar.png');
27+
28+
},
29+
30+
create: function () {
31+
32+
// By this point the preloader assets have loaded to the cache, we've set the game settings
33+
// So now let's start the real preloader going
34+
this.state.start('Preloader');
35+
36+
}
37+
38+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
BasicGame.Game = function (game) {
3+
4+
// When a State is added to Phaser it automatically has the following properties set on it, even if they already exist:
5+
6+
this.game; // a reference to the currently running game
7+
this.add; // used to add sprites, text, groups, etc
8+
this.camera; // a reference to the game camera
9+
this.cache; // the game cache
10+
this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it)
11+
this.load; // for preloading assets
12+
this.math; // lots of useful common math operations
13+
this.sound; // the sound manager - add a sound, play one, set-up markers, etc
14+
this.stage; // the game stage
15+
this.time; // the clock
16+
this.tweens; // the tween manager
17+
this.state; // the state manager
18+
this.world; // the game world
19+
this.particles; // the particle manager
20+
this.physics; // the physics manager
21+
this.rnd; // the repeatable random number generator
22+
23+
// You can use any of these from any function within this State.
24+
// But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.
25+
26+
};
27+
28+
BasicGame.Game.prototype = {
29+
30+
create: function () {
31+
32+
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
33+
34+
},
35+
36+
update: function () {
37+
38+
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
39+
40+
},
41+
42+
quitGame: function (pointer) {
43+
44+
// Here you should destroy anything you no longer need.
45+
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
46+
47+
// Then let's go back to the main menu.
48+
this.state.start('MainMenu');
49+
50+
}
51+
52+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
BasicGame.MainMenu = function (game) {
3+
4+
this.bg;
5+
this.spriteTopLeft;
6+
this.spriteTopRight;
7+
this.spriteBottomLeft;
8+
this.spriteBottomRight;
9+
10+
};
11+
12+
BasicGame.MainMenu.prototype = {
13+
14+
create: function () {
15+
16+
this.bg = this.add.tileSprite(0, 0, this.game.width, this.game.height, 'starfield');
17+
18+
this.spriteTopLeft = this.add.sprite(0, 0, 'tetris3');
19+
20+
this.spriteTopRight = this.add.sprite(game.width, 0, 'tetris1');
21+
this.spriteTopRight.anchor.set(1, 0);
22+
23+
this.spriteBottomLeft = this.add.sprite(0, game.height, 'tetris2');
24+
this.spriteBottomLeft.anchor.set(0, 1);
25+
26+
this.spriteBottomRight = this.add.sprite(game.width, game.height, 'tetris3');
27+
this.spriteBottomRight.anchor.set(1, 1);
28+
29+
},
30+
31+
update: function () {
32+
33+
// Do some nice funky main menu effect here
34+
35+
},
36+
37+
resize: function (width, height) {
38+
39+
// If the game container is resized this function will be called automatically.
40+
// You can use it to align sprites that should be fixed in place and other responsive display things.
41+
42+
this.bg.width = width;
43+
this.bg.height = height;
44+
45+
this.spriteMiddle.x = this.game.world.centerX;
46+
this.spriteMiddle.y = this.game.world.centerY;
47+
48+
this.spriteTopRight.x = this.game.width;
49+
this.spriteBottomLeft.y = this.game.height;
50+
51+
this.spriteBottomRight.x = this.game.width;
52+
this.spriteBottomRight.y = this.game.height;
53+
54+
}
55+
56+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
18+
this.background = this.add.sprite(0, 0, 'preloaderBackground');
19+
this.preloadBar = this.add.sprite(300, 400, 'preloaderBar');
20+
21+
// This sets the preloadBar sprite as a loader sprite.
22+
// What that does is automatically crop the sprite from 0 to full-width
23+
// as the files below are loaded in.
24+
25+
this.load.setPreloadSprite(this.preloadBar);
26+
27+
// Here we load the rest of the assets our game needs.
28+
// You can find all of these assets in the Phaser Examples repository
29+
30+
this.load.image('tetris1', 'assets/sprites/tetrisblock1.png');
31+
this.load.image('tetris2', 'assets/sprites/tetrisblock2.png');
32+
this.load.image('tetris3', 'assets/sprites/tetrisblock3.png');
33+
this.load.image('hotdog', 'assets/sprites/hotdog.png');
34+
this.load.image('starfield', 'assets/skies/deep-space.jpg');
35+
36+
},
37+
38+
create: function () {
39+
40+
this.state.start('MainMenu');
41+
42+
}
43+
44+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Phaser Responsive Project Template</title>
6+
<script src="phaser.min.js"></script>
7+
<script src="Boot.js"></script>
8+
<script src="Preloader.js"></script>
9+
<script src="MainMenu.js"></script>
10+
<script src="Game.js"></script>
11+
<style>
12+
body {
13+
margin: 0;
14+
padding: 0;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
20+
<script type="text/javascript">
21+
22+
window.onload = function() {
23+
24+
// 100% of the browser window - see Boot.js for additional configuration
25+
var game = new Phaser.Game("100%", "100%", Phaser.AUTO, '');
26+
27+
// Add the States your game has.
28+
// 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.
29+
game.state.add('Boot', BasicGame.Boot);
30+
game.state.add('Preloader', BasicGame.Preloader);
31+
game.state.add('MainMenu', BasicGame.MainMenu);
32+
game.state.add('Game', BasicGame.Game);
33+
34+
// Now start the Boot state.
35+
game.state.start('Boot');
36+
37+
};
38+
39+
</script>
40+
41+
</body>
42+
</html>

0 commit comments

Comments
 (0)