Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Scene1 extends Phaser.Scene {
- constructor() {
- super("Scene1");
- }
- _create() {
- this.map = this.add.tilemap("map");
- this.tileset = this.map.addTilesetImage("GreyTransperant");
- this.rocks = this.map.createStaticLayer("Rock", this.tileset);
- this.collisions = this.map.createStaticLayer("Collisions", this.tileset);
- this.collisions.setCollisionByExclusion(-1);
- this.map.createFromTiles([-1], null, this.objects, this, this.cameras.main,"FunnyHitBox");
- this.player = this.physics.add.sprite(260, 302, "player");
- this.cameras.main.centerOn(this.player.x, this.player.y);
- this.physics.add.collider(this.player, this.collisions, null, null, this);
- this.space_bar = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE);
- this.left = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
- this.right = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
- this.up = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.UP);
- this.down = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.DOWN);
- }
- create() {
- this._create();
- }
- update() {
- this.cameras.main.centerOn(this.player.x, this.player.y, this.setCollisions);
- if (this.left.isDown) {
- this.player.body.velocity.x = -200;
- } else if (this.right.isDown) {
- this.player.body.velocity.x = 200;
- } else {
- this.player.body.velocity.x = 0;
- }
- if (this.up.isDown) {
- this.player.body.velocity.y = -200;
- }
- } //update end
- } //scene1 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement