Skip to content

Commit

Permalink
added example project
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Aug 22, 2021
1 parent ef409c0 commit b5fcbec
Show file tree
Hide file tree
Showing 9 changed files with 3,727 additions and 171 deletions.
File renamed without changes.
19 changes: 19 additions & 0 deletions config/bs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Browser sync configuration file for the example project
module.exports = {
server: ['./example'],
serveStatic: [
{
route: '/js',
dir: [
'./dist',
'./node_modules/phaser-ce/build'
],
},
],
files: [
'./dist/index.js',
'./example/**/*'
],
ghostMode: false,
open: false,
};
Binary file added example/assets/sprites/mushroom2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/sprites/phaser1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/sprites/sonic_havok_sanity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions example/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game', { preload: preload, create: create, update: update, render: render });

function preload() {
game.stage.backgroundColor = '#007236';
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png');
game.load.image('phaser', 'assets/sprites/phaser1.png');
}

var cursors;
var logo1;
var logo2;

function create() {
// game.plugins.add(new PhaserRuntimeEditor(game, game.root));
// Modify the world and camera bounds
game.world.setBounds(-1000, -1000, 2000, 2000);

for (var i = 0; i < 200; i++) {
game.add.sprite(game.world.randomX, game.world.randomY, 'mushroom');
}

game.add.text(0, 0, 'this text scrolls\nwith the background', { font: '32px Arial', fill: '#f26c4f', align: 'center' });

logo1 = game.add.sprite(0, 0, 'phaser');
logo1.fixedToCamera = true;
logo1.cameraOffset.setTo(100, 100);

logo2 = game.add.sprite(0, 0, 'phaser');
logo2.fixedToCamera = true;
logo2.cameraOffset.setTo(500, 100);

var t = game.add.text(0, 0, 'this text is fixed to the camera', { font: '32px Arial', fill: '#ffffff', align: 'center' });
t.fixedToCamera = true;
t.cameraOffset.setTo(200, 500);

game.add.tween(logo2.cameraOffset).to({ y: 400 }, 2000, Phaser.Easing.Back.InOut, true, 0, 2000, true);
cursors = game.input.keyboard.createCursorKeys();
}

function update() {
if (cursors.up.isDown) game.camera.y -= 4;
else if (cursors.down.isDown) game.camera.y += 4;

if (cursors.left.isDown) game.camera.x -= 4;
else if (cursors.right.isDown) game.camera.x += 4;
}

function render() {
game.debug.cameraInfo(game.camera, 32, 32);
}
15 changes: 15 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Example</title>
<script src="/js/phaser.js"></script>
<script src="/js/index.js"></script>
</head>
<body>
<div id="game"></div>
<script src="./game.js"></script>
</body>
</html>
Loading

0 comments on commit b5fcbec

Please sign in to comment.