import * as PIXI from "pixi.js";
export default class MyPixiApp extends PIXI.Application {
constructor(view: HTMLCanvasElement) {
super({ view });
this.ticker.add(deltaTime => this.update(deltaTime));
}
update(deltaTime: number) {
// game loop
}
}
autoStart: boolean, // automatically starts the game loop
width: number, // width of the canvas element (in px)
height: number, // height of the canvas element (in px)
view: HTMLCanvasElement, // link to the canvas
transparent: boolean, // if true, the canvas will be transparent
autoDensity: boolean, // whether CSS dimensions should be resized to screen dim.
antialias: boolean, // sets anti-aliasing
preserveDrawingBuffer: boolean, // if true, preserves stencil buffer
resolution: number, // global scale of the screen (default is 1)
forceCanvas: boolean, // prevents selection of WebGL
backgroundColor: number, // background color of the canvas
clearBeforeRender: boolean, // if true, clears the canvas before next render cycle
forceFXAA: boolean, // forces FXAA anti-aliasing
powerPreference: string, // WebGL parameter for devices with more than one GPU
sharedTicker: boolean, // if true, uses global ticker for updates
sharedLoader: boolean, // if true, uses global loader
resizeTo: Window | HTMLElement, // resizes to a custom HTML element
let ticker = this.ticker;
// prevents autostart
ticker.autoStart = false;
// stops the ticker
ticker.stop();
// starts the ticker if autoStart is false
ticker.start();
=============================
// alternative: manual update
ticker.autoStart = false;
ticker.stop();
let myUpdateLoop =(time) => {
ticker.update(time);
this.renderer.render(this.stage);
requestAnimationFrame(myUpdateLoop);
}
myUpdateLoop(performance.now());
let loader = this.loader;
// Chainable `add` to enqueue a resource
loader.add('mySprite', 'data/sprite.png') // first parameter is an alias
.add('spritesheet', 'assets/spritesheet.json')
.add('bitmapFont', 'assets/score.fnt');
// loading is asynchronous !!
loader.load((loader, resources) => {
// init the rest of the game and run the ticker
});
// loader events
loader.onProgress.add(() => {}); // called once per loaded/errored file
loader.onError.add(() => {}); // called once per errored file
loader.onLoad.add(() => {}); // called once per loaded file
loader.onComplete.add(() => {}); // called once when the queued resources all load
Cossacks 3, 800x600 (4:3)
Cossacks 3, 1920x1080 (16:9)
World of Tanks, 1280x1024 (5:4)
World of Tanks, 1360x768 (16:9)
Ashes of the singularity, 1280x1024 (5:4)
Ashes of the singularity, 1920x1080 (16:9)
Hollow knight, 1280x800 zoomed (16:10)
Hollow knight, 2560x1440 zoomed (16:9)
Stardew valley, 1440x900 (16:10)
Stardew valley, 2560x1440 (16:9)
let texture = PIXI.Texture.from("./assets/lab02/sonic.png");
this.sonic = new PIXI.Sprite(texture); // or PIXI.Sprite.from(<url>)
this.loader.add('myFont', './assets/lab02/dosfont.fnt').load(() => {
let text = new PIXI.BitmapText("Pixel bitmap font", { font: { name: "PxPlus IBM VGA8", size: 80 }, align: "center" });
this.stage.addChild(text);
});
const style = new PIXI.TextStyle({ fontFamily: 'Adventure', fontSize: 36,
fill: ['#ffffff', '#00ff99'], // gradient
stroke: '#4a1850', strokeThickness: 5, });
let text = new PIXI.Text("Regular font", style);
this.container = new PIXI.ParticleContainer(DisplayParticles.particlesNum, {
position: true, // allows to change position during update
rotation: true, // allows to change rotation during update
});
// set interactivity
this.sonic.interactive = true;
// will display hand icon
this.sonic.buttonMode = true;
this.sonic.on('pointerdown', () => { this.animRunning = !this.animRunning; });