Reputation: 65
I am working on a platformer style game in phaser 3 using arcade physics and Canvas graphics. At a point in my code I would like to completely restart the current scene, and I do so using this.scene.restart
. Any time I attempt this it gives me the error "Cannot read properties of null (reading 'cut')". When using WebGl graphics it gives me another error of "Cannot read properties of null (reading 'glTexture')". Any help in knowing what this means or how to fix it would be appreciated. line 59494 for WebGl and 26816 for Canvas.
Upvotes: 0
Views: 710
Reputation: 14695
If you want to "load" images before the preload
function of the scene-config, you would simply have to add the pack
property to the Scene
- config, and than you can use images in the preload
function. As seen below in the demo.
Here is the link to the documentation
In any case, I would recommend, if you use this feature, don't load too many files, before the Scene has loaded / executed the
preload
function.
document.body.style = 'margin:0;';
var config = {
type: Phaser.CANVAS,
width: 536,
height: 183,
scene: {
preload,
pack: {
files: [
{ type: 'image', key: 'logo', url: 'https://labs.phaser.io/assets/sprites/phaser1.png' }
]
}
},
banner: false
};
function preload(){
this.add.image(200, 90, 'logo').setOrigin(.5);
}
new Phaser.Game(config);
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.js"></script>
Upvotes: 0