Skip to content

Instantly share code, notes, and snippets.


Thibaut Foussard thibka

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