Jump to content

Best practice loading 80 images


darkshifty
 Share

Recommended Posts

I am fairly new at PIXI.js and i like it so far, however I can't really see how to load 80+ images in a best performant and clean way.
All the examples speak of the loader (which requires a huge 320 lines of image loading code) and a json file, but as far as i could find the json file only supports frames to be loaded (am i wrong?) 
 

app.loader
    .add({
        name: 'clouds',
        url: 'images/clouds.png'
    }, function () {})
    .add({
        name: 'background',
        url: 'images/landscape/wet.png'
    }, function () {})
    .add({
        name: 'delta',
        url: 'images/climate/wet/w-delta.png'
    }, function () {})
    .add({
        name: 'moorland',
        url: 'images/climate/wet/w-moorland.png'
    }, function () {})
    .on("progress", loadProgressHandler)
    .load(setup);

Please advise, is there any best practice in (pre) loading a big selection of images?

Thanks in advance!

Link to comment
Share on other sites

Hello, and Welcome to the forums!

If you have many small images make an atlas with texturepacker/shoebox/"http://free-tex-packer.com/"

For your knowledge, pixi loader is actually https://github.com/englercj/resource-loader/tree/release/3.x and it has a queue with 5 parallel requests.

If you want better API, just pass an array to `add`.

 

 

 

Link to comment
Share on other sites

320 line of code ! hum..
This approach would more clear for your user case.
12 line only

        const list = [
            ['name','url'],
            ['name','url'],
            ['name','url'],
            ['name','url'],
            ['name','url'],
            ['name','url'],
        ]
        const loader = new PIXI.loaders.Loader();
        list.forEach(arr => loader.add(arr[0], arr[1]) ) // or .add(...arr)
        loader.load();
        loader.onError.add((loader, res)=>{
            //stuff
        })
        loader.onProgress.add((loader, res) => {
            //stuff
        })
        loader.onComplete.add((loader, res) => {
            //stuff
        })

And as ivan say to you , for the  best practice in (pre) loading a big selection of images

You will need a texture packer software.
You also have this one free
https://www.codeandweb.com/texturepacker
Work fine in pixijs, or if you use multipack or normals (premium feature) you will need to code your own manager in the pixi loader.

 

 

 

 

Edited by jonforum
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...