Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var game = new Phaser.Game(640, 640, Phaser.CANVAS, '', { preload: preload, create: create, update: update });
- function preload() {
- game.load.tilemap('map', 'Assets/Tilemaps/newSnow.json', null, Phaser.Tilemap.TILED_JSON);
- game.load.image('tileset', 'Assets/Tilemaps/snowTiles.png');
- game.load.image('penguin', 'Assets/penguin.jpg');
- var map;
- var tileset;
- var penguin;
- var Background;
- var Foreground;
- }
- function create() {
- map = game.add.tilemap('map');
- map.addTilesetImage('Snow1', 'tileset');
- // map.addTilesetImage('Foreground', 'tileset');
- // map.setCollision([29], true);
- Background = map.createLayer('Background');
- Foreground = map.createLayer('Foreground');
- map.setCollisionBetween(1, 100, true, Foreground);
- Background.resizeWorld();
- //game.add.sprite(0, 0, 'background');
- game.stage.backgroundColor = '#71c5cf';
- player = game.add.sprite(0, 0, 'penguin');
- player.anchor.setTo(0.5, 0.5);
- game.physics.enable(player, Phaser.Physics.ARCADE);
- player.body.collideWorldBounds = true;
- cursors = game.input.keyboard.createCursorKeys();
- }
- function update() {
- var dirMove = 3;
- if (cursors.left.isDown)
- {
- player.body.x -= dirMove;
- }
- else if (cursors.right.isDown)
- {
- player.body.x += dirMove;
- }
- else if (cursors.up.isDown)
- {
- player.body.y -= dirMove;
- }
- else if (cursors.down.isDown)
- {
- //ycoord += 50;
- player.body.y += dirMove;
- }
- else
- {
- player.animations.stop();
- }
- game.physics.arcade.collide(player, Foreground);
- }
Advertisement
Add Comment
Please, Sign In to add comment