/libs/cocos2d/CCPageTurnTransition.m

http://github.com/kstenerud/ObjectAL-for-iPhone · Objective C · 115 lines · 68 code · 15 blank · 32 comment · 4 complexity · 5ab2255927d5539e113558f93aec4c55 MD5 · raw file

  1. /*
  2. * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3. *
  4. * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
  5. *
  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. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. */
  25. #import "CCPageTurnTransition.h"
  26. #import "CCPageTurn3DAction.h"
  27. #import "CCDirector.h"
  28. @implementation CCPageTurnTransition
  29. /** creates a base transition with duration and incoming scene */
  30. +(id) transitionWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back
  31. {
  32. return [[[self alloc] initWithDuration:t scene:s backwards:back] autorelease];
  33. }
  34. /** initializes a transition with duration and incoming scene */
  35. -(id) initWithDuration:(ccTime) t scene:(CCScene*)s backwards:(BOOL) back
  36. {
  37. // XXX: needed before [super init]
  38. back_ = back;
  39. if( ( self = [super initWithDuration:t scene:s] ) )
  40. {
  41. // do something
  42. }
  43. return self;
  44. }
  45. -(void) sceneOrder
  46. {
  47. inSceneOnTop = back_;
  48. }
  49. //
  50. -(void) onEnter
  51. {
  52. [super onEnter];
  53. CGSize s = [[CCDirector sharedDirector] winSize];
  54. int x,y;
  55. if( s.width > s.height)
  56. {
  57. x=16;y=12;
  58. }
  59. else
  60. {
  61. x=12;y=16;
  62. }
  63. id action = [self actionWithSize:ccg(x,y)];
  64. if(! back_ )
  65. {
  66. [outScene runAction: [CCSequence actions:
  67. action,
  68. [CCCallFunc actionWithTarget:self selector:@selector(finish)],
  69. [CCStopGrid action],
  70. nil]
  71. ];
  72. }
  73. else
  74. {
  75. // to prevent initial flicker
  76. inScene.visible = NO;
  77. [inScene runAction: [CCSequence actions:
  78. [CCShow action],
  79. action,
  80. [CCCallFunc actionWithTarget:self selector:@selector(finish)],
  81. [CCStopGrid action],
  82. nil]
  83. ];
  84. }
  85. }
  86. -(CCIntervalAction*) actionWithSize: (ccGridSize) v
  87. {
  88. if( back_ )
  89. {
  90. // Get hold of the PageTurn3DAction
  91. return [CCReverseTime actionWithAction:
  92. [CCPageTurn3D actionWithSize:v duration:duration]];
  93. }
  94. else
  95. {
  96. // Get hold of the PageTurn3DAction
  97. return [CCPageTurn3D actionWithSize:v duration:duration];
  98. }
  99. }
  100. @end