hi!
I'm use cocos2d-x runtime,there is a problem bothering me:
how to create an RegionAttachment from CCTexture2D* ?
maybe someone tell me code? thanks very mach! :love:
hi!
I'm use cocos2d-x runtime,there is a problem bothering me:
how to create an RegionAttachment from CCTexture2D* ?
maybe someone tell me code? thanks very mach! :love:
See AtlasAttachmentLoader in spine-c. The default rendering in CCSkeleton requires region rendererObject to be an AtlasRegion, which needs an AtlasPage which needs its rendererObject to be a CCTextureAtlas. If you write your own rendering you can use whatever you want for the rendererObject. Pseudo code to get you started:
AtlasPage* page = AtlasPage_create("page name");
CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("image path");
CCTextureAtlas* textureAtlas = CCTextureAtlas::createWithTexture(texture, 4);
textureAtlas->retain();
page->rendererObject = textureAtlas;
page->width = texture->getPixelsWide();
page->height = texture->getPixelsHigh();
AtlasRegion* region = AtlasRegion_create();
region->page = page;
RegionAttachment* attachment = RegionAttachment_create("attachment name");
attachment->rendererObject = region;
RegionAttachment_setUVs(attachment, u, v, u2, v2, rotate); // specify UVs
attachment->regionOffsetX = 0; // zero if not doing whitespace stripping
attachment->regionOffsetY = 0;
attachment->regionWidth = texture->getPixelsWide();
attachment->regionHeight = texture->getPixelsHigh();
attachment->regionOriginalWidth = attachment->regionWidth; // same if not doing whitespace stripping
attachment->regionOriginalHeight = attachment->regionHeight;
// Now all you need to do is set the attachment's offset relative to the bone:
attachment->x = 0;
attachment->y = 0;
attachment->scaleX = 1;
attachment->scaleY = 1;
attachment->rotation = 0;
attachment->width = texture->getPixelsWide();
attachment->height = texture->getPixelsHigh();
RegionAttachment_updateOffset(attachment);