I’m trying to create a scene transition effect, the previous scene fades to black and the next scene will start with a camera mask using either a shape or a bitmap (whichever performs fastest). Is this possible in Phaser 3?
Basically, I’m trying to recreate the effect used in New Super Mario Bros when a level starts, see image below. Btw NSMB also does a bit transparency but ideally it should just be a black border.
I’ve tried the code below in the sandbox, but it seems a mask doesn’t have a scale
or setScale
property or method? See code below (btw is there a way to save&share sandbox code?)
var config = {
type: Phaser.WEBGL,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'phaser-example',
scene: {
preload: preload,
create: create,
update: update
}
};
var controls;
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('phaser2', 'assets/sprites/phaser2.png');
this.load.image('backdrop', 'assets/pics/platformer-backdrop.png');
this.load.image('dude', 'assets/sprites/phaser-dude.png');
this.load.bitmapFont('atari', 'assets/fonts/bitmap/atari-smooth.png', 'assets/fonts/bitmap/atari-smooth.xml');
}
function create ()
{
var bg = this.add.image(400, 300, 'backdrop').setScale(2.0, 2.0);
var dude = this.add.image(400, 300, 'dude').setScale(2.0, 2.0);
var text = this.add.bitmapText(400, 300, 'atari', '', 38).setOrigin(0.5).setCenterAlign().setInteractive();
text.setText('Mission 1\nGet ready!');
text.setText('Too bad!\nGame Over');
var shape1 = this.make.graphics().fillStyle(0x00ff00).fillCircle(400, 300, 200);
var bitmap1 = this.add.image(400, 300, 'phaser2');
var mask1 = shape1.createGeometryMask();
//var mask2 = bitmap1.createBitmapMask();
this.cameras.main.setMask(mask1);
//this.cameras.main.setMask(mask2);
this.tweens.add({
targets: mask1,
scale: 3.0,
ease: 'Sine.easeInOut',
yoyo: true,
repeat: -1,
duration: 2000
});
}
function update (time, delta)
{
// controls.update(delta);
}