diff options
| author | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
|---|---|---|
| committer | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
| commit | 9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch) | |
| tree | 5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCActionProgressTimer.m | |
| download | cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2 cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip | |
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCActionProgressTimer.m')
| -rwxr-xr-x | libs/cocos2d/CCActionProgressTimer.m | 103 |
1 files changed, 103 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCActionProgressTimer.m b/libs/cocos2d/CCActionProgressTimer.m new file mode 100755 index 0000000..c242570 --- /dev/null +++ b/libs/cocos2d/CCActionProgressTimer.m | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 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 | #import "CCActionProgressTimer.h" | ||
| 28 | |||
| 29 | #define kProgressTimerCast CCProgressTimer* | ||
| 30 | |||
| 31 | @implementation CCProgressTo | ||
| 32 | +(id) actionWithDuration: (ccTime) t percent: (float) v | ||
| 33 | { | ||
| 34 | return [[[ self alloc] initWithDuration: t percent: v] autorelease]; | ||
| 35 | } | ||
| 36 | |||
| 37 | -(id) initWithDuration: (ccTime) t percent: (float) v | ||
| 38 | { | ||
| 39 | if( (self=[super initWithDuration: t] ) ) | ||
| 40 | to_ = v; | ||
| 41 | |||
| 42 | return self; | ||
| 43 | } | ||
| 44 | |||
| 45 | -(id) copyWithZone: (NSZone*) zone | ||
| 46 | { | ||
| 47 | CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ percent:to_]; | ||
| 48 | return copy; | ||
| 49 | } | ||
| 50 | |||
| 51 | -(void) startWithTarget:(id) aTarget; | ||
| 52 | { | ||
| 53 | [super startWithTarget:aTarget]; | ||
| 54 | from_ = [(kProgressTimerCast)target_ percentage]; | ||
| 55 | |||
| 56 | // XXX: Is this correct ? | ||
| 57 | // Adding it to support CCRepeat | ||
| 58 | if( from_ == 100) | ||
| 59 | from_ = 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | -(void) update: (ccTime) t | ||
| 63 | { | ||
| 64 | [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; | ||
| 65 | } | ||
| 66 | @end | ||
| 67 | |||
| 68 | @implementation CCProgressFromTo | ||
| 69 | +(id) actionWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage | ||
| 70 | { | ||
| 71 | return [[[self alloc] initWithDuration: t from: fromPercentage to: toPercentage] autorelease]; | ||
| 72 | } | ||
| 73 | |||
| 74 | -(id) initWithDuration: (ccTime) t from:(float)fromPercentage to:(float) toPercentage | ||
| 75 | { | ||
| 76 | if( (self=[super initWithDuration: t] ) ){ | ||
| 77 | to_ = toPercentage; | ||
| 78 | from_ = fromPercentage; | ||
| 79 | } | ||
| 80 | return self; | ||
| 81 | } | ||
| 82 | |||
| 83 | -(id) copyWithZone: (NSZone*) zone | ||
| 84 | { | ||
| 85 | CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration:duration_ from:from_ to:to_]; | ||
| 86 | return copy; | ||
| 87 | } | ||
| 88 | |||
| 89 | - (CCActionInterval *) reverse | ||
| 90 | { | ||
| 91 | return [[self class] actionWithDuration:duration_ from:to_ to:from_]; | ||
| 92 | } | ||
| 93 | |||
| 94 | -(void) startWithTarget:(id) aTarget; | ||
| 95 | { | ||
| 96 | [super startWithTarget:aTarget]; | ||
| 97 | } | ||
| 98 | |||
| 99 | -(void) update: (ccTime) t | ||
| 100 | { | ||
| 101 | [(kProgressTimerCast)target_ setPercentage: from_ + ( to_ - from_ ) * t]; | ||
| 102 | } | ||
| 103 | @end | ||
