Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

Commit

Permalink
Rename speed to timeScale to avoid ambiguity with other nodes that al…
Browse files Browse the repository at this point in the history
…ready have a 'speed'. Also add support for node-schedules.
  • Loading branch information
lhunath committed Aug 23, 2011
1 parent 615dde2 commit f2ce7e6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cocos2d/CCAction.h
Expand Up @@ -33,7 +33,7 @@
enum {
//! Default tag
kCCActionTagInvalid = -1,
kCCActionTagIgnoreSpeed = -2,
kCCActionTagIgnoreTimeScale = -2,
};

/** Base class for CCAction objects.
Expand Down
2 changes: 2 additions & 0 deletions cocos2d/CCActionManager.h
Expand Up @@ -107,5 +107,7 @@ typedef struct _hashElement
*/
-(void) resumeTarget:(id)target;

+ (float)timeScaleForTarget:(id)target;

@end

26 changes: 15 additions & 11 deletions cocos2d/CCActionManager.m
Expand Up @@ -28,6 +28,7 @@


#import "CCActionManager.h"
#import "CCNode.h"
#import "CCScheduler.h"
#import "ccMacros.h"

Expand All @@ -47,7 +48,6 @@ @interface CCActionManager (Private)
-(void) removeActionAtIndex:(NSUInteger)index hashElement:(tHashElement*)element;
-(void) deleteHashElement:(tHashElement*)element;
-(void) actionAllocWithHashElement:(tHashElement*)element;
-(float) speedForTarget:(id)target;
@end


Expand Down Expand Up @@ -317,11 +317,11 @@ -(void) update: (ccTime) dt
currentTarget->currentAction = currentTarget->actions->arr[currentTarget->actionIndex];
currentTarget->currentActionSalvaged = NO;

float speed = 1.0f;
if (currentTarget->currentAction.tag != kCCActionTagIgnoreSpeed)
speed = [self speedForTarget:currentTarget->target];
float timeScale = 1.0f;
if (currentTarget->currentAction.tag != kCCActionTagIgnoreTimeScale)
timeScale = [CCActionManager timeScaleForTarget:currentTarget->target];

[currentTarget->currentAction step: dt * speed];
[currentTarget->currentAction step: dt * timeScale];

if( currentTarget->currentActionSalvaged ) {
// The currentAction told the node to remove it. To prevent the action from
Expand Down Expand Up @@ -355,15 +355,19 @@ -(void) update: (ccTime) dt
currentTarget = nil;
}

- (float)speedForTarget:(id)target {
+ (float)timeScaleForTarget:(id)target {

float speed = 1.0f;
if ([target respondsToSelector:@selector(speed)])
speed *= [target speed];
if ([target respondsToSelector:@selector(tag)])
if ([target tag] == kCCNodeTagIgnoreTimeScale)
return 1.0f;

float timeScale = 1.0f;
if ([target respondsToSelector:@selector(timeScale)])
timeScale *= [target timeScale];
if ([target respondsToSelector:@selector(parent)])
speed *= [self speedForTarget:[target parent]];
timeScale *= [self timeScaleForTarget:[target parent]];

return speed;
return timeScale;
}

@end
1 change: 1 addition & 0 deletions cocos2d/CCNode.h
Expand Up @@ -37,6 +37,7 @@

enum {
kCCNodeTagInvalid = -1,
kCCNodeTagIgnoreTimeScale = -2,
};

@class CCCamera;
Expand Down
7 changes: 4 additions & 3 deletions cocos2d/CCScheduler.m
Expand Up @@ -26,6 +26,7 @@

// cocos2d imports
#import "CCScheduler.h"
#import "CCActionManager.h"
#import "ccMacros.h"
#import "Support/uthash.h"
#import "Support/utlist.h"
Expand Down Expand Up @@ -558,21 +559,21 @@ -(void) tick: (ccTime) dt
// updates with priority < 0
DL_FOREACH_SAFE( updatesNeg, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
entry->impMethod( entry->target, updateSelector, dt );
entry->impMethod( entry->target, updateSelector, dt * [CCActionManager timeScaleForTarget:entry->target] );
}

// updates with priority == 0
DL_FOREACH_SAFE( updates0, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
{
entry->impMethod( entry->target, updateSelector, dt );
entry->impMethod( entry->target, updateSelector, dt * [CCActionManager timeScaleForTarget:entry->target] );
}
}

// updates with priority > 0
DL_FOREACH_SAFE( updatesPos, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
entry->impMethod( entry->target, updateSelector, dt );
entry->impMethod( entry->target, updateSelector, dt * [CCActionManager timeScaleForTarget:entry->target] );
}

// Iterate all over the custome selectors
Expand Down

0 comments on commit f2ce7e6

Please sign in to comment.