Reposition on resize and add title screen element (#9)
This commit is contained in:
1 parent
93ce8285d4
commit
d5035a9a87
3 files changed
+47
-28
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { Engine, ScreenElement, vec } from "excalibur";
|
||||
import { Text } from "../ScreenElements/Text";
|
||||
import { subTitleFont, titleFont } from "../utils/fontUtil";
|
||||
import { spacingM } from "../utils/formattingUtils";
|
||||
|
||||
export class Title extends ScreenElement {
|
||||
private _title: Text = null!;
|
||||
private _subTitle: Text = null!;
|
||||
|
||||
onInitialize(_engine: Engine): void {
|
||||
// Title
|
||||
this._title = new Text({
|
||||
text: "Auto Beer Pong",
|
||||
font: titleFont,
|
||||
});
|
||||
this._title.anchor = vec(0.5, 0);
|
||||
this.addChild(this._title);
|
||||
|
||||
|
||||
// Sub title
|
||||
this._subTitle = new Text({
|
||||
text: "An auto battler with stupid people.",
|
||||
font: subTitleFont,
|
||||
});
|
||||
this._subTitle.anchor = vec(0.5, 0);
|
||||
this._subTitle.pos = vec(0, this._titleHeight + spacingM);
|
||||
this.addChild(this._subTitle);
|
||||
}
|
||||
|
||||
get height(): number {
|
||||
return this._titleHeight + subTitleFont.size + spacingM;
|
||||
}
|
||||
|
||||
private get _titleHeight(): number {
|
||||
return titleFont.size;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
import * as ex from 'excalibur';
|
||||
import { spacingL, spacingM } from '../utils/formattingUtils';
|
||||
import { subTitleFont, titleFont } from '../utils/fontUtil';
|
||||
import { Cups } from '../Cups';
|
||||
import { GameState } from '../GameState';
|
||||
import { GameStateScene } from './GameStateScene';
|
||||
import { PlayerListScreenElement } from '../ScreenElements/PlayerListScreenElement';
|
||||
import { TitledListScreenElement } from '../ScreenElements/TitledListScreenElement';
|
||||
import { Text } from '../ScreenElements/Text';
|
||||
import { Button } from '../ScreenElements/Button';
|
||||
import { PlayerNameInput } from '../GameElements/PlayerNameInput';
|
||||
import { Connection, GameMessageEvent } from '../Connection';
|
||||
import { Title } from '../GameElements/Title';
|
||||
|
||||
const tableWidth = 400;
|
||||
const maxPlayers = 2;
|
||||
@@ -20,13 +19,12 @@ export class LobbyScene extends GameStateScene {
|
||||
private _table: ex.ScreenElement = null!;
|
||||
private _cups: ex.ScreenElement = null!;
|
||||
|
||||
private _title: Title = null!;
|
||||
|
||||
private _bar1: ex.ScreenElement = null!;
|
||||
private _bar2: ex.ScreenElement = null!;
|
||||
private _bar3: ex.ScreenElement = null!;
|
||||
|
||||
private _title: Text = null!;
|
||||
private _subTitle: Text = null!;
|
||||
|
||||
private _playerList: PlayerListScreenElement = null!;
|
||||
private _spectatorsList: TitledListScreenElement = null!;
|
||||
|
||||
@@ -77,23 +75,9 @@ export class LobbyScene extends GameStateScene {
|
||||
this.add(this._cups);
|
||||
|
||||
// Title
|
||||
this._title = new Text({
|
||||
text: "Auto Beer Pong",
|
||||
font: titleFont,
|
||||
});
|
||||
this._title.anchor.setTo(0.5, 0);
|
||||
this._title = new Title();
|
||||
this.add(this._title);
|
||||
|
||||
|
||||
// Sub title
|
||||
this._subTitle = new Text({
|
||||
text: "An auto battler with stupid people.",
|
||||
font: subTitleFont,
|
||||
});
|
||||
this._subTitle.anchor.setTo(0.5, 0);
|
||||
this.add(this._subTitle);
|
||||
|
||||
|
||||
this._playerList = new PlayerListScreenElement("Players", maxPlayers);
|
||||
this._playerList.labels = ["Dubbel"];
|
||||
this._playerList.anchor.setTo(0.5, 0);
|
||||
@@ -118,6 +102,8 @@ export class LobbyScene extends GameStateScene {
|
||||
this._playerNameInput = new PlayerNameInput((_name: string) => this._join());
|
||||
this._playerNameInput.anchor = ex.vec(0.5, 0);
|
||||
|
||||
engine.screen.events.on("resize", () => this._updatePositions());
|
||||
|
||||
this._updateVisibility();
|
||||
this._updatePositions();
|
||||
}
|
||||
@@ -168,10 +154,7 @@ export class LobbyScene extends GameStateScene {
|
||||
y += this._bar1.height + spacingM;
|
||||
|
||||
this._title.pos = ex.vec(halfWidth, y);
|
||||
y += this._title.font.size + spacingM;
|
||||
|
||||
this._subTitle.pos = ex.vec(halfWidth, y);
|
||||
y += this._subTitle.font.size + spacingM;
|
||||
y += this._title.height + spacingM;
|
||||
|
||||
this._bar2.pos = ex.vec(halfWidth, y);
|
||||
y += this._bar2.height + spacingL;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as ex from 'excalibur';
|
||||
import * as ex from "excalibur";
|
||||
import { LobbyScene } from "./Scenes/LobbyScene";
|
||||
import { Connection } from './Connection';
|
||||
import { Connection } from "./Connection";
|
||||
|
||||
(async () => {
|
||||
const connection = new Connection();
|
||||
@@ -17,8 +17,7 @@ import { Connection } from './Connection';
|
||||
});
|
||||
game.toggleDebug();
|
||||
|
||||
|
||||
game.start().then(async () => {
|
||||
await game.goToScene('lobby');
|
||||
await game.goToScene("lobby");
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user