Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2016 04:19
Show Gist options
  • Save videlais/bb2c53d4c990e45dc35e to your computer and use it in GitHub Desktop.
Save videlais/bb2c53d4c990e45dc35e to your computer and use it in GitHub Desktop.
Create description of BasicPlatformer
function create() {
// Make the background color of the game's stage be white (#FFFFFF)
game.stage.backgroundColor = '#FFFFFF';
// Start the physics system ARCADE
// Add the tilemap 'map' to the game
map = game.add.tilemap('map');
// Add the tileset image 'level' to the map
// (The name must match both an image in Phaser's cache
// and the name of an image withi the 'map.json'
// list of tilesets too.)
// Create a layer from the 'map.json' file
// based on 'Tile Layer 1' from the available tiles.
layer = map.createLayer('Tile Layer 1');
// Set the collision range
// Here, the range is from 1 (the first tile) to the fifth (last tile).
map.setCollisionBetween(1, 5);
// Tell the layer to resize the game 'world' to match its size
// Create and add a sprite to the game at the position (2*48 x 6 *48)
// and using, in this case, the spritesheet 'character'
player = game.add.sprite(2 * 48, 6 * 48, 'character');
// By default, sprites do not have a physics 'body'
// Before we can adjust its physics properties,
// we need to add a 'body' by enabling
// (As a second argument, we can specify the
// physics system to use too. However, since we
// started the Arcade system already, it will
// default to that.)
// Set the amount of bounce on the physics body of the 'player' sprite
player.body.bounce.y = 0.1;
// Set the amount of gravity to apply to the physics body of the 'player' sprite
player.body.gravity.y = 96;
// Tell the game's camera to follow the 'player' sprite;
// Have the game create cursor keys (usually arrow keys)
// and save the reference to 'cursors'
cursors = game.input.keyboard.createCursorKeys();
// Add a specifically named key to the input checked for.
// In this case, it is the Keyboard.SPACEBAR
jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment