Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class Level extends Phaser.Scene{
- constructor(){
- super({key:"Level"});
- }
- preload(){
- this.load.image('background', 'assets/backgrounds.png');
- this.load.image('player', 'assets/player.png');
- }
- create(){
- this.background = this.add.tileSprite(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5 , 'background').setOrigin(0,0);
- this.cameras.main.setBounds(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5);
- this.physics.world.setBounds(0, 0, this.sys.game.config.width, this.sys.game.config.height * 5);
- this.player = this.physics.add.sprite(this.sys.game.config.width/2, 490, 'player');
- this.player.setCollideWorldBounds(true);
- this.cameras.main.startFollow(this.player, false);
- }
- update(){
- this.pointer = this.input.activePointer;
- if (this.pointer.isDown){
- this.physics.moveToObject(this.player, this.pointer, 300);
- if(this.pointer.x < this.player.x){
- this.player.flipX = true;
- } else {
- this.player.flipX = false;
- }
- } else{
- this.player.setVelocity(0,0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment