Skip to content

Add responsiveness to the template #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { Preloader } from './scenes/Preloader';
// https://newdocs.phaser.io/docs/3.70.0/Phaser.Types.Core.GameConfig
const config = {
type: Phaser.AUTO,
width: 1024,
height: 768,
width: screen.width,
height: screen.height,
parent: 'game-container',
backgroundColor: '#028af8',
scale: {
Expand Down
1 change: 1 addition & 0 deletions src/scenes/Boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Boot extends Scene
// The smaller the file size of the assets, the better, as the Boot Scene itself has no preloader.

this.load.image('background', 'assets/bg.png');
this.load.image('logo', 'assets/logo.png');
}

create ()
Expand Down
31 changes: 25 additions & 6 deletions src/scenes/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,34 @@ export class Game extends Scene

create ()
{
const canvas = this.game.canvas;
const vw = canvas.width * 0.01; // 1% viewer width
const vh = canvas.height * 0.01; // 1% viewer height
const vmax = vw > vh ? vw : vh;

this.cameras.main.setBackgroundColor(0x00ff00);

this.add.image(512, 384, 'background').setAlpha(0.5);
let background = this.add.image(50 * vw, 50 * vh, 'background').setAlpha(0.5);
background.scaleX = 100 * vw / background.width;
background.scaleY = 100 * vh / background.height;

this.add.text(512, 384, 'Make something fun!\nand share it with us:\[email protected]', {
fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setOrigin(0.5);
this.add.text(
50 * vw,
50 * vh,
'Make something fun!\nand share it with us:\[email protected]',
{
fontFamily: 'Arial Black',
fontSize: 38,
color: '#ffffff',
stroke: '#000000',
strokeThickness: 8,
align: 'center',
wordWrap: {
width: 100 * vw,
useAdvancedWrap: true,
}
}
).setOrigin(0.5);

this.input.once('pointerdown', () => {

Expand Down
25 changes: 19 additions & 6 deletions src/scenes/GameOver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ export class GameOver extends Scene

create ()
{
const canvas = this.game.canvas;
const vw = canvas.width * 0.01; // 1% viewer width
const vh = canvas.height * 0.01; // 1% viewer height
const vmax = vw > vh ? vw : vh;

this.cameras.main.setBackgroundColor(0xff0000);

this.add.image(512, 384, 'background').setAlpha(0.5);
let background = this.add.image(50 * vw, 50 * vh, 'background').setAlpha(0.5);
background.scaleX = 100 * vw / background.width;
background.scaleY = 100 * vh / background.height;


this.add.text(512, 384, 'Game Over', {
fontFamily: 'Arial Black', fontSize: 64, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setOrigin(0.5);
this.add.text(
50 * vw,
50 * vh,
'Game Over',
{
fontFamily: 'Arial Black', fontSize: 64, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}
).setOrigin(0.5);

this.input.once('pointerdown', () => {

Expand Down
36 changes: 29 additions & 7 deletions src/scenes/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,37 @@ export class MainMenu extends Scene

create ()
{
this.add.image(512, 384, 'background');
const canvas = this.game.canvas;
const vw = canvas.width * 0.01; // 1% viewer width
const vh = canvas.height * 0.01; // 1% viewer height
const vmax = vw > vh ? vw : vh;

this.add.image(512, 300, 'logo');
let background = this.add.image(50 * vw, 50*vh, 'background');
background.scaleX = 100 * vw / background.width;
background.scaleY = 100 * vh / background.height;

// Show our "Phaser" title
const title = this.add.image(
50 * vw,
40 * vh,
'logo'
)
if (vmax == vw) {
title.scale = 15 * vh / title.height;
} else {
title.scale = 90 * vw / title.width;
}

this.add.text(512, 460, 'Main Menu', {
fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}).setOrigin(0.5);
this.add.text(
50 * vw,
66.66 * vh,
'Main Menu',
{
fontFamily: 'Arial Black', fontSize: 38, color: '#ffffff',
stroke: '#000000', strokeThickness: 8,
align: 'center'
}
).setOrigin(0.5);

this.input.once('pointerdown', () => {

Expand Down
49 changes: 43 additions & 6 deletions src/scenes/Preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,58 @@ export class Preloader extends Scene

init ()
{
const canvas = this.game.canvas;
const vw = canvas.width * 0.01; // 1% viewer width
const vh = canvas.height * 0.01; // 1% viewer height
const vmax = vw > vh ? vw : vh;

// We loaded this image in our Boot Scene, so we can display it here
this.add.image(512, 384, 'background');
const background = this.add.image(
50 * vw,
50 * vh,
'background'
);
background.scaleX = 100 * vw / background.width;
background.scaleY = 100 * vh / background.height;

// Show our "Phaser" title
const title = this.add.image(
50 * vw,
40 * vh,
'logo'
)
if (vmax == vw) {
title.scale = 15 * vh / title.height;
} else {
title.scale = 90 * vw / title.width;
}

// A simple progress bar. This is the outline of the bar.
this.add.rectangle(512, 384, 468, 32).setStrokeStyle(1, 0xffffff);
const rect = this.add.rectangle(
50 * vw,
66.66 * vh,
90 * vw,
5 * vh,
);
rect.setStrokeStyle(0.25 * vmax, 0x000000);
rect.setDepth(3);

// This is the progress bar itself. It will increase in size from the left based on the % of progress.
const bar = this.add.rectangle(512-230, 384, 4, 28, 0xffffff);
const bar = this.add.rectangle(
rect.x - rect.width / 2,
rect.y - rect.height / 2,
0,
rect.height,
0xffffff
);
bar.setOrigin(0, 0);
bar.setDepth(2);

// Use the 'progress' event emitted by the LoaderPlugin to update the loading bar
this.load.on('progress', (progress) => {

// Update the progress bar (our bar is 464px wide, so 100% = 464px)
bar.width = 4 + (460 * progress);
// Update the progress bar
bar.width = rect.width * progress;

});
}
Expand All @@ -31,7 +69,6 @@ export class Preloader extends Scene
{
// Load the assets for the game - Replace with your own assets
this.load.setPath('assets');

this.load.image('logo', 'logo.png');
}

Expand Down