Rotate Matrix Right
Demonstrates how to rotate a 2D array (matrix) 90 degrees clockwise using Phaser's Matrix utility functions.
1024 × 768
class Example extends Phaser.Scene
{
create ()
{
this.add.text(10, 10, 'Click to rotate the array matrix right', { font: '16px Courier', fill: '#ffffff' });
const text = this.add.text(200, 200, '', { font: '32px Courier', fill: '#00ff00' });
let matrix = [
[ 1, 1, 1, 1, 1, 1 ],
[ 2, 0, 0, 0, 0, 4 ],
[ 2, 0, 1, 2, 0, 4 ],
[ 2, 0, 3, 4, 0, 4 ],
[ 2, 0, 0, 0, 0, 4 ],
[ 3, 3, 3, 3, 3, 3 ]
];
text.setText(Phaser.Utils.Array.Matrix.MatrixToString(matrix));
this.input.on('pointerup', () =>
{
matrix = Phaser.Utils.Array.Matrix.RotateRight(matrix);
text.setText(Phaser.Utils.Array.Matrix.MatrixToString(matrix));
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);