pixijs / spine

Pixi.js plugin that enables Spine support.
Other
564 stars 217 forks source link

Preloaded JSON and custom spritesheets #253

Open kulabros opened 6 years ago

kulabros commented 6 years ago

Hi, I'm having problem, with creating new pixi spine instance, with preloaded json data and spritesheets. My situation: I have preloaded and parsed spritesheets with all images used in spine animations, in pixi texture cache. I have included all json data for spine animations as imports in module - I'm using webpack. When I want to create new Spine instance, with json included data, I have a error ncaught TypeError: Cannot read property 'children' of undefined at new Skeleton ... Do I have to parse data by readSkeletonData method of SkeletonJson class? Why do I need to use mesh attachment loader, when I don't want? Thanks for help! :)

ivanpopelyshev commented 6 years ago

Its possible. Please look at https://github.com/pixijs/pixi-spine/tree/master/examples , there are several ways to load textures/json. I know for sure that people use that method you described (webpack json).

kulabros commented 6 years ago

Ok, thank you for quick reply. I looked at the examples allready before, I'm trying to do similar routine as on https://github.com/pixijs/pixi-spine/blob/master/examples/preloaded_json.md page is described. But in my case, I don't need to use atlas loader - I have allready loaded images. So I think problem is, that I want only parse json data, and don't use atlas loader. SkeletonJson needs attachment loader as a parameter in it's constructor, when I skip it, it won't let me execute readSkeletonData method, because it uses attachment loader.. If I use PIXI.loader as in example, and use my included json spine data for constructing new spins instance, it works ok. No, the only change is that I don't want to load any image or atlas - it is allready done. Iwant to create new Spine object instance, passing it's spine data, having images preloaded, and it doesn't work. Code ends execution at Spine constructor (at function Skeleton)... see screenshot.. Thanks a lot for help:) [ screen shot 2018-06-18 at 12 59 15 screen shot 2018-06-18 at 12 58 54

](url)

ivanpopelyshev commented 6 years ago

If you have loaded all the images, you have to pass existing Atlas to it. Please look at other examples too. I know there are many ways to do all those things, but if you are not ready to dig everything, i cant help you.

kulabros commented 6 years ago

Yes you're exactly right, thank you for the answer, it made me look at the problem other way. The problem really was, that I had to create new PIXI.spine.core.TextureAtlas, and add my textures to it. Than I was able to create atlast attachment loader and spine json parse instance, to use readSkeletonData parser method. The only difference i, that I wasn't able to use atlas.addTextureHash because of some realWidth texture's missing property error.. But, when I add textures to atlas manually by addTexture, using name id and PIXI.Texture.from(name id) parameters, suddenly everything started to work as expected. Thank you very much, your answer helped me and I solved the problem! :)

ivanpopelyshev commented 6 years ago

wow! I'm glad i helped. Make sure that you use as small number of images as possible - its better when all attachments are on the same baseTexture. You can count number of DC's (drawcalls) by hacking renderer.gl.drawElements method, just add a counter there and then call super with same params. Pixi multitexture renderer gives 32 textures on PC by dfault, but for mobiles its 1-4, so beware of large number of baseTextures, it can screw batching.

ivanpopelyshev commented 6 years ago

Just in case, there is a solution to form all images loaded with webpack to an atlas, and you look like someone who can dig enough to understand that API :)