我的精灵位置是(screenWidth,screenHeigh / 2)。我尝试了很多代码,使用CGPathAddArc从右到左移动精灵但不成功。苹果文件很难理解。所以我发布在这里希望有人可以帮助我。 这是我用过的代码之一。
if (iPad) {
CGPathAddArc(thePath, NULL, 384.0f , 768, 384.0f , 0.f, -M_PI*3/2, NO);
}
SKAction *moveAction = [SKAction followPath:thePath asOffset:YES orientToPath:NO duration:(5.0f/200.0f)*(iPad ? 384.0f :200.f)];
很多人提前感谢
答案 0 :(得分:1)
如果您创建一个空白的SpriteKit项目,这个稍微修改过的GameScene.m默认代码将使太空船沿着半圆路径从右向左飞过。
如果您需要进一步澄清,请发表评论!
您的代码段与[SKAction followPath...]
asOffset
参数的关键区别为NO,orientToPath
为YES。
#import "GameScene.h"
@implementation GameScene
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"];
myLabel.text = @"Hello, World!";
myLabel.fontSize = 65;
myLabel.position = CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));
[self addChild:myLabel];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = location;
// HERE COMES THE MODIFICATION
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathAddArc(thePath, NULL, self.frame.size.width/2 , 200, self.frame.size.width/2 , 0.f, -M_PI, NO);
SKAction *moveAction = [SKAction followPath:thePath asOffset:NO orientToPath:YES duration:5.0];
[sprite runAction:[SKAction repeatActionForever:moveAction]];
// HERE ENDS THE MODIFICATION
[self addChild:sprite];
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
}
@end
希望这有帮助!