It seems to me a common misunderstanding here is scope, and I am no exception, but no other thread is helping me understand…
I have the following:
var tileGroup;
class GameScene extends Phaser.Scene {
constructor() {
super('GameScene')
}
preload () {
//GAME ASSETS, ETC, PULLING DATA FROM spawnTiles WORKS FINE WHEN ASSET HERE:
this.load.spritesheet('grasssprite', '../assets/terrain/grassworld/grasssprite.png', {frameWidth: 128, frameHeight: 128 });
}
create () {
this.spawnTiles();
console.log(tileGroup);
spawnTiles (tileGroup) {
var tileGroup = this.add.group();
x=18; //ARBITRARY X Y VALUES FOR EXAMPLE SAKE
y=18;
thisTile = this.add.sprite(x, y, 'grasssprite',1);
tileGroup.add(thisTile);
}
}
My tiles render fine and everything else works in terms of game functionality, but the console.log(tileGroup) here gives ‘undefined’