|
33 | 33 | var proto = sp.Skeleton.CanvasRenderCmd.prototype = Object.create(cc.Node.CanvasRenderCmd.prototype);
|
34 | 34 | proto.constructor = sp.Skeleton.CanvasRenderCmd;
|
35 | 35 |
|
36 |
| - proto._drawSkeleton = function(){ |
37 |
| - |
38 |
| - }; |
39 |
| - |
40 | 36 | proto.rendering = function (wrapper, scaleX, scaleY) {
|
41 | 37 | var node = this._node, i, n;
|
42 | 38 | wrapper = wrapper || cc._renderContext;
|
| 39 | + var context = wrapper.getContext(); |
43 | 40 |
|
44 | 41 | var locSkeleton = node._skeleton,color = node.getColor();
|
45 | 42 | locSkeleton.r = color.r / 255;
|
|
52 | 49 | locSkeleton.b *= locSkeleton.a;
|
53 | 50 | }
|
54 | 51 |
|
55 |
| - wrapper.setTransform(this._worldTransform, scaleX, scaleY); |
56 |
| - wrapper.save(); |
| 52 | + /*wrapper.setTransform(this._worldTransform, scaleX, scaleY); |
| 53 | + context.save(); |
| 54 | + //draw skeleton by itself. |
| 55 | + var slot, attachment, selTexture, selBone, rendererObject; |
| 56 | + for (i = 0, n = locSkeleton.drawOrder.length; i < n; i++) { |
| 57 | + slot = locSkeleton.drawOrder[i]; |
| 58 | + if (!slot.attachment) |
| 59 | + continue; |
57 | 60 |
|
58 |
| -/* //draw skeleton sprite by it self |
59 |
| - wrapper.save(); |
| 61 | + attachment = slot.attachment; |
| 62 | + rendererObject = attachment.rendererObject; |
| 63 | + selTexture = rendererObject.page._texture; |
| 64 | + if(!selTexture || !selTexture._textureLoaded || !slot.bone) |
| 65 | + continue; |
| 66 | +
|
| 67 | + selBone = slot.bone; |
| 68 | + //context.transform(selBone.m00, selBone.m01, selBone.m10, selBone.m11, selBone.worldX, selBone.worldY); |
| 69 | + context.translate(selBone.worldX, selBone.worldY); |
| 70 | + context.scale(selBone.worldScaleX, selBone.worldScaleY); |
| 71 | + console.log(selBone); |
| 72 | + context.rotate(selBone.worldRotation); |
| 73 | + context.drawImage(selTexture._htmlElementObj, |
| 74 | + rendererObject.x, rendererObject.y, rendererObject.width, rendererObject.height, |
| 75 | + //locX * scaleX, locY * scaleY, locWidth * scaleX, locHeight * scaleY); |
| 76 | + 0, 0, rendererObject.width * scaleX, rendererObject.height * scaleY); |
| 77 | +
|
| 78 | + } |
| 79 | + context.restore();*/ |
| 80 | + |
| 81 | + //draw skeleton sprite by it self |
| 82 | +/* wrapper.save(); |
60 | 83 | //set to armature mode (spine need same way to draw)
|
61 | 84 | wrapper._switchToArmatureMode(true, this._worldTransform, scaleX, scaleY);
|
62 |
| - for(i = 0, n = sprites.length; i < n; i++){ |
| 85 | + var sprites = this._skeletonSprites, slot, selSpriteCmd,attachment; |
| 86 | + for (i = 0, n = sprites.length; i < n; i++) { |
63 | 87 | selSpriteCmd = sprites[i]._renderCmd;
|
64 |
| - if(sprites[i]._visible && selSpriteCmd && selSpriteCmd.rendering){ |
| 88 | + if (sprites[i]._visible && selSpriteCmd && selSpriteCmd.rendering) { |
65 | 89 | selSpriteCmd.rendering(wrapper, scaleX, scaleY);
|
66 | 90 | selSpriteCmd._dirtyFlag = 0;
|
67 | 91 | }
|
68 | 92 | }
|
69 | 93 | wrapper._switchToArmatureMode(false);
|
70 | 94 | wrapper.restore();*/
|
71 | 95 |
|
72 |
| - //draw skeleton by itself. |
73 |
| - var slot, attachment; |
74 |
| - for (i = 0, n = locSkeleton.drawOrder.length; i < n; i++) { |
75 |
| - slot = locSkeleton.drawOrder[i]; |
76 |
| - if (!slot.attachment) |
77 |
| - continue; |
78 |
| - |
79 |
| - attachment = slot.attachment; |
80 |
| - var regionTextureAtlas = node.getTextureAtlas(attachment); |
| 96 | + //set to armature mode (spine need same way to draw) |
| 97 | + var sprites = this._skeletonSprites, slot, selSpriteCmd,attachment; |
| 98 | + for (i = 0, n = sprites.length; i < n; i++) { |
| 99 | + selSpriteCmd = sprites[i]._renderCmd; |
| 100 | + if (sprites[i]._visible && selSpriteCmd && selSpriteCmd.rendering) { |
| 101 | + selSpriteCmd.transform(this, false); |
| 102 | + selSpriteCmd.rendering(wrapper, scaleX, scaleY); |
| 103 | + selSpriteCmd._dirtyFlag = 0; |
| 104 | + } |
81 | 105 | }
|
82 |
| - wrapper.restore(); |
83 | 106 |
|
84 | 107 | if (!node._debugSlots && !node._debugBones)
|
85 | 108 | return;
|
86 |
| - |
| 109 | + wrapper.setTransform(this._worldTransform, scaleX, scaleY); |
87 | 110 | var drawingUtil = cc._drawingUtil;
|
88 | 111 | if (node._debugSlots) {
|
89 | 112 | // Slots.
|
90 | 113 | drawingUtil.setDrawColor(0, 0, 255, 255);
|
91 | 114 | drawingUtil.setLineWidth(1);
|
92 | 115 |
|
93 | 116 | var points = [];
|
94 |
| - for (i = 0, n = locSkeleton.slots.length; i < n; i++) { |
| 117 | + var drawOrder = node._skeleton.drawOrder; |
| 118 | + for (i = 0, n = drawOrder.length; i < n; i++) { |
| 119 | + //for (i = 0, n = locSkeleton.slots.length; i < n; i++) { |
95 | 120 | slot = locSkeleton.drawOrder[i];
|
96 | 121 | if (!slot.attachment || slot.attachment.type != sp.ATTACHMENT_TYPE.REGION)
|
97 | 122 | continue;
|
98 | 123 | attachment = slot.attachment;
|
99 |
| - sp._regionAttachment_updateSlotForCanvas(attachment, slot, points); |
| 124 | + this._updateRegionAttachmentSlot(attachment, slot, points); |
100 | 125 | drawingUtil.drawPoly(points, 4, true);
|
101 | 126 | }
|
102 | 127 | }
|
|
129 | 154 | }
|
130 | 155 | };
|
131 | 156 |
|
| 157 | + proto._updateRegionAttachmentSlot = function(attachment, slot, points) { |
| 158 | + if(!points) |
| 159 | + return; |
| 160 | + |
| 161 | + var vertices = {}, VERTEX = sp.VERTEX_INDEX, bone = slot.bone; |
| 162 | + attachment.computeVertices(bone.skeleton.x, bone.skeleton.y, bone, vertices); |
| 163 | + points.length = 0; |
| 164 | + points.push(cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1])); |
| 165 | + points.push(cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4])); |
| 166 | + points.push(cc.p(vertices[VERTEX.X3], vertices[VERTEX.Y3])); |
| 167 | + points.push(cc.p(vertices[VERTEX.X2], vertices[VERTEX.Y2])); |
| 168 | + }; |
| 169 | + |
132 | 170 | proto._createChildFormSkeletonData = function(){
|
133 | 171 | var node = this._node;
|
134 | 172 | var locSkeleton = node._skeleton, rendererObject, rect;
|
|
182 | 220 | selSprite.setBlendFunc(cc.BLEND_SRC, slot.data.additiveBlending ? cc.ONE : cc.BLEND_DST);
|
183 | 221 |
|
184 | 222 | var bone = slot.bone;
|
185 |
| - selSprite.setPosition(bone.worldX + attachment.x * bone.m00 + attachment.y * bone.m01, |
186 |
| - bone.worldY + attachment.x * bone.m10 + attachment.y * bone.m11); |
| 223 | + selSprite.setPosition(bone.worldX, bone.worldY); |
187 | 224 | selSprite.setScale(bone.worldScaleX, bone.worldScaleY);
|
188 |
| - selSprite.setRotation(-(slot.bone.worldRotation + attachment.rotation)); |
| 225 | + //selSprite.setRotation(-(slot.bone.worldRotation + attachment.rotation)); |
| 226 | + selSprite.setRotation(-bone.worldRotation); |
189 | 227 | selSprite.setOpacity(0 | (node._skeleton.a * slot.a * 255));
|
| 228 | + selSprite.setFlippedX(bone.flipX); |
| 229 | + selSprite.setFlippedY(bone.flipY); |
190 | 230 | var r = 0 | (node._skeleton.r * slot.r * 255);
|
191 | 231 | var g = 0 | (node._skeleton.g * slot.g * 255);
|
192 | 232 | var b = 0 | (node._skeleton.b * slot.b * 255);
|
|
0 commit comments