Thank you very much again!!
So I created a MySpineAtlasLoader.cpp/.h file with the code to get a CCTextureAtlas from my custom renderer object. First of all, I declare a struct that I will be using as my renderer object:
struct MySpineRenderer
{
cocos2d::CCTextureAtlas* textureAtlas;
MySpineRenderer(const char* name)
{
std::string str = name;
if (!MyStringUtil::endsWith(str, ".png"))
{
str += ".png";
}
cocos2d::CCTexture2D* texture = getSpriteFrameFromName(str.c_str())->getTexture();
textureAtlas = cocos2d::CCTextureAtlas::createWithTexture(texture, 100);
textureAtlas->retain(); //I will deal with memory management later...
}
};
And I also declare this function to get the CCTextureAtlas from the void* parameter:
cocos2d::CCTextureAtlas* getAtlasFromMyRendererObject(void* rendererObject)
{
MySpineRenderer* castedObject = (MySpineRenderer*)rendererObject;
return castedObject->textureAtlas;
}
Now, the getTextureAtlas() function from CCSkeleton.cpp has to be changed in order to cast the rendererObject to my own structure type and get the atlas using my function. I know you told me that I would not need to change any source code, but I really don't see the other way to do it...
CCTextureAtlas* CCSkeleton::getTextureAtlas (spRegionAttachment* regionAttachment) const {
//return (CCTextureAtlas*)((spAtlasRegion*)regionAttachment->rendererObject)->page->rendererObject;
return getAtlasFromMyRendererObject(regionAttachment->rendererObject);
}
So the next step was to make something in order to make the AtlasAttachmentLoader to create an attachment object whose rendererObject was an instance of my structure MySpineRenderer. I could have changed the code in AtlasAttachmentLoader.c directly, but I tried to create a new file with a new function that copied the behaviour but instantiated my struct instead. With this, I have this function:
spMyAtlasAttachmentLoader* spMyAtlasAttachmentLoader_create (spAtlas* atlas)
Which calls
spAttachment* _spMyAtlasAttachmentLoader_newAttachment (spAttachmentLoader* loader, spSkin* skin, spAttachmentType type, const char* name)
Both are the equivalents to spAtlasAttachmentLoader_create and _spAtlasAttachmentLoader_newAttachment with minor changes (assigning a MySpineRenderer to the rendererObject of the attachment).
In order to use it (finally), I had to change the spSkeletonJson_create() function in SkeletonJson.c to call my new function instead of spAtlasAttachmentLoader_create(). So I have this new version:
spSkeletonJson* spSkeletonJson_create (spAtlas* atlas) {
//spAtlasAttachmentLoader* attachmentLoader = spAtlasAttachmentLoader_create(atlas);
spMyAtlasAttachmentLoader* attachmentLoader = spMyAtlasAttachmentLoader_create(atlas);
spSkeletonJson* self = spSkeletonJson_createWithLoader(SUPER(attachmentLoader));
SUB_CAST(_spSkeletonJson, self)->ownsLoader = 1;
return self;
}
I think I didn't forget to comment anything. It looks like I almost got the result, as my textures are being used. The big problem I am facing now is that the textures are not being scaled down, which is because I don't know how to manipulate the CCTextureAtlas when I create it (I guess).
Once I fix this, I still will need to restore the source code as much as possible and uncouple my code totally (if possible!).
The last step will be not to make the atlas image be required and possibly to ignore most of the .atlas parsing.
Any suggestion or comment will be appreciated (again). Thank you! π