CCTransitionPageTurn.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2011-2012 cocos2d-x.org
  4. Copyright (c) 2013-2014 Chukong Technologies Inc.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. /**
  23. *<p> A transition which peels back the bottom right hand corner of a scene<br/>
  24. * to transition to the scene beneath it simulating a page turn.<br/></p>
  25. *
  26. * <p>This uses a 3DAction so it's strongly recommended that depth buffering<br/>
  27. * is turned on in cc.director using:</p>
  28. *
  29. * <p>cc.director.setDepthBufferFormat(kDepthBuffer16);</p>
  30. * @class
  31. * @extends cc.TransitionScene
  32. * @param {Number} t time in seconds
  33. * @param {cc.Scene} scene
  34. * @param {Boolean} backwards
  35. * @example
  36. * var trans = new cc.TransitionPageTurn(t, scene, backwards);
  37. */
  38. cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTurn# */{
  39. /**
  40. * @param {Number} t time in seconds
  41. * @param {cc.Scene} scene
  42. * @param {Boolean} backwards
  43. */
  44. ctor:function (t, scene, backwards) {
  45. cc.TransitionScene.prototype.ctor.call(this);
  46. this.initWithDuration(t, scene, backwards);
  47. },
  48. /**
  49. * @type Boolean
  50. */
  51. _back:true,
  52. _className:"TransitionPageTurn",
  53. /**
  54. * Creates a base transition with duration and incoming scene.<br/>
  55. * If back is true then the effect is reversed to appear as if the incoming<br/>
  56. * scene is being turned from left over the outgoing scene.
  57. * @param {Number} t time in seconds
  58. * @param {cc.Scene} scene
  59. * @param {Boolean} backwards
  60. * @return {Boolean}
  61. */
  62. initWithDuration:function (t, scene, backwards) {
  63. // XXX: needed before [super init]
  64. this._back = backwards;
  65. if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) {
  66. // do something
  67. }
  68. return true;
  69. },
  70. /**
  71. * @param {cc.Size} vector
  72. * @return {cc.ReverseTime|cc.TransitionScene}
  73. */
  74. actionWithSize:function (vector) {
  75. if (this._back)
  76. return cc.reverseTime(cc.pageTurn3D(this._duration, vector)); // Get hold of the PageTurn3DAction
  77. else
  78. return cc.pageTurn3D(this._duration, vector); // Get hold of the PageTurn3DAction
  79. },
  80. /**
  81. * custom on enter
  82. */
  83. onEnter:function () {
  84. cc.TransitionScene.prototype.onEnter.call(this);
  85. var winSize = cc.director.getWinSize();
  86. var x, y;
  87. if (winSize.width > winSize.height) {
  88. x = 16;
  89. y = 12;
  90. } else {
  91. x = 12;
  92. y = 16;
  93. }
  94. var action = this.actionWithSize(cc.size(x, y));
  95. if (!this._back) {
  96. this._outScene.runAction( cc.sequence(action,cc.CallFunc.create(this.finish, this),cc.StopGrid.create()));
  97. } else {
  98. // to prevent initial flicker
  99. this._inScene.visible = false;
  100. this._inScene.runAction(
  101. cc.sequence(cc.show(),action, cc.callFunc(this.finish, this), cc.stopGrid())
  102. );
  103. }
  104. },
  105. _sceneOrder:function () {
  106. this._isInSceneOnTop = this._back;
  107. }
  108. });
  109. /**
  110. * Creates a base transition with duration and incoming scene.<br/>
  111. * If back is true then the effect is reversed to appear as if the incoming<br/>
  112. * scene is being turned from left over the outgoing scene.
  113. * @deprecated since v3.0,please use new cc.TransitionPageTurn(t, scene, backwards) instead.
  114. * @param {Number} t time in seconds
  115. * @param {cc.Scene} scene
  116. * @param {Boolean} backwards
  117. * @return {cc.TransitionPageTurn}
  118. * @example
  119. * var myTransition = cc.TransitionPageTurn.create(1.5, nextScene, true)//true means backwards
  120. */
  121. cc.TransitionPageTurn.create = function (t, scene, backwards) {
  122. return new cc.TransitionPageTurn(t, scene, backwards);
  123. };