import 'p2' ; import 'pixi' ; import 'phaser' ; import { Sounds , Atlases } from '../Data' ; import SoundManager from '../Managers/SoundManager' ; export default class ToggleButton extends Phaser . Button { protected id : string ; private currentSpr : string ; private sprite1 : string ; private sprite2 : string ; constructor ( game , x , y , sprite1 , sprite2 , callback , callbackContext ) { super ( game , x , y , Atlases . Interface , callback , callbackContext ) ; this . sprite1 = sprite1 ; this . sprite2 = sprite2 ; this . currentSpr = this . sprite1 ; this . setFrames ( this . sprite1 , this . sprite1 , this . sprite1 , this . sprite1 ) ; this . anchor . set ( 0.5 ) ; this . onInputUp . add ( this . playSound , this ) ; this . game . add . existing ( this ) ; } public toggle ( ) { let newSprite = this . currentSpr === this . sprite1 ? this . sprite2 : this . sprite1 ; this . setFrames ( newSprite , newSprite , newSprite , newSprite ) ; this . currentSpr = newSprite ; } param destroyChildren public destroy ( destroyChildren ? ) { this . id = null ; super . destroy ( destroyChildren ) ; } param destroyChildren private playSound ( ) { SoundManager . getInstance ( ) . play ( Sounds . Click ) ; } }