diff options
Diffstat (limited to 'libs/cocos2d/CCTransitionRadial.m')
| -rwxr-xr-x | libs/cocos2d/CCTransitionRadial.m | 115 |
1 files changed, 115 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCTransitionRadial.m b/libs/cocos2d/CCTransitionRadial.m new file mode 100755 index 0000000..a892f35 --- /dev/null +++ b/libs/cocos2d/CCTransitionRadial.m | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Lam Pham | ||
| 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 | |||
| 26 | |||
| 27 | |||
| 28 | #import "CCDirector.h" | ||
| 29 | #import "CCTransitionRadial.h" | ||
| 30 | #import "CCRenderTexture.h" | ||
| 31 | #import "CCLayer.h" | ||
| 32 | #import "CCActionInstant.h" | ||
| 33 | #import "Support/CGPointExtension.h" | ||
| 34 | |||
| 35 | enum { | ||
| 36 | kSceneRadial = 0xc001, | ||
| 37 | }; | ||
| 38 | |||
| 39 | #pragma mark - | ||
| 40 | #pragma mark Transition Radial CCW | ||
| 41 | |||
| 42 | @implementation CCTransitionRadialCCW | ||
| 43 | -(void) sceneOrder | ||
| 44 | { | ||
| 45 | inSceneOnTop_ = NO; | ||
| 46 | } | ||
| 47 | |||
| 48 | -(CCProgressTimerType) radialType | ||
| 49 | { | ||
| 50 | return kCCProgressTimerTypeRadialCCW; | ||
| 51 | } | ||
| 52 | |||
| 53 | -(void) onEnter | ||
| 54 | { | ||
| 55 | [super onEnter]; | ||
| 56 | // create a transparent color layer | ||
| 57 | // in which we are going to add our rendertextures | ||
| 58 | CGSize size = [[CCDirector sharedDirector] winSize]; | ||
| 59 | |||
| 60 | // create the second render texture for outScene | ||
| 61 | CCRenderTexture *outTexture = [CCRenderTexture renderTextureWithWidth:size.width height:size.height]; | ||
| 62 | outTexture.sprite.anchorPoint= ccp(0.5f,0.5f); | ||
| 63 | outTexture.position = ccp(size.width/2, size.height/2); | ||
| 64 | outTexture.anchorPoint = ccp(0.5f,0.5f); | ||
| 65 | |||
| 66 | // render outScene to its texturebuffer | ||
| 67 | [outTexture clear:0 g:0 b:0 a:1]; | ||
| 68 | [outTexture begin]; | ||
| 69 | [outScene_ visit]; | ||
| 70 | [outTexture end]; | ||
| 71 | |||
| 72 | // Since we've passed the outScene to the texture we don't need it. | ||
| 73 | [self hideOutShowIn]; | ||
| 74 | |||
| 75 | // We need the texture in RenderTexture. | ||
| 76 | CCProgressTimer *outNode = [CCProgressTimer progressWithTexture:outTexture.sprite.texture]; | ||
| 77 | // but it's flipped upside down so we flip the sprite | ||
| 78 | outNode.sprite.flipY = YES; | ||
| 79 | // Return the radial type that we want to use | ||
| 80 | outNode.type = [self radialType]; | ||
| 81 | outNode.percentage = 100.f; | ||
| 82 | outNode.position = ccp(size.width/2, size.height/2); | ||
| 83 | outNode.anchorPoint = ccp(0.5f,0.5f); | ||
| 84 | |||
| 85 | // create the blend action | ||
| 86 | CCActionInterval * layerAction = [CCSequence actions: | ||
| 87 | [CCProgressFromTo actionWithDuration:duration_ from:100.f to:0.f], | ||
| 88 | [CCCallFunc actionWithTarget:self selector:@selector(finish)], | ||
| 89 | nil ]; | ||
| 90 | // run the blend action | ||
| 91 | [outNode runAction: layerAction]; | ||
| 92 | |||
| 93 | // add the layer (which contains our two rendertextures) to the scene | ||
| 94 | [self addChild: outNode z:2 tag:kSceneRadial]; | ||
| 95 | } | ||
| 96 | |||
| 97 | // clean up on exit | ||
| 98 | -(void) onExit | ||
| 99 | { | ||
| 100 | // remove our layer and release all containing objects | ||
| 101 | [self removeChildByTag:kSceneRadial cleanup:NO]; | ||
| 102 | [super onExit]; | ||
| 103 | } | ||
| 104 | @end | ||
| 105 | |||
| 106 | #pragma mark - | ||
| 107 | #pragma mark Transition Radial CW | ||
| 108 | |||
| 109 | @implementation CCTransitionRadialCW | ||
| 110 | -(CCProgressTimerType) radialType | ||
| 111 | { | ||
| 112 | return kCCProgressTimerTypeRadialCW; | ||
| 113 | } | ||
| 114 | @end | ||
| 115 | |||
