Okay i’m probably doing something very basic wrong but can’t get this to work.
I have a main.js that call a mainscreen.js (scene 1), a hud.js (scene 2) and some levels (all different *.js). Everything works communication between the screens, overlays etc. except for one screenshot function. I added the code below.
The errorcode for the main.js is: “game is not defined” but also when i change game to overallgame or try a line of code with this. I can’t get this to work.
All help is appreciated.
import {ScenarioHUD} from './js/Hud.js';
import {Radar} from './js/MainScreen_Radar.js';
etc etc.........
const config = {
type: Phaser.WEBGL,
width: 1920,
height: 925, //1080
backgroundColor: 'ffffff',
type: Phaser.AUTO,
dom: {
createContainer: true},
scene: [Radar, ScenarioHUD],
}
var overall_game = new Phaser.Game(config);
The code for the MainScreen_Radar.js
export class Radar extends Phaser.Scene
{
constructor()
{
super({key: 'Radar', active: true});
}
init (puzzlesolved)
{
this.puzzlesolvedID = puzzlesolved.id;
}
preload()
{
}
create()
{
........
button_screenshot.on('pointerup', function (pointer)
{
game.renderer.snapshot(function (image)
{
exportCanvasAsPNG(canvas, 'snapshot', image.src);
});
});
........
}
exportCanvasAsPNG(id, fileName, dataUrl)
{
var canvasElement = document.getElementById(id);
var MIME_TYPE = "image/png";
var imgURL = dataUrl;
var dlLink = document.createElement('a');
dlLink.download = fileName;
dlLink.href = imgURL;
dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':');
document.body.appendChild(dlLink);
dlLink.click();
document.body.removeChild(dlLink);
}