enough today, im happy

This commit is contained in:
koneko 2024-09-22 23:29:27 +02:00
parent 73eba44e5e
commit 5881a8816e
4 changed files with 31 additions and 11 deletions

11
src/base/Assets.ts Normal file
View File

@ -0,0 +1,11 @@
import * as PIXI from "pixi.js";
export default class Assets {
public static async LoadAssets() {
Assets.ButtonTexture = await PIXI.Assets.load({
src: "/assets/gui/button_02.png",
});
}
public static ButtonTexture: PIXI.Texture;
}

View File

@ -1,4 +1,5 @@
import GameObject from "./GameObject"; import GameObject from "./GameObject";
import Assets from "./Assets";
import * as PIXI from "pixi.js"; import * as PIXI from "pixi.js";
export default class Button extends GameObject { export default class Button extends GameObject {
@ -16,7 +17,7 @@ export default class Button extends GameObject {
this.caption = caption; this.caption = caption;
this.color = color; this.color = color;
this.container.interactive = true; this.container.interactive = true;
this.buttonTexture = PIXI.Texture.from("/assets/gui/button02.png"); this.buttonTexture = Assets.ButtonTexture;
this.createButton(); this.createButton();
} }
@ -26,18 +27,24 @@ export default class Button extends GameObject {
private createButton() { private createButton() {
this.container.removeChildren(); this.container.removeChildren();
const button = new PIXI.Graphics(); // const button = new PIXI.Graphics();
button.rect(0, 0, this.bounds.width, this.bounds.height); // button.rect(0, 0, this.bounds.width, this.bounds.height);
button.fill(this.color); // button.fill(this.color);
console.log(this.buttonTexture);
const button = new PIXI.Sprite(this.buttonTexture); // TODO: sliced texture
button.x = 0;
button.y = 0;
button.width = this.bounds.width;
button.height = this.bounds.height;
this.container.addChild(button); this.container.addChild(button);
const text = new PIXI.Text({ text: this.caption }); const text = new PIXI.Text({ text: this.caption });
this.container.addChild(text); this.container.addChild(text);
text.anchor.set(0.5, 0.5); text.anchor.set(0.5, 0.5);
text.x = this.bounds.width / 2; text.x = this.bounds.width / 2;
text.y = this.bounds.height / 2; text.y = this.bounds.height / 2;
this._container.x = this.bounds.x; this.container.x = this.bounds.x;
this._container.y = this.bounds.y; this.container.y = this.bounds.y;
this._container.on("click", () => { this.container.on("click", () => {
this.events.emit("click"); this.events.emit("click");
}); });
} }

View File

@ -1,5 +1,6 @@
import * as PIXI from "pixi.js"; import * as PIXI from "pixi.js";
import Game from "./base/Game"; import Game from "./base/Game";
import Assets from "./base/Assets";
(async () => { (async () => {
const app = new PIXI.Application(); const app = new PIXI.Application();
await app.init({ await app.init({
@ -10,6 +11,7 @@ import Game from "./base/Game";
}); });
document.body.appendChild(app.canvas); document.body.appendChild(app.canvas);
await Assets.LoadAssets();
const game = new Game(app.screen); const game = new Game(app.screen);
app.stage.addChild(game.container); app.stage.addChild(game.container);
window.addEventListener("resize", () => { window.addEventListener("resize", () => {

View File

@ -20,9 +20,9 @@ export default class MainMenu extends Scene {
this._newGameButton = new Button( this._newGameButton = new Button(
"New Game", "New Game",
new PIXI.Rectangle( new PIXI.Rectangle(
100, this.bounds.width / 2 - 300 / 2,
this.bounds.height / 2 - 80, this.bounds.height / 2 - 80,
this.bounds.width - 200, 300,
60 60
), ),
new PIXI.Color("blue") new PIXI.Color("blue")
@ -35,9 +35,9 @@ export default class MainMenu extends Scene {
this._settingsButton = new Button( this._settingsButton = new Button(
"Settings", "Settings",
new PIXI.Rectangle( new PIXI.Rectangle(
100, this.bounds.width / 2 - 300 / 2,
this.bounds.height / 2 + 20, this.bounds.height / 2 + 20,
this.bounds.width - 200, 300,
60 60
), ),
new PIXI.Color("gray") new PIXI.Color("gray")