class Example extends Phaser.Scene { constructor () { super(); } preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v355'); this.load.image('bg', 'assets/skies/gradient13.png'); this.load.image('ayu', 'assets/pics/ayu.png'); } create () { this.add.image(400, 300, 'bg').setFlip(false, true); const vertices = [ -1, 1, 1, 1, -1, -1, 1, -1 ]; const uvs = [ 0, 0, 1, 0, 0, 1, 1, 1 ]; const indicies = [ 0, 2, 1, 2, 3, 1 ]; const mesh = this.add.mesh(400, 300, 'ayu'); mesh.addVertices(vertices, uvs, indicies); mesh.panZ(7); this.debug = this.add.graphics(); mesh.setDebug(this.debug); this.add.text(16, 16, 'Rotate with mouse (+ Shift to pan)\nWheel to zoom\nD to toggle debug'); this.input.keyboard.on('keydown-D', () => { if (mesh.debugCallback) { mesh.setDebug(); } else { mesh.setDebug(this.debug); } }); const rotateRate = 1; const panRate = 1; const zoomRate = 4; this.input.on('pointermove', pointer => { if (!pointer.isDown) { return; } if (!pointer.event.shiftKey) { mesh.modelRotation.y += pointer.velocity.x * (rotateRate / 800); mesh.modelRotation.x += pointer.velocity.y * (rotateRate / 600); } else { mesh.panX(pointer.velocity.x * (panRate / 800)); mesh.panY(pointer.velocity.y * (panRate / 600)); } }); this.input.on('wheel', (pointer, over, deltaX, deltaY, deltaZ) => { mesh.panZ(deltaY * (zoomRate / 600)); }); } update () { this.debug.clear(); this.debug.lineStyle(1, 0x00ff00); } } const config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor: '#0a440a', parent: 'phaser-example', scene: Example }; let game = new Phaser.Game(config);
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v355');
this.load.image('bg', 'assets/skies/gradient13.png');
this.load.image('ayu', 'assets/pics/ayu.png');
}
create ()
{
this.add.image(400, 300, 'bg').setFlip(false, true);
const vertices = [
-1, 1,
1, 1,
-1, -1,
1, -1
];
const uvs = [
0, 0,
1, 0,
0, 1,
1, 1
];
const indicies = [ 0, 2, 1, 2, 3, 1 ];
const mesh = this.add.mesh(400, 300, 'ayu');
mesh.addVertices(vertices, uvs, indicies);
mesh.panZ(7);
this.debug = this.add.graphics();
mesh.setDebug(this.debug);
this.add.text(16, 16, 'Rotate with mouse (+ Shift to pan)\nWheel to zoom\nD to toggle debug');
this.input.keyboard.on('keydown-D', () => {
if (mesh.debugCallback)
{
mesh.setDebug();
}
else
{
mesh.setDebug(this.debug);
}
});
const rotateRate = 1;
const panRate = 1;
const zoomRate = 4;
this.input.on('pointermove', pointer => {
if (!pointer.isDown)
{
return;
}
if (!pointer.event.shiftKey)
{
mesh.modelRotation.y += pointer.velocity.x * (rotateRate / 800);
mesh.modelRotation.x += pointer.velocity.y * (rotateRate / 600);
}
else
{
mesh.panX(pointer.velocity.x * (panRate / 800));
mesh.panY(pointer.velocity.y * (panRate / 600));
}
});
this.input.on('wheel', (pointer, over, deltaX, deltaY, deltaZ) => {
mesh.panZ(deltaY * (zoomRate / 600));
});
}
update ()
{
this.debug.clear();
this.debug.lineStyle(1, 0x00ff00);
}
}
const config = {
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#0a440a',
parent: 'phaser-example',
scene: Example
};
let game = new Phaser.Game(config);