|
60 | 60 | scaleX = scaleX || cc.view.getScaleX(); |
61 | 61 | scaleY = scaleY ||cc.view.getScaleY(); |
62 | 62 | var wrapper = ctx || cc._renderContext, context = wrapper.getContext(); |
63 | | - var t = this._transform; //note: use local transform |
64 | | - wrapper.save(); |
| 63 | + |
| 64 | + var t = this._transform; |
65 | 65 | context.transform(t.a, t.b, t.c, t.d, t.tx * scaleX, -t.ty * scaleY); |
66 | | - context.beginPath(); |
67 | 66 | for (var i = 0; i < stencil._buffer.length; i++) { |
68 | 67 | var vertices = stencil._buffer[i].verts; |
69 | 68 | //TODO: need support circle etc |
|
72 | 71 |
|
73 | 72 | var firstPoint = vertices[0]; |
74 | 73 | context.moveTo(firstPoint.x * scaleX, -firstPoint.y * scaleY); |
75 | | - for (var j = 1, len = vertices.length; j < len; j++) |
| 74 | + for (var j = vertices.length - 1; j > 0; j--) |
76 | 75 | context.lineTo(vertices[j].x * scaleX, -vertices[j].y * scaleY); |
77 | 76 | } |
78 | | - wrapper.restore(); |
79 | 77 | }; |
80 | 78 | }else{ |
81 | 79 | stencil._parent = this._node; |
|
94 | 92 | locCacheCtx.drawImage(canvas, 0, 0); //save the result to shareCache canvas |
95 | 93 | } else { |
96 | 94 | wrapper.save(); |
97 | | - wrapper.save(); //save for clip |
| 95 | + context.beginPath(); //save for clip |
98 | 96 | //Because drawNode's content size is zero |
99 | 97 | wrapper.setTransform(this._worldTransform, scaleX, scaleY); |
| 98 | + |
| 99 | + if (this._node.inverted) { |
| 100 | + context.rect(0, 0, context.canvas.width, -context.canvas.height); |
| 101 | + context.clip(); |
| 102 | + } |
100 | 103 | } |
101 | 104 | }; |
102 | 105 |
|
|
123 | 126 | //hack |
124 | 127 | this._setStencilCompositionOperation(node._stencil); |
125 | 128 | } else { |
126 | | - wrapper.restore(); //it use for |
127 | | - if (node.inverted) { |
128 | | - var canvas = context.canvas; |
129 | | - wrapper.save(); |
130 | | - context.setTransform(1, 0, 0, 1, 0, 0); |
131 | | - |
132 | | - context.moveTo(0, 0); |
133 | | - context.lineTo(0, canvas.height); |
134 | | - context.lineTo(canvas.width, canvas.height); |
135 | | - context.lineTo(canvas.width, 0); |
136 | | - context.lineTo(0, 0); |
137 | | - |
138 | | - wrapper.restore(); |
139 | | - } |
140 | | - context.closePath(); |
141 | 129 | context.clip(); |
142 | 130 | } |
143 | 131 | }; |
|
0 commit comments