-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,53 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import { Application } from 'pixi.js'; | ||
import { Container, Text } from 'pixi.js'; | ||
import { initPixi } from './utils/pixi'; | ||
|
||
const app = new Application(); | ||
|
||
app.init({ | ||
resizeTo: window, | ||
background: 0x000000, | ||
}).then(() => | ||
// eslint-disable-next-line no-new | ||
new class App | ||
{ | ||
document.body.appendChild(app.canvas as any); | ||
}); | ||
private view: Container; | ||
|
||
constructor() | ||
{ | ||
this.init(); | ||
} | ||
|
||
private async init() | ||
{ | ||
const pixiApp = await initPixi(); | ||
|
||
this.view = new Container(); | ||
|
||
pixiApp.stage.addChild(this.view); | ||
|
||
this.createElements(); | ||
|
||
this.addSubscriptions(); | ||
} | ||
|
||
private addSubscriptions() | ||
{ | ||
window.addEventListener('resize', () => this.resize()); | ||
window.addEventListener('deviceorientation', () => this.resize()); | ||
this.resize(); | ||
} | ||
|
||
private createElements() | ||
{ | ||
const text = new Text({ text: 'Pixi 8' }); | ||
|
||
text.anchor.set(0.5); | ||
text.style = { | ||
fontSize: 100, | ||
fill: 0xffffff | ||
}; | ||
|
||
this.view.addChild(text); | ||
} | ||
|
||
private resize(width = window.innerWidth, height = window.innerHeight) | ||
{ | ||
this.view.x = width / 2; | ||
this.view.y = height / 2; | ||
} | ||
}(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Application, ApplicationOptions } from 'pixi.js'; | ||
|
||
export async function initPixi(options?: Partial<ApplicationOptions>): Promise<Application> | ||
{ | ||
const app = new Application(); | ||
|
||
await app.init({ | ||
resizeTo: window, | ||
background: 0x000000, | ||
...options | ||
}); | ||
|
||
document.body.appendChild(app.canvas as any); | ||
|
||
// #v-ifdef MODE=production | ||
// Pixi inspector | ||
(globalThis as any).__PIXI_APP__ = app; | ||
// #v-endif | ||
|
||
return app; | ||
} |