Skip to content

Instantly share code, notes, and snippets.

View thibka's full-sized avatar

Thibaut Foussard thibka

View GitHub Profile
@thibka
thibka / setSize.js
Last active April 5, 2023 07:54
PixiJS - Set sprite size to cover/contain
/*
WIP
Only works for full screen sprites.
width: width of the sprite container
height: height of the sprite container
type: "cover" or "contain"
*/
PIXI.Sprite.prototype.setSize = function(width, height, type) {
var texture = { width: this.texture.width, height: this.texture.height },
targetRatio = width / height,