Jump to content

sprite width/height proportional to image


renathy
 Share

Recommended Posts

I have about 50 images, I load them into Application. Then I create sprite for each image. Images width and height differs, they are not the same width/height, and images are quite large compared with sprites I need on screen.

This is my first App in Pixi.js

I am using latest PIXI.jS version. I have defined width (let us say width = 100). I need all sprites to be width = 100, but height should be calculated proportionally based on image (from which texture was created).

Is it possible?

let mySprite = new PIXI.Sprite(app.loader.resources[imgName].texture);
mySprite.anchor.set(0.5, 0.5);

mySprite.width = 100;
mySprite.height = 100; // instead this should be calculated to fit image proportions

I think I do not have problems to do math, but I have problems to get right values against which calculation/proportions should be calculated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...