Skrskr707 Posted February 15, 2021 Share Posted February 15, 2021 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.