如何在场景中动画化SKLabel的位置?
我试过以下几种方法,但似乎不起作用:
[SKView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
newBestLabel.position = CGPointMake(CGRectGetMinX(self.frame)+70, CGRectGetMaxY(self.frame)-30);
}
completion:^(BOOL finished){}];和
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
newBestLabel.position = CGPointMake(CGRectGetMinX(self.frame)+70, CGRectGetMaxY(self.frame)-30);
}
completion:^(BOOL finished){}];在viewDidLoad中,它从以下位置开始:
newBestLabel.position = CGPointMake(CGRectGetMinX(self.frame)+70, CGRectGetMaxY(self.frame)+30);这里怎么了?
发布于 2014-04-20 10:46:27
因为SKLabelNode是SKNode的子类,所以可以使用名为runAction:的方法,并传入一个SKAction,以满足您的需要。
// create an instance of SKAction
SKAction *moveLabel = [SKAction moveByX:0.0 y:30.0 duration:1.2];
// tell labelNode to run the action
[newBestLabel runAction:moveLabel];同样值得注意的是,SpriteKit所使用的坐标系统与UIKit的坐标系不同。因此,在上面的代码中,正x值将向右移动,而正y值将向上移动!
有许多方法可用于满足您的需要,还有更多的方法,这些方法可以在SKAction类引用中找到。
发布于 2014-04-20 10:45:32
SKLabelNode不是从UIView继承的,这不是处理SpriteKit动画的方法。相反,您应该通过创建一个SKAction并将其应用于节点来处理这个问题:
SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"Avenir"];
label.position = CGPointMake(30, 200);
label.text = @"Lorem Ipsum";
[self addChild:label];
SKAction *moveLabel = [SKAction moveByX:100 y:0 duration:2.0];
[label runAction:moveLabel];和你代码中的坐标不一样,但我相信你可以从这里取下来。还有一个moveTo:如果更适合您的需求,请执行以下操作。
https://stackoverflow.com/questions/23180512
复制相似问题