Video Snapshot Area
Demonstrates how to capture a specific rectangular region of a playing video and apply it as a texture to another Game Object.
1280 × 720
// #module
import Button from '../../libs/ui/Button.js';
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.video('spaceace', 'assets/video/spaceace.mp4', true);
this.load.atlas('ui', 'assets/ui/dark-ui.png', 'assets/ui/dark-ui.json');
}
create ()
{
const intro = this.add.video(0, 0, 'spaceace').setOrigin(0);
intro.play(true);
const grabImage = this.add.image(32, 32).setOrigin(0);
const area = this.add.rectangle(0, 0, 320, 180).setStrokeStyle(1, 0x00ff00);
this.input.on('pointermove', (pointer) => {
const x = Phaser.Math.Clamp(pointer.x, 160, 1120);
const y = Phaser.Math.Clamp(pointer.y, 90, 630);
area.setPosition(x, y);
});
this.input.on('pointerdown', (pointer) => {
const x = Phaser.Math.Clamp(pointer.x, 160, 1120);
const y = Phaser.Math.Clamp(pointer.y, 90, 630);
area.setPosition(x, y);
let snap = intro.snapshotArea(area.x - 160, area.y - 90, 320, 180);
grabImage.setTexture(snap);
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 1280,
height: 720,
antialiasGL: false,
backgroundColor: '#000000',
parent: 'game-container',
scene: Example
};
let game = new Phaser.Game(config);