I was unable to figure it out either way, using the github version or the version bundled with cocos2d-x.
Using images of different dimensions than the one exported from the Spine editor with the unmodified atlas file exported from the editor would not work.
I only know how I solved it and that was by modifying the source to account for the different texture scales within the related Atlas code. If anyone is interested this is my diff, it requires adding the original Spine exported image dimensions to your atlas. For example, if the exported image is 2048 x 2048, add this line to your atlas file
skeleton.png
format: RGBA8888
filter: Nearest,Nearest
repeat: none
orig: 2048 x 2048
(add the "orig:" line after "repeat" as shown)
If anyone knows what the proper way of working within cocos2d without modifying the source, I am interested as well.
---
extensions/spine/Atlas.cpp | 38 ++++++++++++++++++++
---
extensions/spine/Atlas.h | 3 +++
extensions/spine/spine-cocos2dx.cpp | 1 +
3 files changed, 25 insertions(+), 17 deletions(-)
diff
---
git a/extensions/spine/Atlas.cpp b/extensions/spine/Atlas.cpp
index 281e214..f27bf4f 100755
---
a/extensions/spine/Atlas.cpp
+++ b/extensions/spine/Atlas.cpp
@@ -213,6 +213,10 @@ Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
page->vWrap = *str.begin == 'x' ? ATLAS_CLAMPTOEDGE : (*str.begin == 'y' ? ATLAS_REPEAT : ATLAS_REPEAT);
}
+ if (readTuple(end, tuple) != 2) return abortAtlas(self);
+ page->origWidth = toInt(tuple);
+ page->origHeight = toInt(tuple + 1);
+
_AtlasPage_createTexture(page, path);
FREE(path);
} else {
@@ -230,12 +234,12 @@ Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
region->rotate = equals(&str, "true");
if (readTuple(end, tuple) != 2) return abortAtlas(self);
- region->x = toInt(tuple);
- region->y = toInt(tuple + 1);
+ region->x = toInt(tuple) * page->textureScale;
+ region->y = toInt(tuple + 1) * page->textureScale;
if (readTuple(end, tuple) != 2) return abortAtlas(self);
- region->width = toInt(tuple);
- region->height = toInt(tuple + 1);
+ region->width = toInt(tuple) * page->textureScale;
+ region->height = toInt(tuple + 1) * page->textureScale;
region->u = region->x / (float)page->width;
region->v = region->y / (float)page->height;
@@ -250,29 +254,29 @@ Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
if (!(count = readTuple(end, tuple))) return abortAtlas(self);
if (count == 4) { /* split is optional */
region->splits = MALLOC(int, 4);
- region->splits[0] = toInt(tuple);
- region->splits[1] = toInt(tuple + 1);
- region->splits[2] = toInt(tuple + 2);
- region->splits[3] = toInt(tuple + 3);
+ region->splits[0] = toInt(tuple) * page->textureScale;
+ region->splits[1] = toInt(tuple + 1) * page->textureScale;
+ region->splits[2] = toInt(tuple + 2) * page->textureScale;
+ region->splits[3] = toInt(tuple + 3) * page->textureScale;
if (!(count = readTuple(end, tuple))) return abortAtlas(self);
if (count == 4) { /* pad is optional, but only present with splits */
region->pads = MALLOC(int, 4);
- region->pads[0] = toInt(tuple);
- region->pads[1] = toInt(tuple + 1);
- region->pads[2] = toInt(tuple + 2);
- region->pads[3] = toInt(tuple + 3);
+ region->pads[0] = toInt(tuple) * page->textureScale;
+ region->pads[1] = toInt(tuple + 1) * page->textureScale;
+ region->pads[2] = toInt(tuple + 2) * page->textureScale;
+ region->pads[3] = toInt(tuple + 3) * page->textureScale;
if (!readTuple(end, tuple)) return abortAtlas(self);
}
}
- region->originalWidth = toInt(tuple);
- region->originalHeight = toInt(tuple + 1);
+ region->originalWidth = toInt(tuple) * page->textureScale;
+ region->originalHeight = toInt(tuple + 1) * page->textureScale;
readTuple(end, tuple);
- region->offsetX = toInt(tuple);
- region->offsetY = toInt(tuple + 1);
+ region->offsetX = toInt(tuple) * page->textureScale;
+ region->offsetY = toInt(tuple + 1) * page->textureScale;
if (!readValue(end, &str)) return abortAtlas(self);
region->index = toInt(&str);
@@ -336,4 +340,4 @@ AtlasRegion* Atlas_findRegion (const Atlas* self, const char* name) {
return 0;
}
-}} // namespace cocos2d { namespace extension {
\ No newline at end of file
+}} // namespace cocos2d { namespace extension {
diff
---
git a/extensions/spine/Atlas.h b/extensions/spine/Atlas.h
index ea5ca9b..bd1ce48 100755
---
a/extensions/spine/Atlas.h
+++ b/extensions/spine/Atlas.h
@@ -52,6 +52,9 @@ struct AtlasPage {
AtlasFormat format;
AtlasFilter minFilter, magFilter;
AtlasWrap uWrap, vWrap;
+ int origWidth;
+ int origHeight;
+ float textureScale;
void* rendererObject;
int width, height;
diff
---
git a/extensions/spine/spine-cocos2dx.cpp b/extensions/spine/spine-cocos2dx.cpp
index aa40693..b71e4c4 100755
---
a/extensions/spine/spine-cocos2dx.cpp
+++ b/extensions/spine/spine-cocos2dx.cpp
@@ -38,6 +38,7 @@ void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
// Using getContentSize to make it supports the strategy of loading resources in cocos2d-x.
self->width = texture->getPixelsWide();
self->height = texture->getPixelsHigh();
+ self->textureScale = 1.0f * self->width / self->origWidth;
//self->width = texture->getContentSize().width;
//self->height = texture->getContentSize().height;
}
---
1.8.2.3