azerion / phaser-spine

A plugin for Phaser 2 that adds Spine support
MIT License
121 stars 57 forks source link

Multi Page Textures Broken #14

Closed shibekin69 closed 7 years ago

shibekin69 commented 7 years ago

I just noticed this now while I was trying to export a spine project that needed to use multi-page textures since mine won't fit on a single 1024 x 1024 image. So when I exported with multi-page textures, the spine character appears screwed up when it shows up in the Phaser game. If the spine character uses a single-page texture, it appears fine.

Ok, multi page texture images don't seem to be read properly (I only see the first image loaded), and they're not positioned, rotated, etc.. properly.

I tested the sample export files with the newest spine-ts runtime example (canvas mode) code just to see if it looks fine, and it does.

Problem appears in both Canvas or WebGL mode.

shibekin69 commented 7 years ago

Ok, while looking at the SpineTextureLoader function:

this.load = function (page, file) { var image = this.game.make.image(0, 0, this.key); console.log("MAKING IMAGE FOR PAGE " + page + " WITH FILE " + file + "..."); console.log(image); page.rendererObject = image.texture.baseTexture; };

I see that this thing makes an image with the same key for n number of pages. And it looks like it's loading only the first page of the texture too.

AleBles commented 7 years ago

I wish I could look at this kind of stuff a little bit faster, I'm sorry for not having as much time available as I like to fix this.

Fixing this shouldn't be super hard, but right now I'm swamped with other work. I'd be happy accepting any merge request or possible code fixes you can shoot my way :)

shibekin69 commented 7 years ago

Sure thing, I'll give you something later. I managed to come up with a fix (but can't test it more until I prepare my assets for animation and such.) I need a little help with getting the cache text at the loading stage of the spine object though, or a way to count the pages - I'm doing it by specifying a static number range right now.

shibekin69 commented 7 years ago

Here you go. I've added some comments. I'm assuming there's 10 pages of multipage texture images. I don't know how to access the atlas file from within those functions to search for those image extensions...

https://github.com/orange-games/phaser-spine/compare/master...shibekin69:patch-1?expand=1

shibekin69 commented 7 years ago

Pull request made

AleBles commented 7 years ago

Made a commit based on your changes, also adjusted them to parse the atlas file during preloading and get the correct images, this way no API has to be changed and everything is fully backwards compatible. Could you test this build from the dev branch for me? If all is fine for you I'll update everything :)

shibekin69 commented 7 years ago

Cool! I'm still testing it out while I implement a game feature. So far it's been working fine. I'll let you know if I encounter any hiccups with it.

shibekin69 commented 7 years ago

Looks like it's working fine

AleBles commented 7 years ago

Great, I'll merge it. Thanks for all the help!