Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var game = new Phaser.Game
- (
- window.innerWidth * 1 ,
- window.innerHeight * 1 ,
- Phaser.AUTO,
- 'phaser-example', { preload: preload, create: create, update: update, render: render }
- );
- function preload() {
- game.stage.smoothed = false;
- game.load.tilemap('map', 'maps/mapaaa.json', null, Phaser.Tilemap.TILED_JSON);
- game.load.image( 'gardening_ground', 'maps/smaller.png');
- game.load.image( 'spr_fieltro', 'img/fieltro.png');
- }
- var map;
- var layer;
- var cursors;
- var sprite;
- var gameWorld;
- var jumpTimer = 0;
- var jumpButton;
- function create()
- {
- game.stage.backgroundColor = "#4488AA";
- map = game.add.tilemap('map');
- map.addTilesetImage('gardening_ground');
- layer = map.createLayer('Tile Layer 1');
- map.setCollisionBetween(0, 50);
- layer.fixedToCamera = false;
- layer.position.set(0, 0);
- layer.setScale(5);
- layer.debug = true;
- sprite = game.add.sprite(0, -50, 'spr_fieltro');
- sprite.scale.setTo(5, 5);
- game.physics.enable(sprite);
- game.physics.arcade.gravity.y = 1000;
- sprite.body.collideWorldBounds = true;
- cursors = game.input.keyboard.createCursorKeys();
- jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
- game.camera.follow(sprite);
- game.world.setBounds(0, 0, 20000, 20000);
- }
- function update()
- {
- game.physics.arcade.collide(sprite, layer);
- sprite.body.velocity.x = 0;
- if (cursors.left.isDown){ sprite.body.velocity.x = -250;}
- else if (cursors.right.isDown){sprite.body.velocity.x = 250;}
- if (jumpButton.isDown && sprite.body.onFloor() && game.time.now > jumpTimer)
- {sprite.body.velocity.y = -750;jumpTimer = game.time.now + 750;}
- }
- function render()
- {
- game.debug.body(sprite);
- }
Advertisement
Add Comment
Please, Sign In to add comment