Load Img from URL,how to Scaled Down RESPECTING AspectRatio?

0 favourites
  • 10 posts
From the Asset Store
Progress\Loading Bar. Now Load you game like a Professional.
  • So the Sprite Object can Load Image from URL, now, for example it loads from the file chooser and load the image from your phone.

    The sprite is a square and the picture is not a square, the "resize to image size" will expand the sprite beyond the size of the screen so NO.

    But the "keep current size" option, even though the image fits into the square, is stretched.

    Is there a way to scale it down RESPECTING aspect ratio ?

  • You will have to do a little maths to resize the incoming image to fit within the square.

    -Use the width and height of the new image to work out the aspect ratio.

    -Work out if the image is portrait or landscape.

    -then set the new image width and height to fit within the square

  • Let me see if I get this straight:

    Step 1: Let the image load and let the sprite resize to fit the image.

    Step 2: THEN retrieve the resulting width/height of Sprite.

    Step 3: Resize the Sprite from there.

    This might work !!! I will let you know ! Thank you !

  • That's it..

    Load from the URL and create an event with the trigger 'On Image URL loaded' to initialise the resize process.

  • Toddler or aquinn:

    Could you please explain to me what I need to do in the "step 3"?

  • Ok. I saw that it is an old thread but anyone can help me with this issue?

  • Could you please explain to me what I need to do in the "step 3"?

    Say sprite is supposed to be no bigger than 256x256, use a couple of variables/globals to store new width and height based on calculation that sets the biggest side to 256 and the other to a proportionate size, then apply those to the sprite

    newWidth = sprite.Width >= sprite.Height ? 256 : (sprite.Width/sprite.Height)*256

    newHeight = sprite.Height >= sprite.Width ? 256 : (sprite.Height/sprite.Width)*256

    sprite.Width = newWidth

    sprite.Height = newHeight

    EDIT: Did a quick example capx (r233)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Awesome OddConfection!

    Thanks for all the instructions and for the capx too.

    I'm having a problem to load PNG files. The image has a transparent background but the bg always is showed black. Do you know how can I fix it?

  • I'm having a problem to load PNG files. The image has a transparent background but the bg always is showed black. Do you know how can I fix it?

    I'm not sure what the problem is as I am able to load a PNG with a transparent background without problem. Have you tried different PNGs? Maybe there is a problem with the one you are testing.

    A long shot, but I know early versions of Internet Explorer had an issue with PNG transparency, maybe it's a browser issue.

  • I will check it. Thanks for all.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)