|
60 | 60 | var points = [];
|
61 | 61 | for (i = 0, n = locSkeleton.slots.length; i < n; i++) {
|
62 | 62 | slot = locSkeleton.drawOrder[i];
|
63 |
| - if (!slot.attachment || slot.attachment.type != sp.ATTACHMENT_TYPE.REGION) |
| 63 | + if (!slot.attachment || !(slot.attachment instanceof spine.RegionAttachment)) |
64 | 64 | continue;
|
65 | 65 | attachment = slot.attachment;
|
66 | 66 | this._updateRegionAttachmentSlot(attachment, slot, points);
|
|
76 | 76 |
|
77 | 77 | for (i = 0, n = locSkeleton.bones.length; i < n; i++) {
|
78 | 78 | bone = locSkeleton.bones[i];
|
79 |
| - var x = bone.data.length * bone.m00 + bone.worldX; |
80 |
| - var y = bone.data.length * bone.m10 + bone.worldY; |
| 79 | + var x = bone.data.length * bone.a + bone.worldX; |
| 80 | + var y = bone.data.length * bone.c + bone.worldY; |
81 | 81 | drawingUtil.drawLine(
|
82 | 82 | {x: bone.worldX, y: bone.worldY},
|
83 | 83 | {x: x, y: y});
|
|
100 | 100 | if (!points)
|
101 | 101 | return;
|
102 | 102 |
|
103 |
| - var vertices = {}, VERTEX = sp.VERTEX_INDEX, bone = slot.bone; |
104 |
| - attachment.computeVertices(bone.skeleton.x, bone.skeleton.y, bone, vertices); |
| 103 | + var vertices = attachment.updateWorldVertices(slot, false); |
| 104 | + var VERTEX = spine.RegionAttachment; |
105 | 105 | points.length = 0;
|
106 | 106 | points.push(cc.p(vertices[VERTEX.X1], vertices[VERTEX.Y1]));
|
107 | 107 | points.push(cc.p(vertices[VERTEX.X4], vertices[VERTEX.Y4]));
|
|
118 | 118 | slot._slotNode = slotNode;
|
119 | 119 |
|
120 | 120 | if (attachment instanceof spine.RegionAttachment) {
|
121 |
| - spriteName = attachment.rendererObject.name; |
| 121 | + spriteName = attachment.region.name; |
122 | 122 | sprite = this._createSprite(slot, attachment);
|
123 | 123 | slot.currentSprite = sprite;
|
124 | 124 | slot.currentSpriteName = spriteName;
|
|
141 | 141 | };
|
142 | 142 |
|
143 | 143 | proto._createSprite = function (slot, attachment) {
|
144 |
| - var rendererObject = attachment.rendererObject; |
145 |
| - var texture = rendererObject.page._texture; |
| 144 | + var rendererObject = attachment.region; |
| 145 | + var texture = rendererObject.texture.getRealTexture(); |
146 | 146 | var sprite = new cc.Sprite();
|
147 | 147 | if (texture.isLoaded()) {
|
148 | 148 | loaded(sprite, texture, rendererObject, attachment);
|
|
158 | 158 |
|
159 | 159 | proto._updateChild = function () {
|
160 | 160 | var locSkeleton = this._node._skeleton, slots = locSkeleton.slots;
|
161 |
| - var i, n, selSprite; |
| 161 | + var color = this._displayedColor, opacity = this._displayedOpacity; |
| 162 | + var i, n, selSprite, ax, ay; |
162 | 163 |
|
163 | 164 | var slot, attachment, slotNode;
|
164 | 165 | for (i = 0, n = slots.length; i < n; i++) {
|
|
169 | 170 | slotNode.setVisible(false);
|
170 | 171 | continue;
|
171 | 172 | }
|
172 |
| - var type = attachment.type; |
173 |
| - if (type === spine.AttachmentType.region) { |
174 |
| - if (attachment.rendererObject) { |
| 173 | + if (attachment instanceof spine.RegionAttachment){ |
| 174 | + if (attachment.region) { |
175 | 175 | if (!slot.currentSpriteName || slot.currentSpriteName !== attachment.name) {
|
176 |
| - var spriteName = attachment.rendererObject.name; |
| 176 | + var spriteName = attachment.region.name; |
177 | 177 | if (slot.currentSprite !== undefined)
|
178 | 178 | slot.currentSprite.setVisible(false);
|
179 | 179 | slot.sprites = slot.sprites || {};
|
|
188 | 188 | }
|
189 | 189 | }
|
190 | 190 | var bone = slot.bone;
|
191 |
| - slotNode.setPosition(bone.worldX + attachment.x * bone.m00 + attachment.y * bone.m01, |
192 |
| - bone.worldY + attachment.x * bone.m10 + attachment.y * bone.m11); |
193 |
| - slotNode.setScale(bone.worldScaleX, bone.worldScaleY); |
| 191 | + if (attachment.region.offsetX === 0 && attachment.region.offsetY === 0) { |
| 192 | + ax = attachment.x; |
| 193 | + ay = attachment.y; |
| 194 | + } |
| 195 | + else { |
| 196 | + //var regionScaleX = attachment.width / attachment.regionOriginalWidth * attachment.scaleX; |
| 197 | + //ax = attachment.x + attachment.regionOffsetX * regionScaleX - (attachment.width * attachment.scaleX - attachment.regionWidth * regionScaleX) / 2; |
| 198 | + ax = (attachment.offset[0] + attachment.offset[4]) * 0.5; |
| 199 | + ay = (attachment.offset[1] + attachment.offset[5]) * 0.5; |
| 200 | + } |
| 201 | + slotNode.setPosition(bone.worldX + ax * bone.a + ay * bone.b, bone.worldY + ax * bone.c + ay * bone.d); |
| 202 | + slotNode.setScale(bone.getWorldScaleX(), bone.getWorldScaleY()); |
194 | 203 |
|
195 | 204 | //set the color and opacity
|
196 | 205 | selSprite = slot.currentSprite;
|
197 |
| - selSprite._flippedX = bone.worldFlipX; |
198 |
| - selSprite._flippedY = bone.worldFlipY; |
| 206 | + selSprite._flippedX = bone.skeleton.flipX; |
| 207 | + selSprite._flippedY = bone.skeleton.flipY; |
199 | 208 | if (selSprite._flippedY || selSprite._flippedX) {
|
200 |
| - slotNode.setRotation(bone.worldRotation); |
| 209 | + slotNode.setRotation(bone.getWorldRotationX()); |
201 | 210 | selSprite.setRotation(attachment.rotation);
|
202 | 211 | } else {
|
203 |
| - slotNode.setRotation(-bone.worldRotation); |
| 212 | + slotNode.setRotation(-bone.getWorldRotationX()); |
204 | 213 | selSprite.setRotation(-attachment.rotation);
|
205 | 214 | }
|
206 | 215 |
|
207 | 216 | //hack for sprite
|
208 |
| - selSprite._renderCmd._displayedOpacity = 0 | (this._node.getOpacity() * locSkeleton.a * slot.a); |
209 |
| - var r = 0 | (locSkeleton.r * slot.r * 255), g = 0 | (locSkeleton.g * slot.g * 255), b = 0 | (locSkeleton.b * slot.b * 255); |
| 217 | + selSprite._renderCmd._displayedOpacity = 0 | (opacity * slot.color.a); |
| 218 | + var r = 0 | (color.r * slot.color.r), g = 0 | (color.g * slot.color.g), b = 0 | (color.b * slot.color.b); |
210 | 219 | selSprite.setColor(cc.color(r, g, b));
|
211 | 220 | selSprite._renderCmd._updateColor();
|
212 |
| - } else if (type === spine.AttachmentType.skinnedmesh) { |
| 221 | + } else if (attachment instanceof spine.MeshAttachment) { |
213 | 222 | //todo for mesh
|
214 | 223 | } else {
|
215 | 224 | slotNode.setVisible(false);
|
|
0 commit comments