phaser/resources/tutorials/02 Making your first game/part4.html

70 lines
1.7 KiB
HTML
Raw Normal View History

2013-12-07 02:05:07 +00:00
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
2013-12-10 16:31:54 +00:00
<title>Phaser - Making your first game, part 4</title>
2013-12-07 02:05:07 +00:00
<script type="text/javascript" src="js/phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('sky', 'assets/sky.png');
game.load.image('ground', 'assets/platform.png');
game.load.image('star', 'assets/star.png');
game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
}
var platforms;
function create() {
2014-03-24 23:38:52 +00:00
// We're going to be using physics, so enable the Arcade Physics system
game.physics.startSystem(Phaser.Physics.ARCADE);
2013-12-07 02:05:07 +00:00
// A simple background for our game
game.add.sprite(0, 0, 'sky');
// The platforms group contains the ground and the 2 ledges we can jump on
platforms = game.add.group();
2014-03-24 23:38:52 +00:00
// We will enable physics for any object that is created in this group
platforms.enableBody = true;
2013-12-07 02:05:07 +00:00
// Here we create the ground.
var ground = platforms.create(0, game.world.height - 64, 'ground');
// Scale it to fit the width of the game (the original sprite is 400x32 in size)
ground.scale.setTo(2, 2);
// This stops it from falling away when you jump on it
ground.body.immovable = true;
// Now let's create two ledges
var ledge = platforms.create(400, 400, 'ground');
2014-03-24 23:38:52 +00:00
2013-12-07 02:05:07 +00:00
ledge.body.immovable = true;
ledge = platforms.create(-150, 250, 'ground');
2014-03-24 23:38:52 +00:00
2013-12-07 02:05:07 +00:00
ledge.body.immovable = true;
}
function update() {
}
</script>
</body>
</html>