Jump to content

SpriteManager's capacity and loading sprites


Thark
 Share

Recommended Posts

Hey everyone

I just have two simple question I cannot find an answer too.
First Question: The SpriteManager needs a capacity parameter, but why does it need this?
Why can I not change this during runtime?
What does it actually do (in the background) (except for just not showing any sprites that exceed the capacity)?
Does it hurt performance at all if I just put a 'crazy' high number?
Can the manager not just +1 the capacity by itself in the background whenever an instance of the sprite is created? 

It just seems so odd that I have to give it a number and I feel like I'm missing something here.

My second question is how to exactly use the AssetsManager for sprites. The documentation gives this example:

var imageTask = assetsManager.addImageTask("image task", "img.jpg");
imageTask.onSuccess = function(task) {
    console.log(task.image.width);
}

But that doesn't explain how to use it with a Sprite since the task returns an image, and a SpriteManager only requires an image url.

Thank you in advance!
 

Link to comment
Share on other sites

Hello!

1. Capacity

Capacity is used to dimension GPU resources: https://github.com/BabylonJS/Babylon.js/blob/master/src/Sprites/babylon.spriteManager.ts#L82

It is useful because sprites rely on GPU resources like vertex buffer and we cannot just recreate one every time you add a sprite. So instead, we start with a big buffer that we fill until we reach the capacity

2. You can stil rely on the assetsManager because the image will be in the cache when onSuccess will be called

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...