ChrisF Posted November 24, 2018 Share Posted November 24, 2018 Hi, Struggling to understand this, I'm also very new here so I apologize if this is in the wrong place. Basically trying to create a group for my game icons, but the functions outside of create don't seem to have access to phaser commands (game.add.group()) var config = { type: Phaser.AUTO, width: pageWidth, height: pageHeight, scene: { preload: preload, create: create, update: update } }; var game = new Phaser.Game(config); function preload () {} function create () { createBoard(); //var icons = this.add.group(); //Works here } function createBoard() { var icons = game.add.group(); //cannot read type "group" of undefined. game is recognized at this point } Link to comment Share on other sites More sharing options...
mapacarta Posted November 26, 2018 Share Posted November 26, 2018 In phaser 3, game.add doesn't refer to object factory (it is undefined actually). Instead you should use this.add (this refer to scene) Something like this should work: var config = { type: Phaser.AUTO, width: pageWidth, height: pageHeight, scene: { preload: preload, create: create, update: update } }; var game = new Phaser.Game(config); function preload () {} function create () { createBoard.call(this); //var icons = this.add.group(); //Works here } function createBoard() { var icons = this.add.group(); } ChrisF 1 Link to comment Share on other sites More sharing options...
ChrisF Posted November 26, 2018 Author Share Posted November 26, 2018 Thank you, that makes sense and works perfectly. Very much appreciated! mapacarta 1 Link to comment Share on other sites More sharing options...
Recommended Posts