diff --git a/examples/export/runtimes.sh b/examples/export/runtimes.sh index a8b3ca159..f39dec09e 100755 --- a/examples/export/runtimes.sh +++ b/examples/export/runtimes.sh @@ -34,6 +34,11 @@ cp -f ../spineboy/export/spineboy.png ../../spine-as3/spine-as3-example/src/ echo "spine-cocos2d-objc" rm -f ../../spine-cocos2d-objc/Resources/* + +cp -f ../coin/export/coin.json ../../spine-cocos2d-objc/Resources/ +cp -f ../coin/export/coin.atlas ../../spine-cocos2d-objc/Resources/ +cp -f ../coin/export/coin.png ../../spine-cocos2d-objc/Resources/ + cp -f ../goblins/export/goblins-mesh.json ../../spine-cocos2d-objc/Resources/ cp -f ../goblins/export/goblins.atlas ../../spine-cocos2d-objc/Resources/ cp -f ../goblins/export/goblins.png ../../spine-cocos2d-objc/Resources/ @@ -52,6 +57,11 @@ cp -f ../tank/export/tank.png ../../spine-cocos2d-objc/Resources/ echo "spine-cocos2dx" rm -f ../../spine-cocos2dx/example/Resources/common/* + +cp -f ../coin/export/coin.json ../../spine-cocos2dx/example/Resources/common/ +cp -f ../coin/export/coin.atlas ../../spine-cocos2dx/example/Resources/common/ +cp -f ../coin/export/coin.png ../../spine-cocos2dx/example/Resources/common/ + cp -f ../goblins/export/goblins-mesh.json ../../spine-cocos2dx/example/Resources/common/ cp -f ../goblins/export/goblins.atlas ../../spine-cocos2dx/example/Resources/common/ cp -f ../goblins/export/goblins.png ../../spine-cocos2dx/example/Resources/common/ diff --git a/spine-c/spine-c-unit-tests/tests/MemoryTestFixture.cpp b/spine-c/spine-c-unit-tests/tests/MemoryTestFixture.cpp index df224718f..dc4694dbd 100755 --- a/spine-c/spine-c-unit-tests/tests/MemoryTestFixture.cpp +++ b/spine-c/spine-c-unit-tests/tests/MemoryTestFixture.cpp @@ -300,10 +300,10 @@ void MemoryTestFixture::skeletonClipper() { spFloatArray_add(uvs, 0); spFloatArray_add(uvs, 0.5f); spFloatArray_add(uvs, 1); - spShortArray* indices = spShortArray_create(16); - spShortArray_add(indices, 0); - spShortArray_add(indices, 1); - spShortArray_add(indices, 2); + spUnsignedShortArray* indices = spUnsignedShortArray_create(16); + spUnsignedShortArray_add(indices, 0); + spUnsignedShortArray_add(indices, 1); + spUnsignedShortArray_add(indices, 2); spSkeletonClipping_clipTriangles(clipping, vertices->items, vertices->size, indices->items, indices->size, uvs->items); @@ -327,7 +327,7 @@ void MemoryTestFixture::skeletonClipper() { spFloatArray_dispose(vertices); spFloatArray_dispose(uvs); - spShortArray_dispose(indices); + spUnsignedShortArray_dispose(indices); spSlotData_dispose(slotData); spSlot_dispose(slot); diff --git a/spine-c/spine-c/include/spine/Array.h b/spine-c/spine-c/include/spine/Array.h index 8bb7c3717..ce8c2bea1 100644 --- a/spine-c/spine-c/include/spine/Array.h +++ b/spine-c/spine-c/include/spine/Array.h @@ -122,6 +122,7 @@ extern "C" { _SP_ARRAY_DECLARE_TYPE(spFloatArray, float) _SP_ARRAY_DECLARE_TYPE(spIntArray, int) _SP_ARRAY_DECLARE_TYPE(spShortArray, short) +_SP_ARRAY_DECLARE_TYPE(spUnsignedShortArray, unsigned short) _SP_ARRAY_DECLARE_TYPE(spArrayFloatArray, spFloatArray*) _SP_ARRAY_DECLARE_TYPE(spArrayShortArray, spShortArray*) diff --git a/spine-c/spine-c/include/spine/SkeletonClipping.h b/spine-c/spine-c/include/spine/SkeletonClipping.h index af147b4b4..d7317fb0c 100644 --- a/spine-c/spine-c/include/spine/SkeletonClipping.h +++ b/spine-c/spine-c/include/spine/SkeletonClipping.h @@ -46,7 +46,7 @@ typedef struct spSkeletonClipping { spFloatArray* clipOutput; spFloatArray* clippedVertices; spFloatArray* clippedUVs; - spShortArray* clippedTriangles; + spUnsignedShortArray* clippedTriangles; spFloatArray* scratch; spClippingAttachment* clipAttachment; spArrayFloatArray* clippingPolygons; @@ -57,7 +57,7 @@ int spSkeletonClipping_clipStart(spSkeletonClipping* self, spSlot* slot, spClipp void spSkeletonClipping_clipEnd(spSkeletonClipping* self, spSlot* slot); void spSkeletonClipping_clipEnd2(spSkeletonClipping* self); int /*boolean*/ spSkeletonClipping_isClipping(spSkeletonClipping* self); -void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, int verticesLength, short* triangles, int trianglesLength, float* uvs); +void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, int verticesLength, unsigned short* triangles, int trianglesLength, float* uvs); void spSkeletonClipping_dispose(spSkeletonClipping* self); #ifdef __cplusplus diff --git a/spine-c/spine-c/src/spine/Array.c b/spine-c/spine-c/src/spine/Array.c index e0d827e6a..03a32bc78 100644 --- a/spine-c/spine-c/src/spine/Array.c +++ b/spine-c/spine-c/src/spine/Array.c @@ -34,5 +34,6 @@ _SP_ARRAY_IMPLEMENT_TYPE(spFloatArray, float) _SP_ARRAY_IMPLEMENT_TYPE(spIntArray, int) _SP_ARRAY_IMPLEMENT_TYPE(spShortArray, short) +_SP_ARRAY_IMPLEMENT_TYPE(spUnsignedShortArray, unsigned short) _SP_ARRAY_IMPLEMENT_TYPE(spArrayFloatArray, spFloatArray*) _SP_ARRAY_IMPLEMENT_TYPE(spArrayShortArray, spShortArray*) diff --git a/spine-c/spine-c/src/spine/SkeletonClipping.c b/spine-c/spine-c/src/spine/SkeletonClipping.c index 5a2c5ddd9..cb503bcf2 100644 --- a/spine-c/spine-c/src/spine/SkeletonClipping.c +++ b/spine-c/spine-c/src/spine/SkeletonClipping.c @@ -39,7 +39,7 @@ spSkeletonClipping* spSkeletonClipping_create() { clipping->clipOutput = spFloatArray_create(128); clipping->clippedVertices = spFloatArray_create(128); clipping->clippedUVs = spFloatArray_create(128); - clipping->clippedTriangles = spShortArray_create(128); + clipping->clippedTriangles = spUnsignedShortArray_create(128); clipping->scratch = spFloatArray_create(128); return clipping; @@ -51,7 +51,7 @@ void spSkeletonClipping_dispose(spSkeletonClipping* self) { spFloatArray_dispose(self->clipOutput); spFloatArray_dispose(self->clippedVertices); spFloatArray_dispose(self->clippedUVs); - spShortArray_dispose(self->clippedTriangles); + spUnsignedShortArray_dispose(self->clippedTriangles); spFloatArray_dispose(self->scratch); FREE(self); } @@ -111,7 +111,7 @@ void spSkeletonClipping_clipEnd2(spSkeletonClipping* self) { self->clippingPolygons = 0; spFloatArray_clear(self->clippedVertices); spFloatArray_clear(self->clippedUVs); - spShortArray_clear(self->clippedTriangles); + spUnsignedShortArray_clear(self->clippedTriangles); spFloatArray_clear(self->clippingPolygon); } @@ -206,12 +206,12 @@ int /*boolean*/ _clip(spSkeletonClipping* self, float x1, float y1, float x2, fl return clipped; } -void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, int verticesLength, short* triangles, int trianglesLength, float* uvs) { +void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, int verticesLength, unsigned short* triangles, int trianglesLength, float* uvs) { int i; spFloatArray* clipOutput = self->clipOutput; spFloatArray* clippedVertices = self->clippedVertices; spFloatArray* clippedUVs = self->clippedUVs; - spShortArray* clippedTriangles = self->clippedTriangles; + spUnsignedShortArray* clippedTriangles = self->clippedTriangles; spFloatArray** polygons = self->clippingPolygons->items; int polygonsCount = self->clippingPolygons->size; int vertexSize = 2; @@ -219,7 +219,7 @@ void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, short index = 0; spFloatArray_clear(clippedVertices); spFloatArray_clear(clippedUVs); - spShortArray_clear(clippedTriangles); + spUnsignedShortArray_clear(clippedTriangles); outer: for (i = 0; i < trianglesLength; i += 3) { int p; @@ -241,7 +241,7 @@ void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, if (_clip(self, x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) { int ii; float d0, d1, d2, d4, d; - short* clippedTrianglesItems; + unsigned short* clippedTrianglesItems; int clipOutputCount; float* clipOutputItems; float* clippedVerticesItems; @@ -271,18 +271,18 @@ void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, } s = clippedTriangles->size; - clippedTrianglesItems = spShortArray_setSize(clippedTriangles, s + 3 * (clipOutputCount - 2))->items; + clippedTrianglesItems = spUnsignedShortArray_setSize(clippedTriangles, s + 3 * (clipOutputCount - 2))->items; clipOutputCount--; for (ii = 1; ii < clipOutputCount; ii++) { clippedTrianglesItems[s] = index; - clippedTrianglesItems[s + 1] = (short)(index + ii); - clippedTrianglesItems[s + 2] = (short)(index + ii + 1); + clippedTrianglesItems[s + 1] = (unsigned short)(index + ii); + clippedTrianglesItems[s + 2] = (unsigned short)(index + ii + 1); s += 3; } index += clipOutputCount + 1; } else { - short* clippedTrianglesItems; + unsigned short* clippedTrianglesItems; float* clippedVerticesItems = spFloatArray_setSize(clippedVertices, s + 3 * vertexSize)->items; float* clippedUVsItems = spFloatArray_setSize(clippedUVs, s + 3 * vertexSize)->items; clippedVerticesItems[s] = x1; @@ -300,10 +300,10 @@ void spSkeletonClipping_clipTriangles(spSkeletonClipping* self, float* vertices, clippedUVsItems[s + 5] = v3; s = clippedTriangles->size; - clippedTrianglesItems = spShortArray_setSize(clippedTriangles, s + 3)->items; + clippedTrianglesItems = spUnsignedShortArray_setSize(clippedTriangles, s + 3)->items; clippedTrianglesItems[s] = index; - clippedTrianglesItems[s + 1] = (short)(index + 1); - clippedTrianglesItems[s + 2] = (short)(index + 2); + clippedTrianglesItems[s + 1] = (unsigned short)(index + 1); + clippedTrianglesItems[s + 2] = (unsigned short)(index + 2); index += 3; goto outer; } diff --git a/spine-cocos2d-objc/Resources/coin.atlas b/spine-cocos2d-objc/Resources/coin.atlas new file mode 100644 index 000000000..bcdb26b10 --- /dev/null +++ b/spine-cocos2d-objc/Resources/coin.atlas @@ -0,0 +1,27 @@ + +coin.png +size: 512,128 +format: RGBA8888 +filter: Linear,Linear +repeat: none +coin + rotate: false + xy: 2, 2 + size: 130, 123 + orig: 130, 123 + offset: 0, 0 + index: -1 +coin-invert + rotate: false + xy: 134, 2 + size: 130, 123 + orig: 130, 123 + offset: 0, 0 + index: -1 +shine + rotate: false + xy: 266, 2 + size: 36, 123 + orig: 36, 123 + offset: 0, 0 + index: -1 diff --git a/spine-cocos2d-objc/Resources/coin.json b/spine-cocos2d-objc/Resources/coin.json new file mode 100644 index 000000000..f678be598 --- /dev/null +++ b/spine-cocos2d-objc/Resources/coin.json @@ -0,0 +1,171 @@ +{ +"skeleton": { "hash": "4cI0KYdFTZbO7vkQYPFQN+yauDw", "spine": "3.6.14-beta", "width": 260, "height": 359.92, "images": "./images/" }, +"bones": [ + { "name": "root" }, + { "name": "coin-root", "parent": "root", "y": 300, "color": "ff0000ff" }, + { "name": "coin", "parent": "coin-root", "color": "ffe037ff" }, + { "name": "clipping", "parent": "coin", "x": 7.25, "scaleX": 0.96, "scaleY": 0.967, "color": "ffe037ff" }, + { "name": "shine", "parent": "coin-root", "rotation": -24.17, "scaleY": 1.478, "color": "ffffffff" } +], +"slots": [ + { "name": "images/coin", "bone": "coin", "attachment": "coin" }, + { "name": "clipping", "bone": "clipping", "attachment": "clipping" }, + { "name": "images/shine", "bone": "shine", "color": "ffffff93", "attachment": "shine", "blend": "additive" } +], +"skins": { + "default": { + "clipping": { + "clipping": { + "type": "clipping", + "end": "images/coin", + "vertexCount": 36, + "vertices": [ 0.82, 120.87, 25.27, 118.4, 49.23, 110.99, 71.46, 98.15, 88.25, 83.08, 102.58, 64.8, 112.21, 46.03, 117.89, 28, 121.35, 9.23, 120.61, -11.52, 117.65, -30.29, 111.72, -48.08, 102.33, -65.61, 89.47, -82.23, 76.24, -94.71, 61.33, -105.13, 46.26, -112.54, 28.73, -118.22, 8.73, -120.89, -12.27, -120.89, -32.03, -116.94, -51.04, -110.27, -67.59, -101.63, -82.91, -88.78, -96.25, -74.21, -108.35, -55.68, -116.5, -35.43, -120.7, -14.19, -121.69, 5.57, -118.97, 27.56, -111.56, 49.04, -100.43, 69.69, -84.38, 87.47, -66.1, 102.29, -45.6, 112.67, -23.62, 118.59 ], + "color": "ce3a3aff" + } + }, + "images/coin": { + "coin": { + "type": "mesh", + "uvs": [ 1, 1, 0.51662, 0.99661, 0.38311, 0.99567, 0.29957, 0.96664, 0.22817, 0.93237, 0.16736, 0.88777, 0.11597, 0.83202, 0.06732, 0.76058, 0.03288, 0.69072, 0.00816, 0.61391, 0, 0.52843, 0, 0.43778, 0.02307, 0.33992, 0.06544, 0.24204, 0.11924, 0.16659, 0.17691, 0.10919, 0.24399, 0.06252, 0.31853, 0.02742, 0.41818, 0.0076, 0.52609, 1.0E-5, 1, 0, 0.45994, 0.99066, 0.37873, 0.97119, 0.30719, 0.94057, 0.24626, 0.89841, 0.19491, 0.85157, 0.14893, 0.79961, 0.11299, 0.73943, 0.08595, 0.67565, 0.06609, 0.60105, 0.05753, 0.52647, 0.05856, 0.44906, 0.07176, 0.36094, 0.10407, 0.28078, 0.15657, 0.19211, 0.22811, 0.1162, 0.29907, 0.0658, 0.38388, 0.02814, 0.46119, 0.00993 ], + "triangles": [ 38, 18, 19, 37, 17, 18, 37, 18, 38, 36, 16, 17, 36, 17, 37, 35, 15, 16, 35, 16, 36, 34, 14, 15, 34, 15, 35, 34, 33, 13, 34, 13, 14, 12, 13, 33, 32, 12, 33, 11, 12, 32, 31, 11, 32, 31, 10, 11, 30, 10, 31, 31, 33, 30, 29, 30, 33, 29, 9, 10, 29, 10, 30, 32, 33, 31, 34, 28, 29, 8, 9, 29, 8, 29, 28, 33, 34, 29, 25, 26, 27, 7, 8, 28, 7, 28, 27, 27, 28, 25, 26, 7, 27, 6, 7, 26, 34, 36, 28, 28, 36, 25, 6, 26, 25, 5, 6, 25, 34, 35, 36, 37, 24, 25, 5, 25, 24, 4, 5, 24, 36, 37, 25, 22, 23, 24, 4, 24, 23, 3, 4, 23, 24, 21, 22, 3, 23, 22, 38, 24, 37, 24, 1, 21, 2, 22, 21, 3, 22, 2, 1, 38, 19, 1, 24, 38, 2, 21, 1, 19, 20, 0, 1, 19, 0 ], + "vertices": [ 130, -123.5, 4.32, -122.66, -30.39, -122.43, -52.11, -115.26, -70.68, -106.8, -86.49, -95.78, -99.85, -82.01, -112.5, -64.36, -121.45, -47.11, -127.88, -28.14, -130, -7.02, -130, 15.37, -124, 39.54, -112.99, 63.72, -99, 82.35, -84, 96.53, -66.56, 108.06, -47.18, 116.73, -21.27, 121.62, 6.78, 123.5, 130, 123.5, -10.42, -121.19, -31.53, -116.39, -50.13, -108.82, -65.97, -98.41, -79.32, -86.84, -91.28, -74, -100.62, -59.14, -107.65, -43.39, -112.82, -24.96, -115.04, -6.54, -114.77, 12.58, -111.34, 34.35, -102.94, 54.15, -89.29, 76.05, -70.69, 94.8, -52.24, 107.25, -30.19, 116.55, -10.09, 121.05 ], + "hull": 21, + "edges": [ 0, 40, 42, 44, 44, 46, 46, 48, 48, 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 36, 34, 34, 32, 32, 30, 30, 28, 28, 26, 26, 24, 24, 22, 20, 22, 20, 18, 18, 16, 16, 14, 14, 12, 12, 10, 10, 8, 8, 6, 6, 4, 0, 2, 2, 4, 42, 2, 38, 40, 36, 38, 76, 38, 2, 38 ], + "width": 259, + "height": 245 + }, + "coin-invert": { + "type": "mesh", + "uvs": [ 0.61921, 0.00932, 0.70137, 0.03058, 0.76675, 0.06301, 0.82357, 0.10192, 0.86533, 0.14084, 0.90128, 0.1866, 0.92763, 0.22768, 0.95707, 0.28353, 0.97795, 0.33937, 0.99074, 0.38663, 1, 0.45194, 1, 0.50671, 1, 0.56148, 0.98993, 0.62238, 0.97282, 0.6757, 0.95125, 0.73083, 0.91771, 0.78704, 0.88283, 0.83498, 0.84141, 0.87966, 0.79349, 0.91785, 0.73701, 0.95172, 0.65999, 0.98127, 0.60659, 0.991, 0.51662, 0.99661, 0, 1, 0, 0, 0.52609, 1.0E-5, 0.57849, 0.98348, 0.64806, 0.96162, 0.70899, 0.92882, 0.75987, 0.89639, 0.80219, 0.85685, 0.83745, 0.81722, 0.86381, 0.77794, 0.89445, 0.72582, 0.9167, 0.67213, 0.93142, 0.61628, 0.94164, 0.56011, 0.94506, 0.50823, 0.9437, 0.45454, 0.93514, 0.39905, 0.91905, 0.34031, 0.89748, 0.28194, 0.8691, 0.2284, 0.83932, 0.18768, 0.79995, 0.143, 0.76298, 0.10841, 0.71814, 0.07598, 0.66748, 0.04824, 0.61408, 0.0277, 0.5665, 0.01437 ], + "triangles": [ 50, 26, 0, 49, 50, 0, 48, 0, 1, 49, 0, 48, 47, 1, 2, 48, 1, 47, 46, 47, 2, 46, 2, 3, 45, 46, 3, 45, 3, 4, 44, 45, 4, 44, 4, 5, 43, 44, 5, 43, 5, 6, 42, 43, 6, 42, 6, 7, 41, 42, 7, 41, 7, 8, 40, 41, 8, 40, 8, 9, 39, 40, 9, 10, 39, 9, 39, 10, 11, 38, 39, 11, 41, 40, 38, 38, 40, 39, 38, 11, 12, 37, 38, 12, 38, 36, 41, 37, 36, 38, 13, 37, 12, 36, 37, 13, 36, 43, 41, 41, 43, 42, 14, 36, 13, 35, 36, 14, 44, 43, 36, 35, 34, 36, 15, 35, 14, 34, 35, 15, 44, 36, 45, 34, 33, 36, 16, 34, 15, 33, 34, 16, 48, 47, 49, 36, 33, 45, 17, 33, 16, 32, 33, 17, 32, 31, 33, 18, 32, 17, 31, 32, 18, 33, 29, 45, 45, 47, 46, 31, 30, 33, 19, 30, 31, 19, 31, 18, 49, 47, 45, 30, 29, 33, 20, 29, 30, 20, 30, 19, 50, 49, 29, 45, 29, 49, 21, 28, 29, 21, 29, 20, 29, 27, 50, 28, 27, 29, 22, 27, 28, 22, 28, 21, 23, 25, 26, 23, 26, 50, 23, 50, 27, 23, 27, 22, 24, 25, 23 ], + "vertices": [ 42.18, 121.2, 63.54, 115.95, 80.54, 107.94, 95.31, 98.32, 106.17, 88.71, 115.51, 77.41, 122.37, 67.26, 130.02, 53.47, 135.45, 39.68, 138.77, 28, 141.18, 11.87, 141.18, -1.66, 141.18, -15.19, 138.56, -30.23, 134.11, -43.4, 128.51, -57.02, 119.79, -70.9, 110.72, -82.74, 99.95, -93.78, 87.49, -103.21, 72.8, -111.58, 52.78, -118.87, 38.9, -121.28, 15.5, -122.66, -118.82, -123.5, -118.82, 123.5, 17.97, 123.5, 31.59, -119.42, 49.68, -114.02, 65.52, -105.92, 78.75, -97.91, 89.75, -88.14, 98.92, -78.35, 105.77, -68.65, 113.74, -55.78, 119.52, -42.52, 123.35, -28.72, 126.01, -14.85, 126.9, -2.03, 126.54, 11.23, 124.32, 24.94, 120.13, 39.44, 114.53, 53.86, 107.15, 67.09, 99.4, 77.14, 89.17, 88.18, 79.56, 96.72, 67.9, 104.73, 54.73, 111.59, 40.84, 116.66, 28.47, 119.95 ], + "hull": 27, + "edges": [ 46, 52, 46, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 76, 78, 78, 80, 80, 82, 82, 84, 84, 86, 86, 88, 88, 90, 90, 92, 92, 94, 94, 96, 96, 98, 98, 100, 100, 52, 52, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 48, 50, 50, 52, 46, 48, 16, 18, 18, 20 ], + "width": 259, + "height": 245 + } + }, + "images/shine": { + "shine": { "width": 72, "height": 245 } + } + } +}, +"animations": { + "rotate": { + "slots": { + "images/coin": { + "attachment": [ + { "time": 0.5, "name": "coin-invert" } + ] + }, + "images/shine": { + "color": [ + { "time": 0, "color": "ffffff00" }, + { "time": 0.2667, "color": "ffffffbc" }, + { "time": 0.5, "color": "ffffff00" }, + { "time": 0.7333, "color": "ffffffbc" }, + { "time": 1, "color": "ffffff00" } + ] + } + }, + "bones": { + "shine": { + "translate": [ + { + "time": 0, + "x": 175.08, + "y": 0, + "curve": [ 0.213, 0.65, 0.931, 0.67 ] + }, + { + "time": 0.5, + "x": -127.2, + "y": 0, + "curve": [ 0.55, 0.09, 0.931, 0.67 ] + }, + { "time": 1, "x": 175.08, "y": 0 } + ], + "scale": [ + { + "time": 0, + "x": 1, + "y": 1, + "curve": [ 0.213, 0.65, 0.931, 0.67 ] + }, + { + "time": 0.5, + "x": 2, + "y": 1, + "curve": [ 0.55, 0.09, 0.931, 0.67 ] + }, + { "time": 1, "x": 1, "y": 1 } + ] + }, + "coin": { + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.5, "x": 0.93, "y": 0 }, + { "time": 0.5011, "x": -9.18, "y": 0 }, + { "time": 1, "x": 2, "y": 0 } + ] + }, + "clipping": { + "translate": [ + { "time": 0, "x": -0.41, "y": 0 }, + { "time": 0.2667, "x": 1.2, "y": 1.21 }, + { "time": 0.5, "x": 0, "y": 0 }, + { "time": 0.7333, "x": -4.15, "y": 0 }, + { "time": 1, "x": -3.16, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 }, + { "time": 0.2667, "x": 0.464, "y": 1.014 }, + { "time": 0.4667, "x": 0.067, "y": 1.002 }, + { "time": 0.5, "x": 0.033, "y": 1 }, + { "time": 0.7333, "x": 0.492, "y": 1.014 }, + { "time": 1, "x": 1, "y": 1 } + ] + } + }, + "deform": { + "default": { + "images/coin": { + "coin": [ + { + "time": 0, + "offset": 4, + "vertices": [ 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598 ] + }, + { + "time": 0.2333, + "vertices": [ -57.61087, 0, 1.15225, 0, 15.20888, 0, 24.26007, 0, 31.99586, 0, 38.58396, 0, 44.15197, 0, 49.42246, 0, 53.15465, 0, 55.83239, 0, 56.71656, 0, 56.71656, 0, 54.21722, 0, 49.62682, 0, 43.79747, 0, 37.5494, 0, 30.28123, 0, 22.2055, 0, 11.40953, 0, 0, 0, -57.61087, 0, 8.04186, 0, 17.91416, 0, 26.61125, 0, 34.01835, 0, 40.26029, 0, 45.85036, 0, 50.21972, 0, 53.50714, 0, 55.9207, 0, 56.96101, 0, 56.83617, 0, 55.23131, 0, 51.30379, 0, 44.9216, 0, 36.22496, 0, 27.59846, 0, 17.28874, 0, 7.89076 ] + }, + { + "time": 0.4667, + "vertices": [ -115.22174, 0, 2.3045, 0, 20.08046, 0, 40.51821, 0, 57.98577, 0, 72.86182, 0, 85.43448, 0, 97.33535, 0, 105.76271, 0, 111.80908, 0, 113.80557, 0, 113.80557, 0, 108.16202, 0, 97.7968, 0, 84.63402, 0, 70.52576, 0, 54.11411, 0, 35.87894, 0, 11.50145, 1.74997, 0, 0, -115.22174, 0, 16.08371, 0, 35.82832, 0, 53.2225, 0, 68.0367, 0, 80.52058, 0, 91.70073, 0, 100.43944, 0, 107.01427, 0, 111.84139, 0, 113.92201, 0, 113.67234, 0, 110.46262, 0, 102.60757, 0, 89.84319, 0, 72.44992, 0, 55.19692, 0, 34.57748, 0, 15.78153 ] + }, + { + "time": 0.5, + "vertices": [ -123.45187, 0, 2.46911, 0, 21.49595, 0, 43.40345, 0, 62.12716, 0, 78.07299, 0, 91.54979, 0, 104.3065, 0, 113.33989, 0, 119.82108, 0, 121.96114, 0, 121.96114, 0, 115.91174, 0, 104.80113, 0, 90.69177, 0, 75.56894, 0, 57.97707, 0, 38.43056, 0, 12.3, 0, 0, 0, -123.45187, 0, 17.23255, 0, 38.38749, 0, 57.02411, 0, 72.89646, 0, 86.27205, 0, 98.25078, 0, 107.61369, 0, 114.65815, 0, 119.83006, 0, 122.0593, 0, 121.79179, 0, 118.35281, 0, 109.93669, 0, 96.26056, 0, 77.62492, 0, 59.13956, 0, 37.0473, 0, 16.90878 ] + } + ], + "coin-invert": [ + { + "time": 0.5, + "vertices": [ -23.47706, 1.27002, -43.40744, 0, -59.7846, 0, -74.77602, 0, -85.79382, 0, -95.27632, 0, -102.23021, 0, -109.99683, 0, -115.50598, 0, -118.87909, 0, -121.32259, 0, -121.32259, 0, -121.32258, 0, -118.66653, 0, -114.15101, 0, -108.4615, 0, -99.61115, 0, -90.41013, 0, -79.48267, 0, -66.83928, 0, -51.93813, 0, -31.61855, 0, -19.56224, -1.52396, -12.52719, 0, 120.72772, 0, 120.72777, 0, -14.97203, 0, -28.48602, 0, -46.43241, 0, -62.14667, 0, -75.27165, 0, -86.18799, 0, -95.28229, 0, -102.08092, 0, -109.98608, 0, -115.7252, 0, -119.52184, 0, -122.15746, 0, -123.04041, 0, -122.68725, 0, -120.4799, 0, -116.33008, 0, -110.76754, 0, -103.44593, 0, -95.76433, 0, -85.61052, 0, -76.07477, 0, -64.50826, 0, -51.44074, 0, -37.66688, 0, -25.39402 ] + }, + { + "time": 0.7667, + "vertices": [ -12.2558, 0, -21.82668, 0, -29.4435, 0, -36.06335, 0, -40.92855, 0, -45.1158, 0, -48.18647, 0, -51.61602, 0, -54.04874, 0, -55.53822, 0, -56.61722, 0, -56.61722, 0, -56.61721, 0, -55.44436, 0, -53.45041, 0, -50.93806, 0, -47.02994, 0, -42.967, 0, -38.1417, 0, -32.55868, 0, -25.97868, 0, -17.00604, 0, -10.78498, 0, -5.84602, 0, 56.33961, 0, 56.33963, 0, -6.98695, 0, -13.29348, 0, -21.66846, 0, -29.00178, 0, -35.12677, 0, -40.22107, 0, -44.46507, 0, -47.63776, 0, -51.32684, 0, -54.0051, 0, -55.77686, 0, -57.00682, 0, -57.41886, 0, -57.25405, 0, -56.22396, 0, -54.28737, 0, -51.69152, 0, -48.27477, 0, -44.69002, 0, -39.95158, 0, -35.50156, 0, -30.10386, 0, -24.00568, 0, -17.57788, 0, -11.85054 ] + }, + { + "time": 1, + "vertices": [ -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001 ] + } + ] + } + } + } + } +} +} \ No newline at end of file diff --git a/spine-cocos2d-objc/Resources/coin.png b/spine-cocos2d-objc/Resources/coin.png new file mode 100644 index 000000000..f5ea3ad0d Binary files /dev/null and b/spine-cocos2d-objc/Resources/coin.png differ diff --git a/spine-cocos2dx/example/Classes/CoinExample.cpp b/spine-cocos2dx/example/Classes/CoinExample.cpp new file mode 100644 index 000000000..a7cbc62a1 --- /dev/null +++ b/spine-cocos2dx/example/Classes/CoinExample.cpp @@ -0,0 +1,67 @@ +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF + * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include "CoinExample.h" +#include "BatchingExample.h" + +USING_NS_CC; +using namespace spine; + +Scene* CoinExample::scene () { + Scene *scene = Scene::create(); + scene->addChild(CoinExample::create()); + return scene; +} + +bool CoinExample::init () { + if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false; + + skeletonNode = SkeletonAnimation::createWithJsonFile("coin.json", "coin.atlas", 0.5f); + skeletonNode->setAnimation(0, "rotate", true); + + skeletonNode->setPosition(Vec2(_contentSize.width / 2, 150)); + addChild(skeletonNode); + + scheduleUpdate(); + + EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); + listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool { + if (!skeletonNode->getDebugBonesEnabled()) + skeletonNode->setDebugBonesEnabled(true); + else if (skeletonNode->getTimeScale() == 1) + skeletonNode->setTimeScale(0.3f); + else + Director::getInstance()->replaceScene(BatchingExample::scene()); + return true; + }; + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); + + return true; +} diff --git a/spine-cocos2dx/example/Classes/CoinExample.h b/spine-cocos2dx/example/Classes/CoinExample.h new file mode 100644 index 000000000..448978e3f --- /dev/null +++ b/spine-cocos2dx/example/Classes/CoinExample.h @@ -0,0 +1,49 @@ +/****************************************************************************** + * Spine Runtimes Software License v2.5 + * + * Copyright (c) 2013-2016, Esoteric Software + * All rights reserved. + * + * You are granted a perpetual, non-exclusive, non-sublicensable, and + * non-transferable license to use, install, execute, and perform the Spine + * Runtimes software and derivative works solely for personal or internal + * use. Without the written permission of Esoteric Software (see Section 2 of + * the Spine Software License Agreement), you may not (a) modify, translate, + * adapt, or develop new applications using the Spine Runtimes or otherwise + * create derivative works or improvements of the Spine Runtimes or (b) remove, + * delete, alter, or obscure any trademarks or any copyright, trademark, patent, + * or other intellectual property or proprietary rights notices on or in the + * Software, including any copy thereof. Redistributions in binary or source + * form must include this license and terms. + * + * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF + * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#ifndef _COINEXAMPLE_H_ +#define _COINEXAMPLE_H_ + +#include "cocos2d.h" +#include + +class CoinExample : public cocos2d::LayerColor { +public: + static cocos2d::Scene* scene (); + + CREATE_FUNC(CoinExample); + + virtual bool init (); + +private: + spine::SkeletonAnimation* skeletonNode; +}; + +#endif // _COINXAMPLE_H_ diff --git a/spine-cocos2dx/example/Classes/TankExample.cpp b/spine-cocos2dx/example/Classes/TankExample.cpp index 30fb80932..5679b6c49 100644 --- a/spine-cocos2dx/example/Classes/TankExample.cpp +++ b/spine-cocos2dx/example/Classes/TankExample.cpp @@ -29,7 +29,7 @@ *****************************************************************************/ #include "TankExample.h" -#include "BatchingExample.h" +#include "CoinExample.h" USING_NS_CC; using namespace spine; @@ -58,7 +58,7 @@ bool TankExample::init () { else if (skeletonNode->getTimeScale() == 1) skeletonNode->setTimeScale(0.3f); else - Director::getInstance()->replaceScene(BatchingExample::scene()); + Director::getInstance()->replaceScene(CoinExample::scene()); return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); diff --git a/spine-cocos2dx/example/Resources/common/coin.atlas b/spine-cocos2dx/example/Resources/common/coin.atlas new file mode 100644 index 000000000..bcdb26b10 --- /dev/null +++ b/spine-cocos2dx/example/Resources/common/coin.atlas @@ -0,0 +1,27 @@ + +coin.png +size: 512,128 +format: RGBA8888 +filter: Linear,Linear +repeat: none +coin + rotate: false + xy: 2, 2 + size: 130, 123 + orig: 130, 123 + offset: 0, 0 + index: -1 +coin-invert + rotate: false + xy: 134, 2 + size: 130, 123 + orig: 130, 123 + offset: 0, 0 + index: -1 +shine + rotate: false + xy: 266, 2 + size: 36, 123 + orig: 36, 123 + offset: 0, 0 + index: -1 diff --git a/spine-cocos2dx/example/Resources/common/coin.json b/spine-cocos2dx/example/Resources/common/coin.json new file mode 100644 index 000000000..f678be598 --- /dev/null +++ b/spine-cocos2dx/example/Resources/common/coin.json @@ -0,0 +1,171 @@ +{ +"skeleton": { "hash": "4cI0KYdFTZbO7vkQYPFQN+yauDw", "spine": "3.6.14-beta", "width": 260, "height": 359.92, "images": "./images/" }, +"bones": [ + { "name": "root" }, + { "name": "coin-root", "parent": "root", "y": 300, "color": "ff0000ff" }, + { "name": "coin", "parent": "coin-root", "color": "ffe037ff" }, + { "name": "clipping", "parent": "coin", "x": 7.25, "scaleX": 0.96, "scaleY": 0.967, "color": "ffe037ff" }, + { "name": "shine", "parent": "coin-root", "rotation": -24.17, "scaleY": 1.478, "color": "ffffffff" } +], +"slots": [ + { "name": "images/coin", "bone": "coin", "attachment": "coin" }, + { "name": "clipping", "bone": "clipping", "attachment": "clipping" }, + { "name": "images/shine", "bone": "shine", "color": "ffffff93", "attachment": "shine", "blend": "additive" } +], +"skins": { + "default": { + "clipping": { + "clipping": { + "type": "clipping", + "end": "images/coin", + "vertexCount": 36, + "vertices": [ 0.82, 120.87, 25.27, 118.4, 49.23, 110.99, 71.46, 98.15, 88.25, 83.08, 102.58, 64.8, 112.21, 46.03, 117.89, 28, 121.35, 9.23, 120.61, -11.52, 117.65, -30.29, 111.72, -48.08, 102.33, -65.61, 89.47, -82.23, 76.24, -94.71, 61.33, -105.13, 46.26, -112.54, 28.73, -118.22, 8.73, -120.89, -12.27, -120.89, -32.03, -116.94, -51.04, -110.27, -67.59, -101.63, -82.91, -88.78, -96.25, -74.21, -108.35, -55.68, -116.5, -35.43, -120.7, -14.19, -121.69, 5.57, -118.97, 27.56, -111.56, 49.04, -100.43, 69.69, -84.38, 87.47, -66.1, 102.29, -45.6, 112.67, -23.62, 118.59 ], + "color": "ce3a3aff" + } + }, + "images/coin": { + "coin": { + "type": "mesh", + "uvs": [ 1, 1, 0.51662, 0.99661, 0.38311, 0.99567, 0.29957, 0.96664, 0.22817, 0.93237, 0.16736, 0.88777, 0.11597, 0.83202, 0.06732, 0.76058, 0.03288, 0.69072, 0.00816, 0.61391, 0, 0.52843, 0, 0.43778, 0.02307, 0.33992, 0.06544, 0.24204, 0.11924, 0.16659, 0.17691, 0.10919, 0.24399, 0.06252, 0.31853, 0.02742, 0.41818, 0.0076, 0.52609, 1.0E-5, 1, 0, 0.45994, 0.99066, 0.37873, 0.97119, 0.30719, 0.94057, 0.24626, 0.89841, 0.19491, 0.85157, 0.14893, 0.79961, 0.11299, 0.73943, 0.08595, 0.67565, 0.06609, 0.60105, 0.05753, 0.52647, 0.05856, 0.44906, 0.07176, 0.36094, 0.10407, 0.28078, 0.15657, 0.19211, 0.22811, 0.1162, 0.29907, 0.0658, 0.38388, 0.02814, 0.46119, 0.00993 ], + "triangles": [ 38, 18, 19, 37, 17, 18, 37, 18, 38, 36, 16, 17, 36, 17, 37, 35, 15, 16, 35, 16, 36, 34, 14, 15, 34, 15, 35, 34, 33, 13, 34, 13, 14, 12, 13, 33, 32, 12, 33, 11, 12, 32, 31, 11, 32, 31, 10, 11, 30, 10, 31, 31, 33, 30, 29, 30, 33, 29, 9, 10, 29, 10, 30, 32, 33, 31, 34, 28, 29, 8, 9, 29, 8, 29, 28, 33, 34, 29, 25, 26, 27, 7, 8, 28, 7, 28, 27, 27, 28, 25, 26, 7, 27, 6, 7, 26, 34, 36, 28, 28, 36, 25, 6, 26, 25, 5, 6, 25, 34, 35, 36, 37, 24, 25, 5, 25, 24, 4, 5, 24, 36, 37, 25, 22, 23, 24, 4, 24, 23, 3, 4, 23, 24, 21, 22, 3, 23, 22, 38, 24, 37, 24, 1, 21, 2, 22, 21, 3, 22, 2, 1, 38, 19, 1, 24, 38, 2, 21, 1, 19, 20, 0, 1, 19, 0 ], + "vertices": [ 130, -123.5, 4.32, -122.66, -30.39, -122.43, -52.11, -115.26, -70.68, -106.8, -86.49, -95.78, -99.85, -82.01, -112.5, -64.36, -121.45, -47.11, -127.88, -28.14, -130, -7.02, -130, 15.37, -124, 39.54, -112.99, 63.72, -99, 82.35, -84, 96.53, -66.56, 108.06, -47.18, 116.73, -21.27, 121.62, 6.78, 123.5, 130, 123.5, -10.42, -121.19, -31.53, -116.39, -50.13, -108.82, -65.97, -98.41, -79.32, -86.84, -91.28, -74, -100.62, -59.14, -107.65, -43.39, -112.82, -24.96, -115.04, -6.54, -114.77, 12.58, -111.34, 34.35, -102.94, 54.15, -89.29, 76.05, -70.69, 94.8, -52.24, 107.25, -30.19, 116.55, -10.09, 121.05 ], + "hull": 21, + "edges": [ 0, 40, 42, 44, 44, 46, 46, 48, 48, 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 36, 34, 34, 32, 32, 30, 30, 28, 28, 26, 26, 24, 24, 22, 20, 22, 20, 18, 18, 16, 16, 14, 14, 12, 12, 10, 10, 8, 8, 6, 6, 4, 0, 2, 2, 4, 42, 2, 38, 40, 36, 38, 76, 38, 2, 38 ], + "width": 259, + "height": 245 + }, + "coin-invert": { + "type": "mesh", + "uvs": [ 0.61921, 0.00932, 0.70137, 0.03058, 0.76675, 0.06301, 0.82357, 0.10192, 0.86533, 0.14084, 0.90128, 0.1866, 0.92763, 0.22768, 0.95707, 0.28353, 0.97795, 0.33937, 0.99074, 0.38663, 1, 0.45194, 1, 0.50671, 1, 0.56148, 0.98993, 0.62238, 0.97282, 0.6757, 0.95125, 0.73083, 0.91771, 0.78704, 0.88283, 0.83498, 0.84141, 0.87966, 0.79349, 0.91785, 0.73701, 0.95172, 0.65999, 0.98127, 0.60659, 0.991, 0.51662, 0.99661, 0, 1, 0, 0, 0.52609, 1.0E-5, 0.57849, 0.98348, 0.64806, 0.96162, 0.70899, 0.92882, 0.75987, 0.89639, 0.80219, 0.85685, 0.83745, 0.81722, 0.86381, 0.77794, 0.89445, 0.72582, 0.9167, 0.67213, 0.93142, 0.61628, 0.94164, 0.56011, 0.94506, 0.50823, 0.9437, 0.45454, 0.93514, 0.39905, 0.91905, 0.34031, 0.89748, 0.28194, 0.8691, 0.2284, 0.83932, 0.18768, 0.79995, 0.143, 0.76298, 0.10841, 0.71814, 0.07598, 0.66748, 0.04824, 0.61408, 0.0277, 0.5665, 0.01437 ], + "triangles": [ 50, 26, 0, 49, 50, 0, 48, 0, 1, 49, 0, 48, 47, 1, 2, 48, 1, 47, 46, 47, 2, 46, 2, 3, 45, 46, 3, 45, 3, 4, 44, 45, 4, 44, 4, 5, 43, 44, 5, 43, 5, 6, 42, 43, 6, 42, 6, 7, 41, 42, 7, 41, 7, 8, 40, 41, 8, 40, 8, 9, 39, 40, 9, 10, 39, 9, 39, 10, 11, 38, 39, 11, 41, 40, 38, 38, 40, 39, 38, 11, 12, 37, 38, 12, 38, 36, 41, 37, 36, 38, 13, 37, 12, 36, 37, 13, 36, 43, 41, 41, 43, 42, 14, 36, 13, 35, 36, 14, 44, 43, 36, 35, 34, 36, 15, 35, 14, 34, 35, 15, 44, 36, 45, 34, 33, 36, 16, 34, 15, 33, 34, 16, 48, 47, 49, 36, 33, 45, 17, 33, 16, 32, 33, 17, 32, 31, 33, 18, 32, 17, 31, 32, 18, 33, 29, 45, 45, 47, 46, 31, 30, 33, 19, 30, 31, 19, 31, 18, 49, 47, 45, 30, 29, 33, 20, 29, 30, 20, 30, 19, 50, 49, 29, 45, 29, 49, 21, 28, 29, 21, 29, 20, 29, 27, 50, 28, 27, 29, 22, 27, 28, 22, 28, 21, 23, 25, 26, 23, 26, 50, 23, 50, 27, 23, 27, 22, 24, 25, 23 ], + "vertices": [ 42.18, 121.2, 63.54, 115.95, 80.54, 107.94, 95.31, 98.32, 106.17, 88.71, 115.51, 77.41, 122.37, 67.26, 130.02, 53.47, 135.45, 39.68, 138.77, 28, 141.18, 11.87, 141.18, -1.66, 141.18, -15.19, 138.56, -30.23, 134.11, -43.4, 128.51, -57.02, 119.79, -70.9, 110.72, -82.74, 99.95, -93.78, 87.49, -103.21, 72.8, -111.58, 52.78, -118.87, 38.9, -121.28, 15.5, -122.66, -118.82, -123.5, -118.82, 123.5, 17.97, 123.5, 31.59, -119.42, 49.68, -114.02, 65.52, -105.92, 78.75, -97.91, 89.75, -88.14, 98.92, -78.35, 105.77, -68.65, 113.74, -55.78, 119.52, -42.52, 123.35, -28.72, 126.01, -14.85, 126.9, -2.03, 126.54, 11.23, 124.32, 24.94, 120.13, 39.44, 114.53, 53.86, 107.15, 67.09, 99.4, 77.14, 89.17, 88.18, 79.56, 96.72, 67.9, 104.73, 54.73, 111.59, 40.84, 116.66, 28.47, 119.95 ], + "hull": 27, + "edges": [ 46, 52, 46, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 74, 74, 76, 76, 78, 78, 80, 80, 82, 82, 84, 84, 86, 86, 88, 88, 90, 90, 92, 92, 94, 94, 96, 96, 98, 98, 100, 100, 52, 52, 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, 30, 32, 32, 34, 34, 36, 36, 38, 38, 40, 40, 42, 42, 44, 44, 46, 48, 50, 50, 52, 46, 48, 16, 18, 18, 20 ], + "width": 259, + "height": 245 + } + }, + "images/shine": { + "shine": { "width": 72, "height": 245 } + } + } +}, +"animations": { + "rotate": { + "slots": { + "images/coin": { + "attachment": [ + { "time": 0.5, "name": "coin-invert" } + ] + }, + "images/shine": { + "color": [ + { "time": 0, "color": "ffffff00" }, + { "time": 0.2667, "color": "ffffffbc" }, + { "time": 0.5, "color": "ffffff00" }, + { "time": 0.7333, "color": "ffffffbc" }, + { "time": 1, "color": "ffffff00" } + ] + } + }, + "bones": { + "shine": { + "translate": [ + { + "time": 0, + "x": 175.08, + "y": 0, + "curve": [ 0.213, 0.65, 0.931, 0.67 ] + }, + { + "time": 0.5, + "x": -127.2, + "y": 0, + "curve": [ 0.55, 0.09, 0.931, 0.67 ] + }, + { "time": 1, "x": 175.08, "y": 0 } + ], + "scale": [ + { + "time": 0, + "x": 1, + "y": 1, + "curve": [ 0.213, 0.65, 0.931, 0.67 ] + }, + { + "time": 0.5, + "x": 2, + "y": 1, + "curve": [ 0.55, 0.09, 0.931, 0.67 ] + }, + { "time": 1, "x": 1, "y": 1 } + ] + }, + "coin": { + "translate": [ + { "time": 0, "x": 0, "y": 0 }, + { "time": 0.5, "x": 0.93, "y": 0 }, + { "time": 0.5011, "x": -9.18, "y": 0 }, + { "time": 1, "x": 2, "y": 0 } + ] + }, + "clipping": { + "translate": [ + { "time": 0, "x": -0.41, "y": 0 }, + { "time": 0.2667, "x": 1.2, "y": 1.21 }, + { "time": 0.5, "x": 0, "y": 0 }, + { "time": 0.7333, "x": -4.15, "y": 0 }, + { "time": 1, "x": -3.16, "y": 0 } + ], + "scale": [ + { "time": 0, "x": 1, "y": 1 }, + { "time": 0.2667, "x": 0.464, "y": 1.014 }, + { "time": 0.4667, "x": 0.067, "y": 1.002 }, + { "time": 0.5, "x": 0.033, "y": 1 }, + { "time": 0.7333, "x": 0.492, "y": 1.014 }, + { "time": 1, "x": 1, "y": 1 } + ] + } + }, + "deform": { + "default": { + "images/coin": { + "coin": [ + { + "time": 0, + "offset": 4, + "vertices": [ 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598, 0, 15.75598 ] + }, + { + "time": 0.2333, + "vertices": [ -57.61087, 0, 1.15225, 0, 15.20888, 0, 24.26007, 0, 31.99586, 0, 38.58396, 0, 44.15197, 0, 49.42246, 0, 53.15465, 0, 55.83239, 0, 56.71656, 0, 56.71656, 0, 54.21722, 0, 49.62682, 0, 43.79747, 0, 37.5494, 0, 30.28123, 0, 22.2055, 0, 11.40953, 0, 0, 0, -57.61087, 0, 8.04186, 0, 17.91416, 0, 26.61125, 0, 34.01835, 0, 40.26029, 0, 45.85036, 0, 50.21972, 0, 53.50714, 0, 55.9207, 0, 56.96101, 0, 56.83617, 0, 55.23131, 0, 51.30379, 0, 44.9216, 0, 36.22496, 0, 27.59846, 0, 17.28874, 0, 7.89076 ] + }, + { + "time": 0.4667, + "vertices": [ -115.22174, 0, 2.3045, 0, 20.08046, 0, 40.51821, 0, 57.98577, 0, 72.86182, 0, 85.43448, 0, 97.33535, 0, 105.76271, 0, 111.80908, 0, 113.80557, 0, 113.80557, 0, 108.16202, 0, 97.7968, 0, 84.63402, 0, 70.52576, 0, 54.11411, 0, 35.87894, 0, 11.50145, 1.74997, 0, 0, -115.22174, 0, 16.08371, 0, 35.82832, 0, 53.2225, 0, 68.0367, 0, 80.52058, 0, 91.70073, 0, 100.43944, 0, 107.01427, 0, 111.84139, 0, 113.92201, 0, 113.67234, 0, 110.46262, 0, 102.60757, 0, 89.84319, 0, 72.44992, 0, 55.19692, 0, 34.57748, 0, 15.78153 ] + }, + { + "time": 0.5, + "vertices": [ -123.45187, 0, 2.46911, 0, 21.49595, 0, 43.40345, 0, 62.12716, 0, 78.07299, 0, 91.54979, 0, 104.3065, 0, 113.33989, 0, 119.82108, 0, 121.96114, 0, 121.96114, 0, 115.91174, 0, 104.80113, 0, 90.69177, 0, 75.56894, 0, 57.97707, 0, 38.43056, 0, 12.3, 0, 0, 0, -123.45187, 0, 17.23255, 0, 38.38749, 0, 57.02411, 0, 72.89646, 0, 86.27205, 0, 98.25078, 0, 107.61369, 0, 114.65815, 0, 119.83006, 0, 122.0593, 0, 121.79179, 0, 118.35281, 0, 109.93669, 0, 96.26056, 0, 77.62492, 0, 59.13956, 0, 37.0473, 0, 16.90878 ] + } + ], + "coin-invert": [ + { + "time": 0.5, + "vertices": [ -23.47706, 1.27002, -43.40744, 0, -59.7846, 0, -74.77602, 0, -85.79382, 0, -95.27632, 0, -102.23021, 0, -109.99683, 0, -115.50598, 0, -118.87909, 0, -121.32259, 0, -121.32259, 0, -121.32258, 0, -118.66653, 0, -114.15101, 0, -108.4615, 0, -99.61115, 0, -90.41013, 0, -79.48267, 0, -66.83928, 0, -51.93813, 0, -31.61855, 0, -19.56224, -1.52396, -12.52719, 0, 120.72772, 0, 120.72777, 0, -14.97203, 0, -28.48602, 0, -46.43241, 0, -62.14667, 0, -75.27165, 0, -86.18799, 0, -95.28229, 0, -102.08092, 0, -109.98608, 0, -115.7252, 0, -119.52184, 0, -122.15746, 0, -123.04041, 0, -122.68725, 0, -120.4799, 0, -116.33008, 0, -110.76754, 0, -103.44593, 0, -95.76433, 0, -85.61052, 0, -76.07477, 0, -64.50826, 0, -51.44074, 0, -37.66688, 0, -25.39402 ] + }, + { + "time": 0.7667, + "vertices": [ -12.2558, 0, -21.82668, 0, -29.4435, 0, -36.06335, 0, -40.92855, 0, -45.1158, 0, -48.18647, 0, -51.61602, 0, -54.04874, 0, -55.53822, 0, -56.61722, 0, -56.61722, 0, -56.61721, 0, -55.44436, 0, -53.45041, 0, -50.93806, 0, -47.02994, 0, -42.967, 0, -38.1417, 0, -32.55868, 0, -25.97868, 0, -17.00604, 0, -10.78498, 0, -5.84602, 0, 56.33961, 0, 56.33963, 0, -6.98695, 0, -13.29348, 0, -21.66846, 0, -29.00178, 0, -35.12677, 0, -40.22107, 0, -44.46507, 0, -47.63776, 0, -51.32684, 0, -54.0051, 0, -55.77686, 0, -57.00682, 0, -57.41886, 0, -57.25405, 0, -56.22396, 0, -54.28737, 0, -51.69152, 0, -48.27477, 0, -44.69002, 0, -39.95158, 0, -35.50156, 0, -30.10386, 0, -24.00568, 0, -17.57788, 0, -11.85054 ] + }, + { + "time": 1, + "vertices": [ -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001, 0, -17.76001 ] + } + ] + } + } + } + } +} +} \ No newline at end of file diff --git a/spine-cocos2dx/example/Resources/common/coin.png b/spine-cocos2dx/example/Resources/common/coin.png new file mode 100644 index 000000000..f5ea3ad0d Binary files /dev/null and b/spine-cocos2dx/example/Resources/common/coin.png differ diff --git a/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj b/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj index 3b8ff2383..f3ca62892 100644 --- a/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj +++ b/spine-cocos2dx/example/proj.ios_mac/spine-cocos2d-x.xcodeproj/project.pbxproj @@ -87,6 +87,16 @@ 76AAA4471D1811B000C54FCB /* SpineboyExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */; }; 76AAA4571D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; }; 76AAA4581D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; }; + 76D520DA1EB3611300572471 /* ClippingAttachment.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D71EB3611300572471 /* ClippingAttachment.c */; }; + 76D520DB1EB3611300572471 /* SkeletonClipping.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D81EB3611300572471 /* SkeletonClipping.c */; }; + 76D520DC1EB3611300572471 /* Triangulator.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D91EB3611300572471 /* Triangulator.c */; }; + 76D520DE1EB3619800572471 /* ClippingAttachment.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D71EB3611300572471 /* ClippingAttachment.c */; }; + 76D520DF1EB3619800572471 /* SkeletonClipping.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D81EB3611300572471 /* SkeletonClipping.c */; }; + 76D520E01EB3619800572471 /* Triangulator.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D91EB3611300572471 /* Triangulator.c */; }; + 76D520E21EB3625700572471 /* Array.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520E11EB3625700572471 /* Array.c */; }; + 76D520E31EB3625B00572471 /* Array.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520E11EB3625700572471 /* Array.c */; }; + 76D520E61EB362DD00572471 /* CoinExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76D520E41EB362DD00572471 /* CoinExample.cpp */; }; + 76D520E71EB3634600572471 /* CoinExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76D520E41EB362DD00572471 /* CoinExample.cpp */; }; 76F28CB11DEC7EBB00CDE54D /* Animation.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28C8F1DEC7EBA00CDE54D /* Animation.c */; }; 76F28CB21DEC7EBB00CDE54D /* AnimationState.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28C901DEC7EBA00CDE54D /* AnimationState.c */; }; 76F28CB31DEC7EBB00CDE54D /* AnimationStateData.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28C911DEC7EBA00CDE54D /* AnimationStateData.c */; }; @@ -281,6 +291,12 @@ 76AAA40A1D18106000C54FCB /* spine-cocos2dx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "spine-cocos2dx.cpp"; path = "../../src/spine/spine-cocos2dx.cpp"; sourceTree = ""; }; 76AAA40B1D18106000C54FCB /* spine-cocos2dx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "spine-cocos2dx.h"; path = "../../src/spine/spine-cocos2dx.h"; sourceTree = ""; }; 76AAA4521D18132D00C54FCB /* common */ = {isa = PBXFileReference; lastKnownFileType = folder; path = common; sourceTree = ""; }; + 76D520D71EB3611300572471 /* ClippingAttachment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ClippingAttachment.c; path = "../../../spine-c/spine-c/src/spine/ClippingAttachment.c"; sourceTree = ""; }; + 76D520D81EB3611300572471 /* SkeletonClipping.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SkeletonClipping.c; path = "../../../spine-c/spine-c/src/spine/SkeletonClipping.c"; sourceTree = ""; }; + 76D520D91EB3611300572471 /* Triangulator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Triangulator.c; path = "../../../spine-c/spine-c/src/spine/Triangulator.c"; sourceTree = ""; }; + 76D520E11EB3625700572471 /* Array.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Array.c; path = "../../../spine-c/spine-c/src/spine/Array.c"; sourceTree = ""; }; + 76D520E41EB362DD00572471 /* CoinExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CoinExample.cpp; sourceTree = ""; }; + 76D520E51EB362DD00572471 /* CoinExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoinExample.h; sourceTree = ""; }; 76F28C8F1DEC7EBA00CDE54D /* Animation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Animation.c; path = "../../../spine-c/spine-c/src/spine/Animation.c"; sourceTree = ""; }; 76F28C901DEC7EBA00CDE54D /* AnimationState.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = AnimationState.c; path = "../../../spine-c/spine-c/src/spine/AnimationState.c"; sourceTree = ""; }; 76F28C911DEC7EBA00CDE54D /* AnimationStateData.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = AnimationStateData.c; path = "../../../spine-c/spine-c/src/spine/AnimationStateData.c"; sourceTree = ""; }; @@ -464,6 +480,8 @@ 46880B8319C43A87006E1F66 /* Classes */ = { isa = PBXGroup; children = ( + 76D520E41EB362DD00572471 /* CoinExample.cpp */, + 76D520E51EB362DD00572471 /* CoinExample.h */, 76F5BD531D2BD7D3005917E5 /* TankExample.cpp */, 76F5BD541D2BD7D3005917E5 /* TankExample.h */, 76AAA3B31D180F7C00C54FCB /* AppDelegate.cpp */, @@ -534,6 +552,10 @@ 76AAA3B21D180F7300C54FCB /* spine */ = { isa = PBXGroup; children = ( + 76D520E11EB3625700572471 /* Array.c */, + 76D520D71EB3611300572471 /* ClippingAttachment.c */, + 76D520D81EB3611300572471 /* SkeletonClipping.c */, + 76D520D91EB3611300572471 /* Triangulator.c */, 76FAC18A1E3F97D2001CCC8C /* Color.c */, 76FAC18B1E3F97D2001CCC8C /* PointAttachment.c */, 76F28C8F1DEC7EBA00CDE54D /* Animation.c */, @@ -742,6 +764,7 @@ 76F5BD551D2BD7D3005917E5 /* TankExample.cpp in Sources */, 76F28CCC1DEC7EBB00CDE54D /* Slot.c in Sources */, 76F28CB31DEC7EBB00CDE54D /* AnimationStateData.c in Sources */, + 76D520E21EB3625700572471 /* Array.c in Sources */, 76F28CBE1DEC7EBB00CDE54D /* IkConstraint.c in Sources */, 76AAA3C51D180F7C00C54FCB /* SpineboyExample.cpp in Sources */, 76AAA3C11D180F7C00C54FCB /* BatchingExample.cpp in Sources */, @@ -775,17 +798,21 @@ 76F28CB91DEC7EBB00CDE54D /* BoneData.c in Sources */, 76AAA3C21D180F7C00C54FCB /* GoblinsExample.cpp in Sources */, 76F28CC91DEC7EBB00CDE54D /* SkeletonData.c in Sources */, + 76D520DA1EB3611300572471 /* ClippingAttachment.c in Sources */, 76F28CC41DEC7EBB00CDE54D /* PathConstraintData.c in Sources */, 76F28CB81DEC7EBB00CDE54D /* Bone.c in Sources */, 76F28CB61DEC7EBB00CDE54D /* Attachment.c in Sources */, 503AE10217EB989F00D1A890 /* RootViewController.mm in Sources */, 503AE10117EB989F00D1A890 /* main.m in Sources */, + 76D520DB1EB3611300572471 /* SkeletonClipping.c in Sources */, 76F28CCB1DEC7EBB00CDE54D /* Skin.c in Sources */, 76A45BDE1E64396800745AA1 /* SkeletonTwoColorBatch.cpp in Sources */, 76F28CBF1DEC7EBB00CDE54D /* IkConstraintData.c in Sources */, 76F28CC61DEC7EBB00CDE54D /* Skeleton.c in Sources */, 76AAA4101D18106000C54FCB /* SkeletonRenderer.cpp in Sources */, + 76D520E61EB362DD00572471 /* CoinExample.cpp in Sources */, 76FAC18C1E3F97D2001CCC8C /* Color.c in Sources */, + 76D520DC1EB3611300572471 /* Triangulator.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -793,6 +820,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 76D520E71EB3634600572471 /* CoinExample.cpp in Sources */, + 76D520E31EB3625B00572471 /* Array.c in Sources */, + 76D520DE1EB3619800572471 /* ClippingAttachment.c in Sources */, + 76D520DF1EB3619800572471 /* SkeletonClipping.c in Sources */, + 76D520E01EB3619800572471 /* Triangulator.c in Sources */, 76FAC18F1E3F98A0001CCC8C /* Color.c in Sources */, 76FAC1901E3F98A0001CCC8C /* PointAttachment.c in Sources */, 76F28CD11DEC7FFA00CDE54D /* Animation.c in Sources */, diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index 3d86af56c..1f51e5e20 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -62,6 +62,8 @@ SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonD void SkeletonRenderer::initialize () { _worldVertices = new float[1000]; // Max number of vertices per mesh. + + _clipper = spSkeletonClipping_create(); _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setOpacityModifyRGB(true); @@ -99,6 +101,7 @@ SkeletonRenderer::~SkeletonRenderer () { if (_atlas) spAtlas_dispose(_atlas); if (_attachmentLoader) spAttachmentLoader_dispose(_attachmentLoader); delete [] _worldVertices; + spSkeletonClipping_dispose(_clipper); } void SkeletonRenderer::initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) { @@ -275,6 +278,10 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t } break; } + case SP_ATTACHMENT_CLIPPING: { + spClippingAttachment* clip = (spClippingAttachment*)slot->attachment; + spSkeletonClipping_clipStart(_clipper, slot, clip); + } default: continue; } @@ -329,7 +336,9 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t vertex->color2.a = 1; } } + spSkeletonClipping_clipEnd(_clipper, slot); } + spSkeletonClipping_clipEnd2(_clipper); if (lastTwoColorTrianglesCommand) { Node* parent = this->getParent(); diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.h b/spine-cocos2dx/src/spine/SkeletonRenderer.h index 6fadc69aa..99988af93 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.h +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.h @@ -139,6 +139,7 @@ protected: bool _debugSlots; bool _debugBones; bool _debugMeshes; + spSkeletonClipping* _clipper; }; } diff --git a/spine-sfml/example/main.cpp b/spine-sfml/example/main.cpp index 78a706af5..0e29588c9 100644 --- a/spine-sfml/example/main.cpp +++ b/spine-sfml/example/main.cpp @@ -385,11 +385,11 @@ void test (SkeletonData* skeletonData, Atlas* atlas) { int main () { testcase(test, "data/tank.json", "data/tank.skel", "data/tank.atlas", 1.0f); testcase(coin, "data/coin.json", "data/coin.skel", "data/coin.atlas", 0.5f); - /*testcase(vine, "data/vine.json", "data/vine.skel", "data/vine.atlas", 0.5f); + testcase(vine, "data/vine.json", "data/vine.skel", "data/vine.atlas", 0.5f); testcase(tank, "data/tank.json", "data/tank.skel", "data/tank.atlas", 0.2f); testcase(raptor, "data/raptor.json", "data/raptor.skel", "data/raptor.atlas", 0.5f); testcase(spineboy, "data/spineboy.json", "data/spineboy.skel", "data/spineboy.atlas", 0.6f); testcase(goblins, "data/goblins-mesh.json", "data/goblins-mesh.skel", "data/goblins.atlas", 1.4f); - testcase(stretchyman, "data/stretchyman.json", "data/stretchyman.skel", "data/stretchyman.atlas", 0.6f);*/ + testcase(stretchyman, "data/stretchyman.json", "data/stretchyman.skel", "data/stretchyman.atlas", 0.6f); return 0; } diff --git a/spine-sfml/src/spine/spine-sfml.cpp b/spine-sfml/src/spine/spine-sfml.cpp index f4b5eb67d..d410d2cdd 100644 --- a/spine-sfml/src/spine/spine-sfml.cpp +++ b/spine-sfml/src/spine/spine-sfml.cpp @@ -64,7 +64,7 @@ namespace spine { SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData, AnimationStateData* stateData) : timeScale(1), vertexArray(new VertexArray(Triangles, skeletonData->bonesCount * 4)), - worldVertices(0) { + worldVertices(0), clipper(0) { Bone_setYDown(true); worldVertices = MALLOC(float, SPINE_MESH_VERTEX_COUNT_MAX); skeleton = Skeleton_create(skeletonData); @@ -73,6 +73,8 @@ SkeletonDrawable::SkeletonDrawable (SkeletonData* skeletonData, AnimationStateDa if (ownsAnimationStateData) stateData = AnimationStateData_create(skeletonData); state = AnimationState_create(stateData); + + clipper = spSkeletonClipping_create(); } SkeletonDrawable::~SkeletonDrawable () { @@ -81,6 +83,7 @@ SkeletonDrawable::~SkeletonDrawable () { if (ownsAnimationStateData) AnimationStateData_dispose(state->data); AnimationState_dispose(state); Skeleton_dispose(skeleton); + spSkeletonClipping_dispose(clipper); } void SkeletonDrawable::update (float deltaTime) { @@ -93,8 +96,8 @@ void SkeletonDrawable::update (float deltaTime) { void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const { vertexArray->clear(); states.texture = 0; + unsigned short quadIndices[6] = { 0, 1, 2, 2, 3, 0 }; - sf::Vertex vertices[4]; sf::Vertex vertex; Texture* texture = 0; for (int i = 0; i < skeleton->slotsCount; ++i) { @@ -102,133 +105,92 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const { Attachment* attachment = slot->attachment; if (!attachment) continue; + float* vertices = worldVertices; + int verticesCount = 0; + float* uvs = 0; + unsigned short* indices = 0; + int indicesCount = 0; + spColor* attachmentColor; + if (attachment->type == ATTACHMENT_REGION) { RegionAttachment* regionAttachment = (RegionAttachment*)attachment; + spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, vertices, 0, 2); + verticesCount = 4; + uvs = regionAttachment->uvs; + indices = quadIndices; + indicesCount = 6; texture = (Texture*)((AtlasRegion*)regionAttachment->rendererObject)->page->rendererObject; - spRegionAttachment_computeWorldVertices(regionAttachment, slot->bone, worldVertices, 0, 2); - - sf::BlendMode blend; - switch (slot->data->blendMode) { - case BLEND_MODE_ADDITIVE: - blend = BlendAdd; - break; - case BLEND_MODE_MULTIPLY: - blend = BlendMultiply; - break; - case BLEND_MODE_SCREEN: // Unsupported, fall through. - default: - blend = BlendAlpha; - } - - if (states.texture == 0) states.texture = texture; - - if (states.blendMode != blend || states.texture != texture) { - target.draw(*vertexArray, states); - vertexArray->clear(); - states.blendMode = blend; - states.texture = texture; - } - - Uint8 r = static_cast(skeleton->color.r * slot->color.r * 255); - Uint8 g = static_cast(skeleton->color.g * slot->color.g * 255); - Uint8 b = static_cast(skeleton->color.b * slot->color.b * 255); - Uint8 a = static_cast(skeleton->color.a * slot->color.a * 255); - - Vector2u size = texture->getSize(); - vertices[0].color.r = r; - vertices[0].color.g = g; - vertices[0].color.b = b; - vertices[0].color.a = a; - vertices[0].position.x = worldVertices[VERTEX_X1]; - vertices[0].position.y = worldVertices[VERTEX_Y1]; - vertices[0].texCoords.x = regionAttachment->uvs[VERTEX_X1] * size.x; - vertices[0].texCoords.y = regionAttachment->uvs[VERTEX_Y1] * size.y; - - vertices[1].color.r = r; - vertices[1].color.g = g; - vertices[1].color.b = b; - vertices[1].color.a = a; - vertices[1].position.x = worldVertices[VERTEX_X2]; - vertices[1].position.y = worldVertices[VERTEX_Y2]; - vertices[1].texCoords.x = regionAttachment->uvs[VERTEX_X2] * size.x; - vertices[1].texCoords.y = regionAttachment->uvs[VERTEX_Y2] * size.y; - - vertices[2].color.r = r; - vertices[2].color.g = g; - vertices[2].color.b = b; - vertices[2].color.a = a; - vertices[2].position.x = worldVertices[VERTEX_X3]; - vertices[2].position.y = worldVertices[VERTEX_Y3]; - vertices[2].texCoords.x = regionAttachment->uvs[VERTEX_X3] * size.x; - vertices[2].texCoords.y = regionAttachment->uvs[VERTEX_Y3] * size.y; - - vertices[3].color.r = r; - vertices[3].color.g = g; - vertices[3].color.b = b; - vertices[3].color.a = a; - vertices[3].position.x = worldVertices[VERTEX_X4]; - vertices[3].position.y = worldVertices[VERTEX_Y4]; - vertices[3].texCoords.x = regionAttachment->uvs[VERTEX_X4] * size.x; - vertices[3].texCoords.y = regionAttachment->uvs[VERTEX_Y4] * size.y; - - vertexArray->append(vertices[0]); - vertexArray->append(vertices[1]); - vertexArray->append(vertices[2]); - vertexArray->append(vertices[0]); - vertexArray->append(vertices[2]); - vertexArray->append(vertices[3]); + attachmentColor = ®ionAttachment->color; } else if (attachment->type == ATTACHMENT_MESH) { MeshAttachment* mesh = (MeshAttachment*)attachment; if (mesh->super.worldVerticesLength > SPINE_MESH_VERTEX_COUNT_MAX) continue; texture = (Texture*)((AtlasRegion*)mesh->rendererObject)->page->rendererObject; spVertexAttachment_computeWorldVertices(SUPER(mesh), slot, 0, mesh->super.worldVerticesLength, worldVertices, 0, 2); + verticesCount = mesh->super.worldVerticesLength >> 1; + uvs = mesh->uvs; + indices = mesh->triangles; + indicesCount = mesh->trianglesCount; + attachmentColor = &mesh->color; + } else if (attachment->type == SP_ATTACHMENT_CLIPPING) { + spClippingAttachment* clip = (spClippingAttachment*)slot->attachment; + spSkeletonClipping_clipStart(clipper, slot, clip); + } else continue; - sf::BlendMode blend; - switch (slot->data->blendMode) { - case BLEND_MODE_ADDITIVE: - blend = BlendAdd; - break; - case BLEND_MODE_MULTIPLY: - blend = BlendMultiply; - break; - case BLEND_MODE_SCREEN: // Unsupported, fall through. - default: - blend = BlendAlpha; - } - - if (states.texture == 0) states.texture = texture; - - if (states.blendMode != blend || states.texture != texture) { - target.draw(*vertexArray, states); - vertexArray->clear(); - states.blendMode = blend; - states.texture = texture; - } - - Uint8 r = static_cast(skeleton->color.r * slot->color.r * 255); - Uint8 g = static_cast(skeleton->color.g * slot->color.g * 255); - Uint8 b = static_cast(skeleton->color.b * slot->color.b * 255); - Uint8 a = static_cast(skeleton->color.a * slot->color.a * 255); - vertex.color.r = r; - vertex.color.g = g; - vertex.color.b = b; - vertex.color.a = a; - - Vector2u size = texture->getSize(); - for (int i = 0; i < mesh->trianglesCount; ++i) { - int index = mesh->triangles[i] << 1; - vertex.position.x = worldVertices[index]; - vertex.position.y = worldVertices[index + 1]; - vertex.texCoords.x = mesh->uvs[index] * size.x; - vertex.texCoords.y = mesh->uvs[index + 1] * size.y; - vertexArray->append(vertex); - } + Uint8 r = static_cast(skeleton->color.r * slot->color.r * attachmentColor->r * 255); + Uint8 g = static_cast(skeleton->color.g * slot->color.g * attachmentColor->g * 255); + Uint8 b = static_cast(skeleton->color.b * slot->color.b * attachmentColor->b * 255); + Uint8 a = static_cast(skeleton->color.a * slot->color.a * attachmentColor->a * 255); + vertex.color.r = r; + vertex.color.g = g; + vertex.color.b = b; + vertex.color.a = a; + sf::BlendMode blend; + switch (slot->data->blendMode) { + case BLEND_MODE_ADDITIVE: + blend = BlendAdd; + break; + case BLEND_MODE_MULTIPLY: + blend = BlendMultiply; + break; + case BLEND_MODE_SCREEN: // Unsupported, fall through. + default: + blend = BlendAlpha; } - } + if (states.texture == 0) states.texture = texture; + + if (states.blendMode != blend || states.texture != texture) { + target.draw(*vertexArray, states); + vertexArray->clear(); + states.blendMode = blend; + states.texture = texture; + } + + if (spSkeletonClipping_isClipping(clipper)) { + spSkeletonClipping_clipTriangles(clipper, vertices, verticesCount << 1, indices, indicesCount, uvs); + vertices = clipper->clippedVertices->items; + verticesCount = clipper->clippedVertices->size >> 1; + uvs = clipper->clippedUVs->items; + indices = clipper->clippedTriangles->items; + indicesCount = clipper->clippedTriangles->size; + } + + Vector2u size = texture->getSize(); + for (int i = 0; i < indicesCount; ++i) { + int index = indices[i] << 1; + vertex.position.x = vertices[index]; + vertex.position.y = vertices[index + 1]; + vertex.texCoords.x = uvs[index] * size.x; + vertex.texCoords.y = uvs[index + 1] * size.y; + vertexArray->append(vertex); + } + + spSkeletonClipping_clipEnd(clipper, slot); + } target.draw(*vertexArray, states); + spSkeletonClipping_clipEnd2(clipper); } } /* namespace spine */ diff --git a/spine-sfml/src/spine/spine-sfml.h b/spine-sfml/src/spine/spine-sfml.h index ffa960e71..6fa1fc139 100644 --- a/spine-sfml/src/spine/spine-sfml.h +++ b/spine-sfml/src/spine/spine-sfml.h @@ -58,6 +58,7 @@ public: private: bool ownsAnimationStateData; float* worldVertices; + spSkeletonClipping* clipper; }; } /* namespace spine */