(items, config)
| 58 | * @return {Phaser.Filters.Mask[]} The new Mask filters, in order of target. |
| 59 | */ |
| 60 | var AddMaskShape = function (items, config) |
| 61 | { |
| 62 | if (!Array.isArray(items)) { items = [ items ]; } |
| 63 | if (!config) { config = {}; } |
| 64 | var aspectRatio = (config.aspectRatio === undefined) ? 1 : config.aspectRatio; |
| 65 | var padding = config.padding || 0; |
| 66 | |
| 67 | var scene = items[0].scene; |
| 68 | var output = []; |
| 69 | |
| 70 | for (var i = 0; i < items.length; i++) |
| 71 | { |
| 72 | var item = items[i]; |
| 73 | |
| 74 | var region = config.region; |
| 75 | if (!region) |
| 76 | { |
| 77 | if (config.useInternal && item._sizeComponent) |
| 78 | { |
| 79 | region = new Rectangle(0, 0, item.width, item.height); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | region = new Rectangle(0, 0, scene.scale.width, scene.scale.height); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Create a shape to use as a mask. |
| 88 | var shape; |
| 89 | switch (config.shape) |
| 90 | { |
| 91 | case 'ellipse': |
| 92 | { |
| 93 | shape = scene.add.ellipse(0, 0, aspectRatio, 1, 0xffffff); |
| 94 | break; |
| 95 | } |
| 96 | case 'square': |
| 97 | { |
| 98 | shape = scene.add.rectangle(0, 0, 1, 1, 0xffffff); |
| 99 | break; |
| 100 | } |
| 101 | case 'rectangle': |
| 102 | { |
| 103 | shape = scene.add.rectangle(0, 0, aspectRatio, 1, 0xffffff); |
| 104 | break; |
| 105 | } |
| 106 | case 'circle': |
| 107 | default: |
| 108 | { |
| 109 | shape = scene.add.circle(0, 0, 1, 0xffffff); |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Remove shape from scene, as we don't need to display it, |
| 115 | // and it will be garbage collected once the Mask is destroyed. |
| 116 | scene.children.remove(shape); |
| 117 |
no test coverage detected
searching dependent graphs…