Jump to content

Player class not rendering


Skrskr707
 Share

Recommended Posts

Hello, im creating a game with ES6 classes and im stuck att creating an instance of a player in the firstLevel.. I have one class for Player, one class for firstLevel and one config script.

This is the code for creating the level and creating a instance to the player. When i console log this.game.scene i can see that the player has been added to the scene, but just wont render itself..

When i did the exact same thing in the config file i could render the Player, but i need to create the instance in the level to be able to access its properties.

import Player from './player.js';

class firstLevel extends Phaser.Scene {
    constructor() {
        super({ key: "firstLevel"})  
     }
    preload() {
        this.load.tilemapTiledJSON("level", "./assets/levels/level-1.json");
        this.load.image("tiles", "./assets/levels/terrain_atlas.png");
    }

    create() {
        let map = this.make.tilemap({key: 'level'});
        let terrain = map.addTilesetImage("terrain_atlas", "tiles");
        map.createLayer("Grass", terrain).setDepth(-1);
        map.createLayer("Walls", terrain).setDepth(-1);
        map.createLayer("Small flowers", terrain).setDepth(-1);
        map.createLayer("Entrance", terrain).setDepth(-1);


//instance of player
        var player1 = new Player();
        this.game.scene.add("Player", player1);
        console.log(this.game.scene);
    }
    update() {}
}
export default firstLevel;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...