CCTransitionPageTurn.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /****************************************************************************
  2. Copyright (c) 2010-2012 cocos2d-x.org
  3. Copyright (c) 2008-2010 Ricardo Quesada
  4. Copyright (c) 2011 Zynga 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.getInstance().setDepthBufferFormat(kDepthBuffer16);</p>
  30. * @class
  31. * @extends cc.TransitionScene
  32. */
  33. cc.TransitionPageTurn = cc.TransitionScene.extend(/** @lends cc.TransitionPageTurn# */{
  34. /**
  35. * @type Boolean
  36. */
  37. _back:true,
  38. /**
  39. * Creates a base transition with duration and incoming scene.<br/>
  40. * If back is true then the effect is reversed to appear as if the incoming<br/>
  41. * scene is being turned from left over the outgoing scene.
  42. * @param {Number} t time in seconds
  43. * @param {cc.Scene} scene
  44. * @param {Boolean} backwards
  45. * @return {Boolean}
  46. */
  47. initWithDuration:function (t, scene, backwards) {
  48. // XXX: needed before [super init]
  49. this._back = backwards;
  50. if (cc.TransitionScene.prototype.initWithDuration.call(this, t, scene)) {
  51. // do something
  52. }
  53. return true;
  54. },
  55. /**
  56. * @param {cc.Size} vector
  57. * @return {cc.ReverseTime|cc.TransitionScene}
  58. */
  59. actionWithSize:function (vector) {
  60. if (this._back)
  61. return cc.ReverseTime.create(cc.PageTurn3D.create(this._duration, vector)); // Get hold of the PageTurn3DAction
  62. else
  63. return cc.PageTurn3D.create(this._duration, vector); // Get hold of the PageTurn3DAction
  64. },
  65. /**
  66. * custom on enter
  67. */
  68. onEnter:function () {
  69. cc.TransitionScene.prototype.onEnter.call(this);
  70. var winSize = cc.Director.getInstance().getWinSize();
  71. var x, y;
  72. if (winSize.width > winSize.height) {
  73. x = 16;
  74. y = 12;
  75. } else {
  76. x = 12;
  77. y = 16;
  78. }
  79. var action = this.actionWithSize(cc.size(x, y));
  80. if (!this._back) {
  81. this._outScene.runAction( cc.Sequence.create(action,cc.CallFunc.create(this.finish, this),cc.StopGrid.create()));
  82. } else {
  83. // to prevent initial flicker
  84. this._inScene.setVisible(false);
  85. this._inScene.runAction(
  86. cc.Sequence.create(cc.Show.create(),action, cc.CallFunc.create(this.finish, this), cc.StopGrid.create())
  87. );
  88. }
  89. },
  90. _sceneOrder:function () {
  91. this._isInSceneOnTop = this._back;
  92. }
  93. });
  94. /**
  95. * Creates a base transition with duration and incoming scene.<br/>
  96. * If back is true then the effect is reversed to appear as if the incoming<br/>
  97. * scene is being turned from left over the outgoing scene.
  98. * @param {Number} t time in seconds
  99. * @param {cc.Scene} scene
  100. * @param {Boolean} backwards
  101. * @return {cc.TransitionPageTurn}
  102. * @example
  103. * // Example
  104. * var myTransition = cc.TransitionPageTurn.create(1.5, nextScene, true)//true means backwards
  105. */
  106. cc.TransitionPageTurn.create = function (t, scene, backwards) {
  107. var transition = new cc.TransitionPageTurn();
  108. transition.initWithDuration(t, scene, backwards);
  109. return transition;
  110. };