Well, it didn’t work. I got this error:
phaser.min.js:1 Uncaught TypeError: Cannot read property 'sprite' of undefined
at Object.t.exports [as CreateFromTiles] (phaser.min.js:1)
at initialize.createFromTiles (phaser.min.js:1)
at initialize.create (game.js:71)
at initialize.create (phaser.min.js:1)
at initialize.loadComplete (phaser.min.js:1)
at initialize.h.emit (phaser.min.js:1)
at initialize.loadComplete (phaser.min.js:1)
at initialize.fileProcessComplete (phaser.min.js:1)
at initialize.onProcessComplete (phaser.min.js:1)
at AudioContext.config.context (phaser.min.js:1)
t.exports @ phaser.min.js:1
createFromTiles @ phaser.min.js:1
create @ game.js:71
create @ phaser.min.js:1
loadComplete @ phaser.min.js:1
h.emit @ phaser.min.js:1
loadComplete @ phaser.min.js:1
fileProcessComplete @ phaser.min.js:1
onProcessComplete @ phaser.min.js:1
config.context @ phaser.min.js:1
also, when I run questionMarkBricks in the console, I get returned undefined.
I’ll just put the relevant part of my code here in hopes that my error will be spotted:
const config = {
type: Phaser.AUTO, // Which renderer to use
width: 350, // Canvas width in pixels
height: 208, // Canvas height in pixels
//zoom: 2, // Since we're working with 16x16 pixel tiles
pixelArt: true, // Force the game to scale images up crisply
parent: "game_container", // ID of the DOM element to add the canvas to
scale: {
parent: 'game_container',
mode: Phaser.Scale.CENTER_BOTH,
width: 350,
height: 208
},
scene: {
preload: preload,
create: create,
update: update
},
physics: {
default: "arcade",
arcade: {
gravity: { y: 500 },
debug: false
}
}
};
const game = new Phaser.Game(config);
var controls, map, tiles, marioTileset, layer, player, goombas, goomba1, goomba2, themeMusic, marioDiesSound, coinCollectedSound, soundButton, groundLayer, graphicsLayer, coinLayer, coinTiles, questionMarkBricks;
var score = 0;
var soundsOn = true;
var playerDead = false;
function preload() {
// Runs once, loads up assets like images and audio
this.load.spritesheet('smallMario', './assets/sprites/sprites-mario-small.png', { frameWidth: 16, frameHeight: 16, endFrame: 14, spacing: 1 });
this.load.spritesheet('big-mario', './assets/sprites/sprites-mario-big.png', { frameWidth: 16, frameHeight: 32, endFrame: 21, spacing: 1 });
this.load.spritesheet('coin', './assets/sprites/coin.png', { frameWidth: 16, frameHeight: 32, endFrame: 21, spacing: 1 });
this.load.spritesheet('goomba', './assets/sprites/goombas.png', { frameWidth: 16, frameHeight: 16, endFrame: 2 });
this.load.spritesheet('soundButton', './assets/speaker_icon.png', { frameWidth: 16, frameHeight: 16, endFrame: 1 });
this.load.image("mario-tiles", "./assets/NES-Super-Mario-Bros-Tileset.png");
this.load.tilemapTiledJSON("Levelmap", "./tilemaps/mario-level-1-v2.json");
this.load.bitmapFont('superMarioFont', './assets/fonts/supermario_0.png', './assets/fonts/supermario.fnt');
}
function create() {
// Runs once, after all assets in preload are loaded
// Load and assign Tilemap variables
map = this.make.tilemap({ key: "Levelmap" });
tiles = map.addTilesetImage("NES_Super_Mario", "mario-tiles");
layer = map.createStaticLayer(0, tiles, 0, 0); // layer index, tileset, x, y
coinTiles = map.addTilesetImage('coin');
groundLayer = map.createStaticLayer('Ground', tiles, 0, 0);
graphicsLayer = map.createStaticLayer('Graphics', tiles, 0, 0);
coinLayer = map.createDynamicLayer('Coins', coinTiles, 0, 0);
questionMarkBricksLayer = map.createStaticLayer('QuestionBricks', tiles, 0, 0);
// tiles.firstgid equals 1
questionMarkBricks = map.createFromTiles(tiles.firstgid+24, null, {key: 'questionMarkBrick', frame: 0}, this.scene, this.cameras.main, questionMarkBricksLayer);
// questionMarkBricks equals undefined
// There is more code in my create function after this but I don't believe it is relevant.
}
Thanks again for the help!