Permalink
Browse files

ease demo: shows how to alter time (speed) in runtime. issue #236

  • Loading branch information...
1 parent e8df2fe commit b2b68ea05725048199cdedfbe4428a9a4197cacb @ricardoquesada ricardoquesada committed Mar 12, 2009
View
@@ -64,7 +64,7 @@ Poeple/companies who were/are contributing code to cocos2d for iPhone (alphabeti
Treat warnings as errors patch
Action's elapsed is property patch
MenuItemFont label can be changed
- Menu can be aligned in Columns
+ Menu can be aligned in Columns and Rows
MenuItem supports LabelAtlas
Added RGB protocol in CocosNode, Atlas, Texture
* mark at abitofthought: author of Fast Director
@@ -85,6 +85,7 @@ Poeple/companies who were/are contributing code to cocos2d for iPhone (alphabeti
* Steve Oldmeadow: patches for Texture2D
* Valentin Milea: clean up CocosNode, added better comments to CocosNode
Set transformAnchor point in Sprite
+ Actions can have tags
* yarrington: patches for Director
View
@@ -1,4 +1,7 @@
-version 0.7.1 - ??
+version 0.7.1 - ??-Mar-2009
+ . Actions: added tags to actions (issue #222)
+ . Actions: Spawns can be Speeded (issue #257)
+ . Actions: Speed can be altered in runtime (part of issue #236)
. AtlasSprite: new feature (issue #238)
. CocosNode: Camera is lazy alloced (issue #94)
. CocosNode: addChild, removeChild:cleanup, getChildByTag family functions (issue #253)
@@ -12,7 +15,7 @@ version 0.7.1 - ??
. Demos: added performance test (issue #243)
. Director: FastDirector doesn't leak autoreleased objects (issue #221)
. Director: prevents calling startAnimation twice in a row (issue #215)
- . Menu: can be aligned in columns (issue #206)
+ . Menu: can be aligned in columns / rows. Updated menu example (issue #206)
. Menu: MenuItem supports LabelAtlas (issue #235)
. Scheduler: if signature is not correct Assert (issue #218)
. Sprite: correct transform anchor point (issue #216)
View
@@ -99,17 +99,11 @@ enum {
// actions
NSMutableArray *actions;
-
- // (vali) make the following 3 @private?
NSMutableArray *actionsToRemove;
NSMutableArray *actionsToAdd;
// scheduled selectors
- NSMutableDictionary *scheduledSelectors;
-
- // time scaling.
- ccTime timeScaleDuration;
- float timeScale, timeScaleTarget;
+ NSMutableDictionary *scheduledSelectors;
}
/** The z order of the node relative to it's "brothers": children of the same parent */
@@ -118,8 +112,6 @@ enum {
@property(readwrite,assign) float rotation;
/** The scale factor of the node. 1.0 is the default scale factor */
@property(readwrite,assign) float scale, scaleX, scaleY;
-/** The time scale factor of the node. 1.0 is the default scale factor. Higher scale causes time to progress faster while lower scale causes slowmotion. */
-@property(readwrite,assign) float timeScale;
/** The parallax ratio of the node. 1.0 is the default ratio */
@property(readwrite,assign) float parallaxRatio;
/** The X parallax ratio of the node. 1.0 is the default ratio */
@@ -304,20 +296,18 @@ enum {
-(Action*) runAction: (Action*) action;
/** Removes all actions from the running action list */
-(void) stopAllActions;
-/** Removes one action from the running action list */
+/** Removes an action from the running action list */
-(void) stopAction: (Action*) action;
+/** Removes an action from the running action list given its tag */
+-(void) stopActionByTag:(int) tag;
+/** Gets an action from the running action list given its tag */
+-(Action*) getActionByTag:(int) tag;
/** Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).
* Composable actions are counted as 1 action. Example:
* If you are running 1 Sequence of 7 actions, it will return 1.
* If you are running 7 Sequences of 2 actions, it will return 7.
*/
-(int) numberOfRunningActions;
-/** Start time scaling on this node and its children.
- * Time scale values higher than 1 will speed up this node's actions' time progression relative to its siblings'.
- * Time scale values lower than 1 will make this node appear to run its actions in slow motion.
- */
--(void) scaleTimeTo:(float)aTimeScale duration:(ccTime)aTimeScaleDuration;
-
// timers
View
@@ -39,7 +39,7 @@ -(void) detachChild:(CocosNode *)child cleanup:(BOOL)doCleanup;
@implementation CocosNode
-@synthesize rotation, timeScale, scaleX, scaleY, position, parallaxRatioX, parallaxRatioY;
+@synthesize rotation, scaleX, scaleY, position, parallaxRatioX, parallaxRatioY;
@synthesize visible;
@synthesize transformAnchor, relativeTransformAnchor;
@synthesize parent, children;
@@ -94,11 +94,7 @@ -(id) init
// default.
// "whole screen" objects should set it to NO, like Scenes and Layers
relativeTransformAnchor = YES;
-
- // default time scale.
- timeScale = 1;
- timeScaleDuration = 0;
-
+
return self;
}
@@ -569,31 +565,66 @@ -(Action*) runAction:(Action*) action
-(void) stopAllActions
{
[actionsToAdd removeAllObjects];
-
+
[actionsToRemove removeAllObjects];
[actionsToRemove addObjectsFromArray:actions];
}
-(void) stopAction: (Action*) action
{
- if( [actionsToRemove containsObject:action] ) {
- // do nothing
- } else if( [actionsToAdd containsObject:action] ) {
- [actionsToAdd removeObject:action];
- } else if( [actions containsObject:action] ) {
+ if( [actions containsObject:action] )
[actionsToRemove addObject:action];
+
+ else if( [actionsToAdd containsObject:action] )
+ [actionsToAdd removeObject:action];
+ else
+ CCLOG(@"stopAction: action not found!");
+}
+
+-(void) stopActionByTag:(int) aTag
+{
+ NSAssert( aTag != kActionTagInvalid, @"Invalid tag");
+
+ // is running ?
+ for( Action *a in actions ) {
+ if( a.tag == aTag ) {
+ [actionsToRemove addObject:a];
+ return;
+ }
}
+ // is going to be added ?
+ for( Action *a in actionsToAdd ) {
+ if( a.tag == aTag ) {
+ [actionsToAdd removeObject:a];
+ return;
+ }
+ }
+ CCLOG(@"stopActionByTag: action not found!");
}
--(int) numberOfRunningActions
+-(Action*) getActionByTag:(int) aTag
{
- return [actionsToAdd count]+[actions count];
+ NSAssert( aTag != kActionTagInvalid, @"Invalid tag");
+
+ // is running ?
+ for( Action *a in actions ) {
+ if( a.tag == aTag )
+ return a;
+ }
+
+ // is going to be added ?
+ for( Action *a in actionsToAdd ) {
+ if( a.tag == aTag )
+ return a;
+ }
+
+ CCLOG(@"getActionByTag: action not found");
+ return nil;
}
--(void) scaleTimeTo:(float)aTimeScale duration:(ccTime)aTimeScaleDuration
+-(int) numberOfRunningActions
{
- timeScaleTarget = aTimeScale;
- timeScaleDuration = aTimeScaleDuration;
+ return [actionsToAdd count]+[actions count];
}
-(void) step_: (ccTime) dt
@@ -615,19 +646,7 @@ -(void) step_: (ccTime) dt
[self unschedule: @selector(step_:)];
return;
}
-
- // linear time scaling
- if(timeScaleDuration) {
- if(timeScale - timeScaleTarget < 0.1f) {
- timeScale = timeScaleTarget;
- timeScaleDuration = 0;
- }
- else
- timeScale += (timeScaleTarget - timeScale) * dt / timeScaleDuration;
- }
- for(CocosNode *node = self; node; node = node.parent)
- dt *= node.timeScale;
-
+
// Assume the instructions inside [action step: dt] end up calling cleanup on
// the current node. This could happen, for example, if the action is a CallFunc
// which tells the current node's parent to removeAndStop our node.
View
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * EaseAction by Jason Booth
+ * Copyright (C) 2008, 2009 Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
View
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * EaseAction by Jason Booth
+ * Copyright (C) 2008, 2009 Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
View
@@ -324,9 +324,9 @@ -(id) initOne: (IntervalAction*) one_ two: (IntervalAction*) two_
two = two_;
if( d1 > d2 )
- two = [Sequence actions: two_, [DelayTime actionWithDuration: (d1-d2)], nil];
+ two = [Sequence actionOne: two_ two:[DelayTime actionWithDuration: (d1-d2)] ];
else if( d1 < d2)
- one = [Sequence actions: one_, [DelayTime actionWithDuration: (d2-d1)], nil];
+ one = [Sequence actionOne: one_ two: [DelayTime actionWithDuration: (d2-d1)] ];
[one retain];
[two retain];
@@ -355,10 +355,6 @@ -(void) start
[two start];
}
--(BOOL) isDone
-{
- return [one isDone] && [two isDone];
-}
-(void) update: (ccTime) t
{
[one update:t];
View
@@ -37,11 +37,11 @@
-(void) alignItemsHorizontally;
/** align items in rows of columns */
--(void) alignItemsInColumns: (NSNumber *) columns, ...;
+-(void) alignItemsInColumns: (NSNumber *) columns, ... NS_REQUIRES_NIL_TERMINATION;
-(void) alignItemsInColumns: (NSNumber *) columns vaList: (va_list) args;
/** align items in columns of rows */
--(void) alignItemsInRows: (NSNumber *) rows, ...;
+-(void) alignItemsInRows: (NSNumber *) rows, ... NS_REQUIRES_NIL_TERMINATION;
-(void) alignItemsInRows: (NSNumber *) rows vaList: (va_list) args;
View
@@ -177,8 +177,6 @@ typedef struct sParticle
-(id) initWithTotalParticles:(int) numberOfParticles;
//! Add a particle to the emitter
-(BOOL) addParticle;
-//! Update all particles
--(void) update:(ccTime)dt;
//! Initializes a particle
-(void) initParticle: (Particle*) particle;
//! draw all the particles
View
@@ -172,23 +172,6 @@ -(void) initParticle: (Particle*) particle
}
-(void) step: (ccTime) dt
-{
- if(timeScaleDuration) {
- if(timeScale - timeScaleTarget < 0.1f) {
- timeScale = timeScaleTarget;
- timeScaleDuration = 0;
- }
- else
- timeScale += (timeScaleTarget - timeScale) * dt / timeScaleDuration;
- }
- for(CocosNode *node = self; node; node = node.parent)
- dt *= node.timeScale;
-
- if(dt)
- [self update:dt];
-}
-
--(void) update: (ccTime) dt
{
if( active && emissionRate ) {
float rate = 1.0f / emissionRate;
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * Motion Streak Class by Jason Booth
+ * Copyright (C) 2008, 2009 by Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * Motion Streak Class by Jason Booth
+ * Copyright (C) 2008, 2009 Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
View
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * Ribbon Class by Jason Booth
+ * Copyright (C) 2008, 2009 Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
View
@@ -2,9 +2,7 @@
*
* http://code.google.com/p/cocos2d-iphone
*
- * Copyright (C) 2008 Ricardo Quesada
- *
- * Ribbon Class by Jason Booth
+ * Copyright (C) 2008, 2009 Jason Booth
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
View
@@ -48,3 +48,7 @@
@interface SpriteEaseSineInOut : SpriteDemo
{}
@end
+
+@interface Speed1 : SpriteDemo
+{}
+@end
Oops, something went wrong.

0 comments on commit b2b68ea

Please sign in to comment.