我设计了一个SKLabelNode对象。每当我触摸SKLabelNode对象时,我想让它从下往上移动然后向下移动。首先,它将从下往上移动,然后需要从上到下移动。这是代码..任何人都可以帮忙!
- (void)touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event
{
//SKNode *helloNode = [self childNodeWithName:@"helloNode"];
SKNode * helloNode=[self childNodeWithName:@"helloNode"];
if ([helloNode.name isEqualToString:@"helloNode"])
{
helloNode.name = @"";
SKAction *moveUp = [SKAction moveByX: 0 y: 100.0 duration: 0.5];
//SKAction *zoom = [SKAction scaleTo: 2.0 duration: 0.25];
SKAction *pause = [SKAction waitForDuration: 0.5];
SKAction *fadeAway = [SKAction fadeOutWithDuration: 0.25];
SKAction *fadeIn = [SKAction fadeInWithDuration:0.25];
//SKAction *remove = [SKAction removeFromParent];
SKAction *moveSequence = [SKAction sequence:@[moveUp, pause, fadeAway,fadeIn]];
[helloNode runAction: moveSequence];
}
else
{
helloNode.name=@"helloNode";
SKAction *moveUp = [SKAction moveByX: 0 y: 50.0 duration: 0.5];
//SKAction *zoom = [SKAction scaleTo: 2.0 duration: 0.25];
SKAction *pause = [SKAction waitForDuration: 0.5];
SKAction *fadeAway = [SKAction fadeOutWithDuration: 0.25];
SKAction *fadeIn = [SKAction fadeInWithDuration:0.25];
//SKAction *remove = [SKAction removeFromParent];
SKAction *moveSequence = [SKAction sequence:@[moveUp, pause, fadeAway,fadeIn]];
[helloNode runAction: moveSequence];
}
}
答案 0 :(得分:0)
I'm not sure about the exact problem you are facing.
You can start the move upwards action in your didMoveToView or wherever you want. After that you simply run your move downwards action in your touch listener.
If you want to toggle your move direction (one time up, next time down..) you need to remove the previous action before you set the new one or just overwrite it (use the same action name).