Advertisement
Guest User

createFromTiles Code

a guest
Sep 1st, 2019
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Scene1 extends Phaser.Scene {
  2.     constructor() {
  3.         super("Scene1");
  4.     }
  5.     _create() {
  6.         this.map = this.add.tilemap("map");
  7.        
  8.         this.tileset = this.map.addTilesetImage("GreyTransperant");
  9.        
  10.         this.rocks = this.map.createStaticLayer("Rock", this.tileset);
  11.         this.collisions = this.map.createStaticLayer("Collisions", this.tileset);
  12.         this.collisions.setCollisionByExclusion(-1);
  13.  
  14.         this.map.createFromTiles([-1], null, this.objects, this, this.cameras.main,"FunnyHitBox");
  15.        
  16.         this.player = this.physics.add.sprite(260, 302, "player");
  17.         this.cameras.main.centerOn(this.player.x, this.player.y);
  18.  
  19.         this.physics.add.collider(this.player, this.collisions, null, null, this);
  20.        
  21.         this.space_bar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
  22.         this.left = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
  23.         this.right = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
  24.         this.up = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
  25.         this.down = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
  26.             }
  27.     create() {
  28.         this._create();
  29.     }
  30.     update() {
  31.         this.cameras.main.centerOn(this.player.x, this.player.y, this.setCollisions);
  32.        
  33.         if (this.left.isDown) {
  34.                 this.player.body.velocity.x = -200;
  35.             } else if (this.right.isDown) {
  36.                 this.player.body.velocity.x = 200;
  37.             } else {
  38.                 this.player.body.velocity.x = 0;
  39.             }
  40.  
  41.         if (this.up.isDown) {
  42.                 this.player.body.velocity.y = -200;
  43.         }
  44.     } //update end
  45. } //scene1 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement