|
1 | 1 | /** |
2 | | - * We're replacing a couple of Pixi's methods here to fix or add some vital functionality: |
3 | | - * |
4 | | - * 1) Added support for Trimmed sprite sheets |
5 | | - * 2) Skip display objects with an alpha of zero |
| 2 | +* We're replacing a couple of Pixi's methods here to fix or add some vital functionality: |
| 3 | +* |
| 4 | +* 1) Added support for Trimmed sprite sheets |
| 5 | +* 2) Skip display objects with an alpha of zero |
| 6 | +* 3) Avoid Style Recalculation from the incorrect bgcolor value |
| 7 | +* |
| 8 | +* Hopefully we can remove this once Pixi has been updated to support these things. |
| 9 | +*/ |
| 10 | + |
| 11 | +/** |
| 12 | + * Renders the stage to its canvas view |
6 | 13 | * |
7 | | - * Hopefully we can remove this once Pixi has been updated to support these things. |
| 14 | + * @method render |
| 15 | + * @param stage {Stage} the Stage element to be rendered |
8 | 16 | */ |
9 | | - |
10 | | -PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) |
| 17 | +PIXI.CanvasRenderer.prototype.render = function(stage) |
11 | 18 | { |
12 | | - // no loger recurrsive! |
13 | | - var transform; |
14 | | - var context = this.context; |
| 19 | + PIXI.texturesToUpdate.length = 0; |
| 20 | + PIXI.texturesToDestroy.length = 0; |
| 21 | + |
| 22 | + PIXI.visibleCount++; |
| 23 | + stage.updateTransform(); |
15 | 24 |
|
16 | | - context.globalCompositeOperation = 'source-over'; |
| 25 | + // update the background color |
| 26 | + // if(this.view.style.backgroundColor!=stage.backgroundColorString && !this.transparent)this.view.style.backgroundColor = stage.backgroundColorString; |
| 27 | + |
| 28 | + this.context.setTransform(1, 0, 0, 1, 0, 0); |
| 29 | + this.context.clearRect(0, 0, this.width, this.height) |
| 30 | + this.renderDisplayObject(stage); |
| 31 | + |
| 32 | + // Remove frame updates |
| 33 | + if (PIXI.Texture.frameUpdates.length > 0) |
| 34 | + { |
| 35 | + PIXI.Texture.frameUpdates.length = 0; |
| 36 | + } |
17 | 37 |
|
18 | | - // one the display object hits this. we can break the loop |
| 38 | +} |
| 39 | + |
| 40 | +PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) |
| 41 | +{ |
| 42 | + // Once the display object hits this we can break the loop |
19 | 43 | var testObject = displayObject.last._iNext; |
20 | 44 | displayObject = displayObject.first; |
21 | 45 |
|
22 | 46 | do |
23 | 47 | { |
24 | | - transform = displayObject.worldTransform; |
| 48 | + //transform = displayObject.worldTransform; |
25 | 49 |
|
26 | | - if(!displayObject.visible) |
| 50 | + if (!displayObject.visible) |
27 | 51 | { |
28 | 52 | displayObject = displayObject.last._iNext; |
29 | 53 | continue; |
30 | 54 | } |
31 | 55 |
|
32 | | - if(!displayObject.renderable || displayObject.alpha == 0) |
| 56 | + if (!displayObject.renderable || displayObject.alpha == 0) |
33 | 57 | { |
34 | 58 | displayObject = displayObject._iNext; |
35 | 59 | continue; |
36 | 60 | } |
37 | 61 |
|
38 | | - if(displayObject instanceof PIXI.Sprite) |
| 62 | + if (displayObject instanceof PIXI.Sprite) |
39 | 63 | { |
40 | | - var frame = displayObject.texture.frame; |
| 64 | + // var frame = displayObject.texture.frame; |
41 | 65 |
|
42 | | - if(frame) |
| 66 | + if (displayObject.texture.frame) |
43 | 67 | { |
44 | | - context.globalAlpha = displayObject.worldAlpha; |
| 68 | + this.context.globalAlpha = displayObject.worldAlpha; |
45 | 69 |
|
46 | 70 | if (displayObject.texture.trimmed) |
47 | 71 | { |
48 | | - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2] + displayObject.texture.trim.x, transform[5] + displayObject.texture.trim.y); |
| 72 | + this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2] + displayObject.texture.trim.x, displayObject.worldTransform[5] + displayObject.texture.trim.y); |
49 | 73 | } |
50 | 74 | else |
51 | 75 | { |
52 | | - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]); |
| 76 | + this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]); |
53 | 77 | } |
54 | 78 |
|
55 | | - context.drawImage(displayObject.texture.baseTexture.source, |
56 | | - frame.x, |
57 | | - frame.y, |
58 | | - frame.width, |
59 | | - frame.height, |
60 | | - (displayObject.anchor.x) * -frame.width, |
61 | | - (displayObject.anchor.y) * -frame.height, |
62 | | - frame.width, |
63 | | - frame.height); |
| 79 | + this.context.drawImage( |
| 80 | + displayObject.texture.baseTexture.source, |
| 81 | + displayObject.texture.frame.x, |
| 82 | + displayObject.texture.frame.y, |
| 83 | + displayObject.texture.frame.width, |
| 84 | + displayObject.texture.frame.height, |
| 85 | + (displayObject.anchor.x) * -displayObject.texture.frame.width, |
| 86 | + (displayObject.anchor.y) * -displayObject.texture.frame.height, |
| 87 | + displayObject.texture.frame.width, |
| 88 | + displayObject.texture.frame.height); |
64 | 89 | } |
65 | 90 | } |
66 | | - else if(displayObject instanceof PIXI.Strip) |
| 91 | + else if (displayObject instanceof PIXI.Strip) |
67 | 92 | { |
68 | | - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) |
| 93 | + this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]) |
69 | 94 | this.renderStrip(displayObject); |
70 | 95 | } |
71 | | - else if(displayObject instanceof PIXI.TilingSprite) |
| 96 | + else if (displayObject instanceof PIXI.TilingSprite) |
72 | 97 | { |
73 | | - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) |
| 98 | + this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]) |
74 | 99 | this.renderTilingSprite(displayObject); |
75 | 100 | } |
76 | | - else if(displayObject instanceof PIXI.CustomRenderable) |
| 101 | + else if (displayObject instanceof PIXI.CustomRenderable) |
77 | 102 | { |
78 | 103 | displayObject.renderCanvas(this); |
79 | 104 | } |
80 | | - else if(displayObject instanceof PIXI.Graphics) |
| 105 | + else if (displayObject instanceof PIXI.Graphics) |
81 | 106 | { |
82 | | - context.setTransform(transform[0], transform[3], transform[1], transform[4], transform[2], transform[5]) |
83 | | - PIXI.CanvasGraphics.renderGraphics(displayObject, context); |
| 107 | + this.context.setTransform(displayObject.worldTransform[0], displayObject.worldTransform[3], displayObject.worldTransform[1], displayObject.worldTransform[4], displayObject.worldTransform[2], displayObject.worldTransform[5]) |
| 108 | + PIXI.CanvasGraphics.renderGraphics(displayObject, this.context); |
84 | 109 | } |
85 | | - else if(displayObject instanceof PIXI.FilterBlock) |
| 110 | + else if (displayObject instanceof PIXI.FilterBlock) |
86 | 111 | { |
87 | | - if(displayObject.open) |
| 112 | + if (displayObject.open) |
88 | 113 | { |
89 | | - context.save(); |
| 114 | + this.context.save(); |
90 | 115 |
|
91 | 116 | var cacheAlpha = displayObject.mask.alpha; |
92 | 117 | var maskTransform = displayObject.mask.worldTransform; |
93 | 118 |
|
94 | | - context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) |
| 119 | + this.context.setTransform(maskTransform[0], maskTransform[3], maskTransform[1], maskTransform[4], maskTransform[2], maskTransform[5]) |
95 | 120 |
|
96 | 121 | displayObject.mask.worldAlpha = 0.5; |
97 | 122 |
|
98 | | - context.worldAlpha = 0; |
| 123 | + this.context.worldAlpha = 0; |
99 | 124 |
|
100 | | - PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, context); |
101 | | - context.clip(); |
| 125 | + PIXI.CanvasGraphics.renderGraphicsMask(displayObject.mask, this.context); |
| 126 | + this.context.clip(); |
102 | 127 |
|
103 | 128 | displayObject.mask.worldAlpha = cacheAlpha; |
104 | 129 | } |
105 | 130 | else |
106 | 131 | { |
107 | | - context.restore(); |
| 132 | + this.context.restore(); |
108 | 133 | } |
109 | 134 | } |
110 | | - // count++ |
| 135 | + // count++ |
111 | 136 | displayObject = displayObject._iNext; |
112 | | - |
113 | | - |
114 | 137 | } |
115 | 138 | while(displayObject != testObject) |
116 | 139 |
|
|
0 commit comments