Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/lib/menuItem.js
1036 views
1
2
function menuItem( image )
3
{
4
if ( typeof(image) != 'string' )
5
{
6
throw 'Constructor argument must be text';
7
}
8
9
var _image = gamejs.image.load(image);
10
var _size = _image.getSize();
11
var _active = false;
12
var _callback = null;
13
14
this.setActive = function( active ){
15
if ( typeof(active) != 'boolean' )
16
{
17
throw 'Active flag must be boolean';
18
}
19
20
var rect = new gamejs.Rect([0,0],[parseInt(_size[0] / 2), _size[1]]);
21
22
if ( active )
23
{
24
rect.x = parseInt(_size[0] / 2);
25
}
26
27
_image.crop(rect);
28
_active = active;
29
30
return this;
31
}
32
33
this.addCallback = function( callback ){
34
if ( typeof(callback) !== 'function' )
35
{
36
throw 'Callback must be a function';
37
}
38
39
_callback = callback;
40
return this;
41
}
42
43
this.setText = function( text ){
44
if ( typeof(text) != 'string' )
45
{
46
throw 'Text argument must be text';
47
}
48
49
_text = text;
50
return this;
51
}
52
53
this.getCanvas = function(){
54
return _image;
55
}
56
}
57