GameOverLayer.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Created by Administrator on 2014/8/19.
  3. */
  4. var GameOverLayer = cc.Layer.extend
  5. ({
  6. target:null,
  7. shareSprite:null,
  8. menu:null,
  9. setCallback:function(target){
  10. this.target = target;
  11. },
  12. textLable:null,
  13. setText:function(text){
  14. if(!this.textLable){
  15. this.textLable = cc.LabelTTF.create(text,"微软雅黑",15);
  16. this.textLable.setColor(cc.c3b(0,0,0));
  17. this.textLable.setPosition(this.winSize.width/2,this.winSize.height/2-9);
  18. this.addChild(this.textLable);
  19. }else{
  20. this.textLable.setString(text);
  21. }
  22. },
  23. ctor:function () {
  24. this._super();
  25. if( 'touches' in sys.capabilities ){
  26. this.setTouchEnabled(true);
  27. }
  28. else if ('mouse' in sys.capabilities )
  29. this.setMouseEnabled(true);
  30. },
  31. onEnter:function()
  32. {
  33. cc.registerTargetedDelegate(-126, true, this);
  34. this._super();
  35. },
  36. onExit:function(){
  37. cc.unregisterTouchDelegate(this);
  38. this._super();
  39. },
  40. init:function() {
  41. this._super();
  42. this.winSize = cc.Director.getInstance().getWinSize();
  43. var dialog = cc.Sprite.create(res_dialog_bg);
  44. dialog.setPosition(this.winSize.width/2,this.winSize.height/2);
  45. this.addChild(dialog);
  46. var head2 = cc.Sprite.create(head2Src);
  47. head2.setPosition(this.winSize.width/2+75,this.winSize.height/2+50);
  48. this.addChild(head2);
  49. var $this = this;
  50. var agin = cc.MenuItemImage.create(res_agin_btn,res_agin_btn,function(){
  51. $this.target.aginGame();
  52. });
  53. agin.setPosition(-90,-50);
  54. var more = cc.MenuItemImage.create(res_more_btn,res_more_btn,function(){
  55. try {
  56. _hmt.push(['_trackEvent', 'escape', 'click', 'more', '1']);
  57. } catch(e) {}
  58. window.open("http://game.ikongzhong.cn");
  59. });
  60. more.setPosition(0,-50);
  61. var share = cc.MenuItemImage.create(res_share_btn,res_share_btn,function(){
  62. try {
  63. _hmt.push(['_trackEvent', 'escape', 'click', 'share', '1']);
  64. } catch(e) {}
  65. $(".ad_banner").css("display","none");
  66. $this.menu.setEnabled(false);
  67. $this.shareSprite = cc.Sprite.create(res_share);
  68. $this.shareSprite.setPosition($this.winSize.width- $this.shareSprite.getContentSize().width/2,$this.winSize.height- $this.shareSprite.getContentSize().height/2);
  69. $this.addChild($this.shareSprite );
  70. });
  71. share.setPosition(90,-50);
  72. this.menu = cc.Menu.create(agin,more,share);
  73. this.menu.setTouchPriority(-126);
  74. this.addChild( this.menu);
  75. return true;
  76. },
  77. onTouchBegan:function (touch, event) {
  78. if(this.shareSprite){
  79. this.shareSprite.removeFromParent();
  80. this.menu.setEnabled(true);
  81. $(".ad_banner").css("display","inline");
  82. }
  83. return true;
  84. },
  85. onTouchMoved:function (touch, event) {
  86. },
  87. onTouchEnded:function (touch, event) {
  88. }
  89. });
  90. GameOverLayer.create = function (time,text,word) {
  91. var sg = new GameOverLayer();
  92. if (sg && sg.init())
  93. {
  94. sg.setText( "这次坚持了"+time.toFixed(2)+"秒,击败了全国"+text+"%的\n人,算是"+word+"了");
  95. return sg;
  96. }
  97. return null;
  98. };