How SpritePackedManager works or maybe is not working at all

i spent time creating the texture which has many sprites inside like in the example here:

but obviously i have different sprites, also documentation didn’t say that the json file used there can have the same name as the texture but changing “.png” for “.json” ( anyway, this is not important ).

so, when you have several sprites that contains animations, let me put an example:

` const enemyPacker = new SpritePackedManager(“enemyPacker”,“/assets/atlas/eneAtlas.png”, 30,this.scene)

this.enemies2[0] = new Sprite(“enemy2-”+idx, enemyPacker);
this.enemies2[0].cellRef = “ene2”;
if i use cellRef =0, it will put the sprite index at the first entry of the json file, not my first frame of "ene2" sprite section, also this:this.enemies2[0].playAnimation(3, 7, true, 50);`

does not work, if you put 0 and 4 ( for my sprite animation initial frame and end frame ), it will also change the sprite for the first entry on json file which is not “ene2”.

my question is:
is SpritePackedManager only to put static or sprites with 1 frame?
cause i thought this was a better way to load an atlas with many frames including animations and then select from every sprite what you want to use?, well is only working for static sprites not for animations,
cause when you change the cellIndex it changes to other sprite.

has anybody an example of an animation of the same sprite with different frames, not animation between different sprites. thanks in advance…

Hi @pavul

Did you check this doc page : Sprite Map Animations | Babylon.js Documentation

It looks like what you need with 1 sprite and different animation frames.

yes, and that work, the difference with SpriteMap and SpritePackageManager is that for SpriteMap i would need every sprite image separated(making one call per texture once the game starts) and is better to put all the sprites of a game in a big image (usually called atlas) cause is better that way, there is one call to that big texture from the server and is kept in memory, hence is easier to get just a portion of the texture that will be renderer in screen(internally speaking).

i think that the usage of spritePackagemanager, but is not working like it should.
that’s why i am asking

EDIT:
by the way SpriteMap is to craete a level based on tiles ( or tilesets ), i don’t see accuarate to create an SpriteMap with stageSize field for sprite measures, so that means i will have to create one spriteMap for sprite in order to animate which i don’t think is the right option

Adding @Pryme8 who I believe worked on this feature.

i am checking SpriteMap, to see if that works for what i need, will reply my findings later

What are you trying to do? The sprite map only supports and atlas so I’m not sure why you would need to load a bunch of images?

I’m not savvy about the packed Manager but what I think you are asking is how you can create your own packed sprite texture and json?

what i am trying to do is to put all my game sprites (in pixel art) in an image and then create every sprite with or without the animations to load just one image and one json file, instead several images.

when an Sprite is instantiated with SpritePackedManager it only works for sprites with one frame, cause so far i haven’t been able to play the animation for that specific sprite, let me give you an example:
const enemyPacker = new SpritePackedManager(“enemyPacker”,“/assets/atlas/eneAtlas.png”, 30,this.scene)

    this.bullet= new Sprite( "bullet0", enemyPacker)
    this.bullet.cellRef = "enebullet";
    this.bullet.position=new Vector3(1,0,0)
    this.bullet.playAnimation( 0,1,true, 300 )

i know my bullet sprite has 2 frames ( 0 and 1 ), but if i use above code playAnimation will loop through cellIndex of sprite enebullet and cellIndex 0 of another sprite

here is the video of what i am talking about:

if you feature does not work with animations, you can specify in documentation then.

Im not sure, we would have to ask someone that knows the SpritePackedManager better.

It probably can be done, if not then I doubt its a hard fix.

From the doc it looks like it should work so I suspect there might be a bug in the looping code:

Can you share a repro in the playground so I ll have a look ASAP ?

if you look at the video i posted above, you can see the texture, with the sprite indexes at the right, and the bullet sprite with the index 0 and 1 at the left, also you can see the json at the right of the screen.
if it must work it isn’t that is what i am showing in the video.

Yes, but please, could you create a repro to help us fix the issue.

Creating the repro does not look much but if you see the number of issues the community helps on, this is an amazing boost for the ppl that are addressing those issues. The best would be to have it in the playground https://playground.babylonjs.com/

yeah i’ll try to do something

1 Like