Path: blob/main/public/games/files/algaes-escapade/js/lib/menuItem.js
1036 views
1function menuItem( image )2{3if ( typeof(image) != 'string' )4{5throw 'Constructor argument must be text';6}78var _image = gamejs.image.load(image);9var _size = _image.getSize();10var _active = false;11var _callback = null;1213this.setActive = function( active ){14if ( typeof(active) != 'boolean' )15{16throw 'Active flag must be boolean';17}1819var rect = new gamejs.Rect([0,0],[parseInt(_size[0] / 2), _size[1]]);2021if ( active )22{23rect.x = parseInt(_size[0] / 2);24}2526_image.crop(rect);27_active = active;2829return this;30}3132this.addCallback = function( callback ){33if ( typeof(callback) !== 'function' )34{35throw 'Callback must be a function';36}3738_callback = callback;39return this;40}4142this.setText = function( text ){43if ( typeof(text) != 'string' )44{45throw 'Text argument must be text';46}4748_text = text;49return this;50}5152this.getCanvas = function(){53return _image;54}55}5657