Jump to content

Using strings for sprite frame names in Animation manager


ForgeableSum
 Share

Recommended Posts

When I add a sprite with the animation manager, I can't seem to get the useNumericIndex: false to work (i.e. reference frames by string name instead of number). The animation works just fine if I use the numeric index. But for organizational purposes, I need to use a string. Here's my code (including JSON):

sprite.animations.add('idleN', ['test', 'sdfsd', 'sdfsvvvvd', 'sdfsdf'], 15, true, false);{"filename": "test","frame": {"x":0,"y":0,"w":64,"h":64},"rotated": false,"trimmed": true,"spriteSourceSize": {"x":0,"y":0,"w":64,"h":64},"sourceSize": {"w":64,"h":64}},{"filename": "sdfsd","frame": {"x":64,"y":0,"w":64,"h":64},"rotated": false,"trimmed": true,"spriteSourceSize": {"x":0,"y":0,"w":64,"h":64},"sourceSize": {"w":64,"h":64}},{"filename": "sdfsvvvvd","frame": {"x":128,"y":0,"w":64,"h":64},"rotated": false,"trimmed": true,"spriteSourceSize": {"x":0,"y":0,"w":64,"h":64},"sourceSize": {"w":64,"h":64}},{"filename": "sdfsdf","frame": {"x":192,"y":0,"w":64,"h":64},"rotated": false,"trimmed": true,"spriteSourceSize": {"x":0,"y":0,"w":64,"h":64},"sourceSize": {"w":64,"h":64}},

I've tried all sorts of different file names: no luck. I get "Uncaught TypeError: Cannot read property 'x' of undefined - Phaser line 11". Could it be that the "filename" property isn't what I need to set? There's nothing in the docs that says what property I would use to name the sprite ... in fact, there's nothing in the docs about how to structure your JSON period. It's toilsome have to reverse engineer the json used in phaser examples. where would I go for that information? I can't find an instance of useNumericIndex: false in the examples. 

Link to comment
Share on other sites

As the docs say the json files are built automatically by tools such as Texture Packer, Shoebox or Flash. This is an industry standard format, not specific to Phaser.

 

Very rarely (if ever) would you create these files by hand. There's just too much margin for error in getting the coordinates wrong.

 

The "useNumericIndex" parameter isn't required in the above code. All that is needed are correct frame names, and more importantly, the correct format when loading the json in the first place. The json above is an atlasHash format, not atlasArray. However it is malformed and missing the required frames block. Either that or you didn't copy and paste it all into the forum post.

Link to comment
Share on other sites

Thanks for responding. This really clears some things up.

 

I only copy + pasted the relevant selection, not the entire thing (hence the missing frames block). The JSON was generated with Texture Packer (as per the directions in the API), but I didn't know there were different kinds of JSON formats. I assume there is an option in Texture Packer for the atlasArray format? I will try that format when I get home today. Thanks!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...