0
在cocos2d v3中,找不到類似CCTargetedAction的內容。 它在我的項目中是必需的,所以我從cocos2d v2複製了代碼。我的CCTargetedAction兩次運行動作
@interface CCTargetedAction : CCActionInterval
/** This is the target that the action will be forced to run with */
@property(readwrite,nonatomic,retain) id forcedTarget;
@property(readwrite,nonatomic,retain) CCActionFiniteTime* action;
/** Create an action with the specified action and forced target */
+(id)actionWithTarget:(id)target
action:(CCActionFiniteTime*)action;
/** Init an action with the specified action and forced target */
-(id)initWithTarget:(id)target
action:(CCActionFiniteTime*)action;
@end
@implementation CCTargetedAction
+(id)actionWithTarget:(id)target
action:(CCActionFiniteTime*)action
{
return [(CCTargetedAction*)[self alloc] initWithTarget:target
action:action];
}
-(id)initWithTarget:(id)target
action:(CCActionFiniteTime*)action
{
self = [super initWithDuration:action.duration];
if(self)
{
self.forcedTarget = target;
self.action = action;
}
return self;
}
-(id)copyWithZone:(NSZone*)zone
{
CCAction *copy = [(CCTargetedAction*) [[self class] allocWithZone: zone]
initWithTarget:_forcedTarget
action:[_action copy]];
return copy;
}
- (void) startWithTarget:(id)aTarget
{
[super startWithTarget:aTarget];
[_action startWithTarget:_forcedTarget];
}
- (void) stop
{
[_action stop];
}
- (void) update:(CCTime) time
{
[_action update:time];
}
@end
但是我的CCTargetedAction運行兩次。
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CCActionCallBlock* block = [CCActionCallBlock actionWithBlock:^{
CCLOG(@"call block");
}];
CCTargetedAction* action = [CCTargetedAction actionWithTarget:self
action:block];
[self runAction:action];
}
如果我觸摸屏幕一次,則會輸出兩次日誌消息。
2014-04-07 22:09:57.439 TargetedActionTest[3924:60b] call block
2014-04-07 22:09:57.455 TargetedActionTest[3924:60b] call block
爲什麼這段代碼運行兩次?
謝謝。