HiddingButton.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. HiddingButton = function ( game, group, x, y, hideX, hideY, art, price ) {
  2. Phaser.Group.call(this, game );
  3. group.add( this );
  4. this.x = x;
  5. this.y = y;
  6. this.scale.set( 0.8, 0.8 );
  7. this.price = price;
  8. this.sprite = this.create(0,0, 'sprites', art );
  9. this.sprite.inputEnabled = true;
  10. this.events = this.sprite.events;
  11. if( price ){
  12. var style_price = {font:'Bold '+scaleValue(20)+'px Arial', fill: '#ffffff', align: 'right'};
  13. this.labelPrice = this.game.add.text( this.width+scaleValue(5) , this.height-scaleValue(10), ''+price, style_price, this );
  14. this.labelPrice.anchor.set( 1, 0 );
  15. }
  16. this.scaleTween = this.game.add.tween( this.scale );
  17. this.hideX = hideX;
  18. this.hideY = hideY;
  19. this.origX = x;
  20. this.origY = y;
  21. this.tween = this.game.add.tween( this );
  22. };
  23. HiddingButton.prototype = Object.create(Phaser.Group.prototype);
  24. HiddingButton.prototype.constructor = HiddingButton;
  25. var p = HiddingButton.prototype;
  26. p.touch = function() {
  27. this.scaleTween._parent = null;
  28. this.scaleTween._lastChild = null;
  29. this.scaleTween.to( {x:0.7, y:0.7}, 50, Phaser.Easing.Quadratic.Out, true, 0, 0, true);
  30. };
  31. p.setLabel = function( text ){
  32. var style_name = {font:'Bold '+scaleValue(12)+'px Arial', fill: '#ffffff', align: 'center'};
  33. this.labelName= this.game.add.text( this.sprite.width/2 , -scaleValue(4), text, style_name, this );
  34. this.labelName.anchor.set( 0.5, 1 );
  35. };
  36. p.hide = function( animate, playTime ) {
  37. var time = 100;
  38. if( !animate ){
  39. this.x = this.hideX;
  40. this.y = this.hideY;
  41. this.visible = false;
  42. return;
  43. }
  44. if( playTime!=null )
  45. time = playTime;
  46. this.sprite.inputEnabled = false;
  47. this.tween._parent = null;
  48. this.tween._lastChild = null;
  49. this.tween.onComplete.removeAll();
  50. this.tween.onComplete.add( function(){this.visible = false;}, this );
  51. this.tween.to( {x: this.hideX, y:this.hideY}, time, Phaser.Easing.Sinusoidal.Out, true );
  52. };
  53. p.show = function( animate, playTime ) {
  54. var time = 100;
  55. if( !animate ){
  56. this.x = this.origX;
  57. this.y = this.origY;
  58. this.visible = true;
  59. return;
  60. }
  61. if( playTime!=null )
  62. time = playTime;
  63. this.visible = true;
  64. this.sprite.inputEnabled = true;
  65. this.tween._parent = null;
  66. this.tween._lastChild = null;
  67. this.tween.onComplete.removeAll();
  68. this.tween.to( {x: this.origX, y:this.origY}, time, Phaser.Easing.Sinusoidal.In, true );
  69. };