|
27 | 27 | cc.SpriteBatchNode.CanvasRenderCmd.call(this, renderable);
|
28 | 28 | this._needDraw = true;
|
29 | 29 | this._realWorldTransform = {a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0};
|
30 |
| - this._childrenRenderCmds = []; |
31 | 30 |
|
32 | 31 | var locCanvas = cc._canvas;
|
33 | 32 | var tmpCanvas = cc.newElement('canvas');
|
|
46 | 45 | var proto = cc.TMXLayer.CanvasRenderCmd.prototype = Object.create(cc.SpriteBatchNode.CanvasRenderCmd.prototype);
|
47 | 46 | proto.constructor = cc.TMXLayer.CanvasRenderCmd;
|
48 | 47 |
|
49 |
| - proto._copyRendererCmds = function (rendererCmds) { |
50 |
| - if (!rendererCmds) |
51 |
| - return; |
52 |
| - |
53 |
| - var locCacheCmds = this._childrenRenderCmds; |
54 |
| - locCacheCmds.length = 0; |
55 |
| - for (var i = 0, len = rendererCmds.length; i < len; i++) { |
56 |
| - locCacheCmds[i] = rendererCmds[i]; |
57 |
| - } |
58 |
| - }; |
59 |
| - |
60 | 48 | //set the cache dirty flag for canvas
|
61 | 49 | proto._setNodeDirtyForCache = function () {
|
62 | 50 | this._cacheDirty = true;
|
63 | 51 | };
|
64 | 52 |
|
65 | 53 | proto._renderingChildToCache = function (scaleX, scaleY) {
|
66 | 54 | if (this._cacheDirty) {
|
67 |
| - var locCacheCmds = this._childrenRenderCmds, wrapper = this._cacheContext, |
| 55 | + var wrapper = this._cacheContext, |
68 | 56 | context = wrapper.getContext(), locCanvas = this._cacheCanvas;
|
69 | 57 |
|
70 | 58 | //wrapper.save();
|
71 | 59 | context.setTransform(1, 0, 0, 1, 0, 0);
|
72 | 60 | context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
73 | 61 | //reset the cache context
|
74 | 62 |
|
75 |
| - for (var i = 0, len = locCacheCmds.length; i < len; i++) { |
76 |
| - locCacheCmds[i].rendering(wrapper, scaleX, scaleY); |
77 |
| - locCacheCmds[i]._cacheDirty = false; |
| 63 | + this._node.sortAllChildren(); |
| 64 | + var locChildren = this._node._children; |
| 65 | + for (var i = 0, len = locChildren.length; i < len; i++) { |
| 66 | + if (locChildren[i]){ |
| 67 | + var selCmd = locChildren[i]._renderCmd; |
| 68 | + if(selCmd){ |
| 69 | + selCmd.rendering(wrapper, scaleX, scaleY); |
| 70 | + selCmd._cacheDirty = false; |
| 71 | + } |
| 72 | + } |
78 | 73 | }
|
| 74 | + |
79 | 75 | //wrapper.restore();
|
80 | 76 | this._cacheDirty = false;
|
81 | 77 | }
|
|
87 | 83 | return;
|
88 | 84 |
|
89 | 85 | var node = this._node;
|
90 |
| - //TODO: it will implement dynamic compute child cutting automation. |
91 |
| - var i, len, locChildren = node._children; |
92 |
| - // quick return if not visible |
93 |
| - if (!node._visible || !locChildren || locChildren.length === 0) |
94 |
| - return; |
95 |
| - |
96 |
| - var wrapper, context; |
97 |
| - |
98 |
| - if (this._cacheDirty) { |
99 |
| - var locCanvas = this._cacheCanvas, instanceID = node.__instanceId, renderer = cc.renderer; |
100 |
| - wrapper = this._cacheContext, context = wrapper.getContext(), |
101 |
| - //begin cache |
102 |
| - renderer._turnToCacheMode(instanceID); |
103 |
| - |
104 |
| - node.sortAllChildren(); |
105 |
| - for (i = 0, len = locChildren.length; i < len; i++) { |
106 |
| - if (locChildren[i]){ |
107 |
| - var selCmd = locChildren[i]._renderCmd; |
108 |
| - if(selCmd){ |
109 |
| - selCmd.visit(this); |
110 |
| - selCmd._cacheDirty = false; |
111 |
| - } |
112 |
| - } |
113 |
| - } |
114 |
| - |
115 |
| - //copy cached render cmd array to TMXLayer renderer |
116 |
| - this._copyRendererCmds(renderer._cacheToCanvasCmds[instanceID]); |
117 |
| - |
118 |
| - //wrapper.save(); |
119 |
| - context.setTransform(1, 0, 0, 1, 0, 0); |
120 |
| - context.clearRect(0, 0, locCanvas.width, locCanvas.height); |
121 |
| - //set the wrapper's offset |
122 |
| - |
123 |
| - //draw to cache canvas |
124 |
| - renderer._renderingToCacheCanvas(wrapper, instanceID); |
125 |
| - } |
126 |
| - |
127 | 86 | this._renderingChildToCache(scaleX, scaleY);
|
128 |
| - wrapper = ctx || cc._renderContext; |
129 |
| - context = wrapper.getContext(); |
| 87 | + var wrapper = ctx || cc._renderContext, context = wrapper.getContext(); |
130 | 88 | wrapper.setGlobalAlpha(alpha);
|
131 | 89 |
|
132 | 90 | var posX = 0 | ( -this._anchorPointInPoints.x), posY = 0 | ( -this._anchorPointInPoints.y);
|
|
199 | 157 | }
|
200 | 158 | }
|
201 | 159 |
|
202 |
| - //copy cached render cmd array to TMXLayer renderer |
203 |
| - this._copyRendererCmds(renderer._cacheToCanvasCmds[instanceID]); |
204 |
| - |
205 | 160 | //wrapper.save();
|
206 | 161 | context.setTransform(1, 0, 0, 1, 0, 0);
|
207 | 162 | context.clearRect(0, 0, locCanvas.width, locCanvas.height);
|
|
0 commit comments