Old thread, but here is my solution, just in case it's useful:
/** Moves a CCNode object x,y pixels by modifying it's position attribute.
x and y are relative to the position of the object.
Can be concurrently called.
@since 1.0.0-rsanchez
*/
@interface CCMoveByEx : CCActionInterval <NSCopying>
{
CGPoint delta;
ccTime previousTick;
}
/** creates the action */
+(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
/** initializes the action */
-(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
@end
/** Moves a CCNode object to the position x,y. x and y are absolute coordinates by modifying it's position attribute.
Can be concurrently called.
@since 1.0.0-rsanchez
*/
@interface CCMoveToEx : CCMoveByEx
{
CGPoint endPosition;
}
/** creates the action */
+(id) actionWithDuration:(ccTime)duration position:(CGPoint)position;
/** initializes the action */
-(id) initWithDuration:(ccTime)duration position:(CGPoint)position;
@end
@interface CCMoveByEx : CCActionInterval <NSCopying>
{
CGPoint delta;
ccTime previousTick;
}
/** creates the action */
+(id) actionWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
/** initializes the action */
-(id) initWithDuration: (ccTime)duration position:(CGPoint)deltaPosition;
@end
@interface CCMoveToEx : CCMoveByEx
{
CGPoint endPosition;
}
/** creates the action */
+(id) actionWithDuration:(ccTime)duration position:(CGPoint)position;
/** initializes the action */
-(id) initWithDuration:(ccTime)duration position:(CGPoint)position;
@end
//
// MoveToEx
//
#pragma mark -
#pragma mark MoveToEx
@implementation CCMoveToEx
+(id) actionWithDuration: (ccTime) t position: (CGPoint) p
{
return [[[self alloc] initWithDuration:t position:p ] autorelease];
}
-(id) initWithDuration: (ccTime) t position: (CGPoint) p
{
if( (self=[super initWithDuration: t]) ) {
endPosition = p;
}
return self;
}
-(id) copyWithZone: (NSZone*) zone
{
CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: endPosition];
return copy;
}
-(void) startWithTarget:(CCNode *)aTarget
{
[super startWithTarget:aTarget];
delta = ccpSub( endPosition, [(CCNode*)target_ position] );
}
@end
//
// MoveByEx
//
#pragma mark -
#pragma mark MoveByEx
@implementation CCMoveByEx
+(id) actionWithDuration: (ccTime) t position: (CGPoint) p
{
return [[[self alloc] initWithDuration:t position:p ] autorelease];
}
-(id) initWithDuration: (ccTime) t position: (CGPoint) p
{
if( (self=[super initWithDuration: t]) )
delta = p;
return self;
}
-(id) copyWithZone: (NSZone*) zone
{
CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] position: delta];
return copy;
}
-(void) startWithTarget:(CCNode *)aTarget
{
previousTick = 0;
[super startWithTarget:aTarget];
}
-(CCActionInterval*) reverse
{
return [[self class] actionWithDuration:duration_ position:ccp( -delta.x, -delta.y)];
}
-(void) update: (ccTime) t
{
[target_ setPosition: ccpAdd([target_ position], ccpMult(delta, t-previousTick) )];
previousTick=t;
}
@end