-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreenSprite.js
119 lines (107 loc) · 3.04 KB
/
ScreenSprite.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//-----------------------------------------------------------------------------
/**
* The sprite which covers the entire game screen.
*
* @class ScreenSprite
* @constructor
*/
function ScreenSprite() {
this.initialize.apply(this, arguments);
}
ScreenSprite.prototype = Object.create(PIXI.Container.prototype);
ScreenSprite.prototype.constructor = ScreenSprite;
ScreenSprite.prototype.initialize = function () {
PIXI.Container.call(this);
this._graphics = new PIXI.Graphics();
this.addChild(this._graphics);
this.opacity = 0;
this._red = -1;
this._green = -1;
this._blue = -1;
this._colorText = '';
this.setBlack();
};
/**
* The opacity of the sprite (0 to 255).
*
* @property opacity
* @type Number
*/
Object.defineProperty(ScreenSprite.prototype, 'opacity', {
get: function () {
return this.alpha * 255;
},
set: function (value) {
this.alpha = value.clamp(0, 255) / 255;
},
configurable: true
});
ScreenSprite.YEPWarned = false;
ScreenSprite.warnYep = function () {
if (!ScreenSprite.YEPWarned) {
console.log("Deprecation warning. Please update YEP_CoreEngine. ScreenSprite is not a sprite, it has graphics inside.");
ScreenSprite.YEPWarned = true;
}
};
Object.defineProperty(ScreenSprite.prototype, 'anchor', {
get: function () {
ScreenSprite.warnYep();
this.scale.x = 1;
this.scale.y = 1;
return {x: 0, y: 0};
},
set: function (value) {
this.alpha = value.clamp(0, 255) / 255;
},
configurable: true
});
Object.defineProperty(ScreenSprite.prototype, 'blendMode', {
get: function () {
return this._graphics.blendMode;
},
set: function (value) {
this._graphics.blendMode = value;
},
configurable: true
});
/**
* Sets black to the color of the screen sprite.
*
* @method setBlack
*/
ScreenSprite.prototype.setBlack = function () {
this.setColor(0, 0, 0);
};
/**
* Sets white to the color of the screen sprite.
*
* @method setWhite
*/
ScreenSprite.prototype.setWhite = function () {
this.setColor(255, 255, 255);
};
/**
* Sets the color of the screen sprite by values.
*
* @method setColor
* @param {Number} r The red value in the range (0, 255)
* @param {Number} g The green value in the range (0, 255)
* @param {Number} b The blue value in the range (0, 255)
*/
ScreenSprite.prototype.setColor = function (r, g, b) {
if (this._red !== r || this._green !== g || this._blue !== b) {
r = Math.round(r || 0).clamp(0, 255);
g = Math.round(g || 0).clamp(0, 255);
b = Math.round(b || 0).clamp(0, 255);
this._red = r;
this._green = g;
this._blue = b;
this._colorText = Utils.rgbToCssColor(r, g, b);
var graphics = this._graphics;
graphics.clear();
var intColor = (r << 16) | (g << 8) | b;
graphics.beginFill(intColor, 1);
//whole screen with zoom. BWAHAHAHAHA
graphics.drawRect(-Graphics.width * 5, -Graphics.height * 5, Graphics.width * 10, Graphics.height * 10);
}
};