diff --git a/spine-cocos2d-objc/TwoColorTest.atlas b/spine-cocos2d-objc/TwoColorTest.atlas deleted file mode 100644 index 3f7ce242c..000000000 --- a/spine-cocos2d-objc/TwoColorTest.atlas +++ /dev/null @@ -1,13 +0,0 @@ - -TwoColorTest.png -size: 512,512 -format: RGBA8888 -filter: Linear,Linear -repeat: none -squareWithBorder - rotate: false - xy: 2, 2 - size: 300, 300 - orig: 300, 300 - offset: 0, 0 - index: -1 diff --git a/spine-cocos2d-objc/TwoColorTest.json b/spine-cocos2d-objc/TwoColorTest.json deleted file mode 100644 index 830de2ea9..000000000 --- a/spine-cocos2d-objc/TwoColorTest.json +++ /dev/null @@ -1,150 +0,0 @@ -{ -"skeleton": { "hash": "+PGAjM+dGgrId6XMqdIJm8hlvRE", "spine": "3.6.09-beta", "width": 300, "height": 300, "images": "" }, -"bones": [ - { "name": "root", "x": -178.03, "y": 229.83 }, - { "name": "singleColorTint", "parent": "root", "x": -400 }, - { "name": "singleColorTint2", "parent": "root", "x": -400, "y": -383 }, - { "name": "twoColorTint", "parent": "root", "x": 800 }, - { "name": "twoColorTint2", "parent": "root", "x": 800, "y": -382 }, - { "name": "twoColorTint (blackOnly)", "parent": "root" }, - { "name": "twoColorTint (blackOnly)2", "parent": "root", "y": -391 }, - { "name": "twoColorTint (colorOnly)", "parent": "root", "x": 400 }, - { "name": "twoColorTint (colorOnly)2", "parent": "root", "x": 400, "y": -382 } -], -"slots": [ - { "name": "squareWithBorder", "bone": "singleColorTint", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder7", "bone": "singleColorTint2", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder2", "bone": "twoColorTint (blackOnly)", "dark": "000000", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder8", "bone": "twoColorTint (blackOnly)2", "dark": "000000", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder4", "bone": "twoColorTint (colorOnly)", "dark": "000000", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder5", "bone": "twoColorTint (colorOnly)2", "dark": "000000", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder3", "bone": "twoColorTint", "dark": "000000", "attachment": "squareWithBorder" }, - { "name": "squareWithBorder6", "bone": "twoColorTint2", "dark": "000000", "attachment": "squareWithBorder" } -], -"skins": { - "default": { - "squareWithBorder": { - "squareWithBorder": { "width": 300, "height": 300 } - }, - "squareWithBorder2": { - "squareWithBorder": { "width": 300, "height": 300 } - }, - "squareWithBorder3": { - "squareWithBorder": { "width": 300, "height": 300 } - }, - "squareWithBorder4": { - "squareWithBorder": { "width": 300, "height": 300 } - }, - "squareWithBorder5": { - "squareWithBorder": { - "type": "mesh", - "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ], - "triangles": [ 1, 2, 3, 1, 3, 0 ], - "vertices": [ 150, -150, -150, -150, -197, 99, 183, 155 ], - "hull": 4, - "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ], - "width": 300, - "height": 300 - } - }, - "squareWithBorder6": { - "squareWithBorder": { - "type": "mesh", - "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ], - "triangles": [ 1, 2, 3, 1, 3, 0 ], - "vertices": [ 238, -200, -191, -60, -150, 150, 119, 111 ], - "hull": 4, - "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ], - "width": 300, - "height": 300 - } - }, - "squareWithBorder7": { - "squareWithBorder": { - "type": "mesh", - "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ], - "triangles": [ 1, 2, 3, 1, 3, 0 ], - "vertices": [ 210, -132, -150, -150, -150, 150, 124, 119 ], - "hull": 4, - "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ], - "width": 300, - "height": 300 - } - }, - "squareWithBorder8": { - "squareWithBorder": { - "type": "mesh", - "uvs": [ 1, 1, 0, 1, 0, 0, 1, 0 ], - "triangles": [ 1, 2, 3, 1, 3, 0 ], - "vertices": [ 150, -150, -150, -150, -97, 58, 86, 62 ], - "hull": 4, - "edges": [ 0, 2, 2, 4, 4, 6, 0, 6 ], - "width": 300, - "height": 300 - } - } - } -}, -"animations": { - "animation": { - "slots": { - "squareWithBorder": { - "color": [ - { "time": 0, "color": "fffffffe" }, - { "time": 1, "color": "9e17b3fe" }, - { "time": 2, "color": "fffffffe" } - ] - }, - "squareWithBorder2": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "fffffffe", "dark": "ff0000" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - }, - "squareWithBorder3": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "80ff00fe", "dark": "001cff" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - }, - "squareWithBorder4": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "ffd300fe", "dark": "000000" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - }, - "squareWithBorder5": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "ffd300fe", "dark": "000000" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - }, - "squareWithBorder6": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "80ff00fe", "dark": "001cff" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - }, - "squareWithBorder7": { - "color": [ - { "time": 0, "color": "fffffffe" }, - { "time": 1, "color": "9e17b3fe" }, - { "time": 2, "color": "fffffffe" } - ] - }, - "squareWithBorder8": { - "twoColor": [ - { "time": 0, "light": "fffffffe", "dark": "000000" }, - { "time": 1, "light": "fffffffe", "dark": "ff0000" }, - { "time": 2, "light": "fffffffe", "dark": "000000" } - ] - } - } - } -} -} \ No newline at end of file diff --git a/spine-cocos2d-objc/TwoColorTest.png b/spine-cocos2d-objc/TwoColorTest.png deleted file mode 100644 index f78c2923b..000000000 Binary files a/spine-cocos2d-objc/TwoColorTest.png and /dev/null differ diff --git a/spine-cocos2d-objc/spine-cocos2d-objc.xcodeproj/project.pbxproj b/spine-cocos2d-objc/spine-cocos2d-objc.xcodeproj/project.pbxproj index 749a00a7e..66c7a676e 100644 --- a/spine-cocos2d-objc/spine-cocos2d-objc.xcodeproj/project.pbxproj +++ b/spine-cocos2d-objc/spine-cocos2d-objc.xcodeproj/project.pbxproj @@ -34,9 +34,6 @@ 765A2EF61D7D7A08003FB779 /* goblins.atlas in Resources */ = {isa = PBXBuildFile; fileRef = 765A2EF41D7D7A08003FB779 /* goblins.atlas */; }; 765A2EF71D7D7A08003FB779 /* goblins.png in Resources */ = {isa = PBXBuildFile; fileRef = 765A2EF51D7D7A08003FB779 /* goblins.png */; }; 76BF7E071E66ED9C00485998 /* GLUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 76BF7E051E66ED9C00485998 /* GLUtils.c */; }; - 76BFBC301E78254F00675E2B /* TwoColorTest.atlas in Resources */ = {isa = PBXBuildFile; fileRef = 76BFBC2D1E78254F00675E2B /* TwoColorTest.atlas */; }; - 76BFBC311E78254F00675E2B /* TwoColorTest.json in Resources */ = {isa = PBXBuildFile; fileRef = 76BFBC2E1E78254F00675E2B /* TwoColorTest.json */; }; - 76BFBC321E78254F00675E2B /* TwoColorTest.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BFBC2F1E78254F00675E2B /* TwoColorTest.png */; }; 76F28D161DEC810300CDE54D /* Animation.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28CF41DEC810200CDE54D /* Animation.c */; }; 76F28D171DEC810300CDE54D /* AnimationState.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28CF51DEC810300CDE54D /* AnimationState.c */; }; 76F28D181DEC810300CDE54D /* AnimationStateData.c in Sources */ = {isa = PBXBuildFile; fileRef = 76F28CF61DEC810300CDE54D /* AnimationStateData.c */; }; @@ -165,9 +162,6 @@ 765A2EF51D7D7A08003FB779 /* goblins.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = goblins.png; path = Resources/goblins.png; sourceTree = ""; }; 76BF7E051E66ED9C00485998 /* GLUtils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = GLUtils.c; path = src/spine/GLUtils.c; sourceTree = ""; }; 76BF7E061E66ED9C00485998 /* GLUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GLUtils.h; path = src/spine/GLUtils.h; sourceTree = ""; }; - 76BFBC2D1E78254F00675E2B /* TwoColorTest.atlas */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TwoColorTest.atlas; sourceTree = ""; }; - 76BFBC2E1E78254F00675E2B /* TwoColorTest.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = TwoColorTest.json; sourceTree = ""; }; - 76BFBC2F1E78254F00675E2B /* TwoColorTest.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TwoColorTest.png; sourceTree = ""; }; 76F28CF41DEC810200CDE54D /* Animation.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Animation.c; path = "../spine-c/spine-c/src/spine/Animation.c"; sourceTree = ""; }; 76F28CF51DEC810300CDE54D /* AnimationState.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = AnimationState.c; path = "../spine-c/spine-c/src/spine/AnimationState.c"; sourceTree = ""; }; 76F28CF61DEC810300CDE54D /* AnimationStateData.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = AnimationStateData.c; path = "../spine-c/spine-c/src/spine/AnimationStateData.c"; sourceTree = ""; }; @@ -344,9 +338,6 @@ 43C32867170B0C7F004A9460 /* Resources */ = { isa = PBXGroup; children = ( - 76BFBC2D1E78254F00675E2B /* TwoColorTest.atlas */, - 76BFBC2E1E78254F00675E2B /* TwoColorTest.json */, - 76BFBC2F1E78254F00675E2B /* TwoColorTest.png */, 765A2EF41D7D7A08003FB779 /* goblins.atlas */, 765A2EF51D7D7A08003FB779 /* goblins.png */, 76F5BD9C1D2BDE1C005917E5 /* raptor.atlas */, @@ -526,17 +517,14 @@ 43C3287D170B0DBE004A9460 /* Default-568h@2x.png in Resources */, 43C3287E170B0DBE004A9460 /* Default-Landscape~ipad.png in Resources */, 43C3287F170B0DBE004A9460 /* Default.png in Resources */, - 76BFBC321E78254F00675E2B /* TwoColorTest.png in Resources */, 76F5BDA31D2BDE1C005917E5 /* raptor.json in Resources */, 43C32880170B0DBE004A9460 /* Default@2x.png in Resources */, 765A2EF71D7D7A08003FB779 /* goblins.png in Resources */, 43C32881170B0DBE004A9460 /* Icon-72.png in Resources */, 76F5BDA41D2BDE1C005917E5 /* raptor.png in Resources */, 43C32882170B0DBE004A9460 /* Icon-Small-50.png in Resources */, - 76BFBC301E78254F00675E2B /* TwoColorTest.atlas in Resources */, 76F5BDA21D2BDE1C005917E5 /* raptor.atlas in Resources */, 43C32883170B0DBE004A9460 /* Icon-Small.png in Resources */, - 76BFBC311E78254F00675E2B /* TwoColorTest.json in Resources */, 43C32884170B0DBE004A9460 /* Icon-Small@2x.png in Resources */, 43C32885170B0DBE004A9460 /* Icon.png in Resources */, 76F5BDA71D2BDE1C005917E5 /* tank.png in Resources */, diff --git a/spine-cocos2d-objc/src/spine/GLUtils.c b/spine-cocos2d-objc/src/spine/GLUtils.c index c95cf09bc..29a64a96a 100644 --- a/spine-cocos2d-objc/src/spine/GLUtils.c +++ b/spine-cocos2d-objc/src/spine/GLUtils.c @@ -30,6 +30,8 @@ #include "GLUtils.h" +#include + #include #include @@ -203,6 +205,9 @@ spTwoColorBatcher* spTwoColorBatcher_create() { batcher->indicesBuffer = MALLOC(unsigned short, MAX_INDICES); batcher->numIndices = 0; batcher->numVertices = 0; + batcher->lastTextureHandle = -1; + batcher->lastSrcBlend = -1; + batcher->lastDstBlend = -1; return batcher; } @@ -220,7 +225,7 @@ void spTwoColorBatcher_add(spTwoColorBatcher* batcher, spMeshPart mesh) { memcpy(vertices, &mesh.mesh->vertices[mesh.startVertex], mesh.numVertices * sizeof(spVertex)); unsigned short offset = (unsigned short)batcher->numVertices; - for (int i = batcher->numIndices, j = mesh.startIndex, n = batcher->numIndices + mesh.numIndices; i < n; i++, j++) { + for (int i = 0, j = mesh.startIndex, n = mesh.numIndices; i < n; i++, j++) { indices[i] = mesh.mesh->indices[j] + offset; } @@ -251,10 +256,10 @@ void spTwoColorBatcher_flush(spTwoColorBatcher* batcher) { glEnableVertexAttribArray(batcher->color2AttributeLocation); glEnableVertexAttribArray(batcher->texCoordsAttributeLocation); - glVertexAttribPointer(batcher->positionAttributeLocation, 4, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)0); - glVertexAttribPointer(batcher->colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)16); - glVertexAttribPointer(batcher->color2AttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)20); - glVertexAttribPointer(batcher->texCoordsAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)24); + glVertexAttribPointer(batcher->positionAttributeLocation, 4, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, x)); + glVertexAttribPointer(batcher->colorAttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, color)); + glVertexAttribPointer(batcher->color2AttributeLocation, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, color2)); + glVertexAttribPointer(batcher->texCoordsAttributeLocation, 2, GL_FLOAT, GL_FALSE, sizeof(spVertex), (GLvoid*)offsetof(spVertex, u)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batcher->indexBufferHandle); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * batcher->numIndices, batcher->indicesBuffer, GL_STATIC_DRAW); diff --git a/spine-cocos2d-objc/src/spine/SkeletonRenderer.m b/spine-cocos2d-objc/src/spine/SkeletonRenderer.m index 03568d1b6..0039e7061 100644 --- a/spine-cocos2d-objc/src/spine/SkeletonRenderer.m +++ b/spine-cocos2d-objc/src/spine/SkeletonRenderer.m @@ -185,6 +185,7 @@ static bool handlerQueued = false; const unsigned short* triangles = 0; int trianglesCount = 0; float r = 0, g = 0, b = 0, a = 0; + float dr = 0, dg = 0, db = 0; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment) continue; @@ -274,6 +275,14 @@ static bool handlerQueued = false; CCRenderBufferSetTriangle(buffer, j, triangles[j * 3], triangles[j * 3 + 1], triangles[j * 3 + 2]); } } else { + if (slot->darkColor) { + dr = slot->darkColor->r; + dg = slot->darkColor->g; + db = slot->darkColor->b; + } else { + dr = dg = db = 0; + } + spMeshPart meshPart; spMesh_allocatePart(mesh, &meshPart, verticesCount / 2, trianglesCount, self.texture.name, srcBlend, dstBlend); @@ -288,8 +297,8 @@ static bool handlerQueued = false; vertices->y = vertex.position.y; vertices->z = vertex.position.z; vertices->w = vertex.position.w; - vertices->color = ((int)(r * 255)) << 24 | ((int)(g * 255)) << 16 | ((int)(b * 255)) << 8 | ((int)(a * 255)); - vertices->color2 = ((int)(r * 255)) << 24 | ((int)(g * 255)) << 16 | ((int)(b * 255)) << 8 | ((int)(a * 255)); + vertices->color = ((unsigned short)(r * 255))| ((unsigned short)(g * 255)) << 8 | ((unsigned short)(b * 255)) <<16 | ((unsigned short)(a * 255)) << 24; + vertices->color2 = ((unsigned short)(dr * 255)) | ((unsigned short)(dg * 255)) << 8 | ((unsigned short)(db * 255)) << 16 | ((unsigned short)(255)) << 24; vertices->u = uvs[i * 2]; vertices->v = 1 - uvs[i * 2 + 1]; }