Guest User

Untitled

a guest
Apr 29th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default class Level extends Phaser.Scene{
  2.   constructor(){
  3.         super({key:"Level"});
  4.       }
  5.       preload(){
  6.         this.load.image('background', 'assets/backgrounds.png');
  7.         this.load.image('player', 'assets/player.png');
  8.       }
  9.       create(){
  10.         this.background = this.add.tileSprite(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5 , 'background').setOrigin(0,0);
  11.  
  12.         this.cameras.main.setBounds(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5);
  13.         this.physics.world.setBounds(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5);
  14.  
  15.         this.player = this.physics.add.sprite(this.sys.game.config.width/2, 490, 'player');
  16.         this.player.setCollideWorldBounds(true);
  17.  
  18.         this.cameras.main.startFollow(this.player, false);
  19.  
  20.  
  21.  
  22.       }
  23.       update(){
  24.  
  25.         this.pointer = this.input.activePointer;
  26.         if (this.pointer.isDown){
  27.           this.physics.moveToObject(this.player, this.pointer, 300);
  28.           if(this.pointer.x < this.player.x){
  29.             this.player.flipX = true;
  30.           } else {
  31.             this.player.flipX = false;
  32.           }
  33.         } else{
  34.           this.player.setVelocity(0,0);
  35.         }
  36.       }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment