- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
import pool from "./../system/pooling.js";
import Renderable from "./renderable.js";
/**
* @classdesc
* a generic Color Layer Object. Fills the entire Canvas with the color not just the container the object belongs to.
* @augments Renderable
*/
export default class ColorLayer extends Renderable {
/**
* @param {string} name - Layer name
* @param {Color|string} color - CSS color
* @param {number} [z = 0] - z-index position
*/
constructor(name, color, z) {
// parent constructor
super(0, 0, Infinity, Infinity);
/**
* the layer color component
* @public
* @type {Color}
* @name color
* @memberof ColorLayer#
*/
this.color = pool.pull("Color").parseCSS(color);
this.onResetEvent(name, color, z);
}
onResetEvent(name, color, z = 0) {
// apply given parameters
this.name = name;
this.pos.z = z;
this.floating = true;
// string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
this.color.parseCSS(color);
}
/**
* draw this color layer (automatically called by melonJS)
* @name draw
* @memberof ColorLayer
* @protected
* @param {CanvasRenderer|WebGLRenderer} renderer - a renderer instance
* @param {Camera2d} [viewport] - the viewport to (re)draw
*/
draw(renderer, viewport) {
renderer.save();
renderer.clipRect(
0, 0,
viewport.width, viewport.height
);
renderer.clearColor(this.color);
renderer.restore();
}
/**
* Destroy function
* @ignore
*/
destroy() {
pool.push(this.color);
this.color = undefined;
super.destroy();
}
}