Skip to content

Instantly share code, notes, and snippets.

Avatar

Thibaut Foussard thibka

  • Paris, France
View GitHub Profile
@thibka
thibka / setSize.js
Last active Aug 12, 2022
PixiJS - Set sprite size to cover/contain
View setSize.js
/*
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,