Save PNGs into an Array and loaded later on without losing any quality?

0 favourites
  • 5 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hi,

    Is there any way to save PNGs into an Array and loaded later on but without losing any quality?

    So the idea is to just load the assets on demand from an Array instead of online server if the quality of the assets is gonna be the same standards as if I was gonna load them from actual PNGs.

    Nepeo I hope you don't mind I tagged you maybe you can give me an accurate Answer as you design many parts of C3 Engine

    Thank you

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • PNGs are a lossless format, so there is no way this could lose quality.

  • PNGs are a lossless format, so there is no way this could lose quality.

    Thanks Ashley for confirming it

  • You can store images as base64 string in an array, then decode them into images as required. But be careful about the size of the images.

    Base64 converts bytes into a subset of 64 values that can be safely represented as letters in a document. As it's a subset that means you end up increasing the number of bytes you need. For every 3 bytes in, you get 4 bytes out. So a 3MB image is 4MB encoded as base64. Also JS uses 2 bytes per character for strings, so that becomes 8MB once the array has been loaded into memory.

    Otherwise it's a fairly sound idea. I've written programs that embed binary data in the file as base64, it's an easy way to reduce the number of network requests.

    A more complicated alternative is to download the images when the game is first loaded, then stash them in localstorage. Localstorage is written to disk so it won't impact your memory usage as much, and you can write binary data directly instead of using base64. It will be a little slower to load the image than accessing from an array, but faster than the network.

  • Nepeo

    Awesome Thanks very much for this useful info, you answered many questions & doubts that I had, also the localstorage idea it's very interesting I'm gonna give it a try :)

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