ios7 – SpriteNode不遵循cgpath

ios7 – SpriteNode不遵循cgpath,第1张

概述我对新游戏精灵有问题…… 我的“赛车”在第一圈完美地跟踪了赛道,但从那时起,似乎它在每一圈结束时都会偏离.有人能告诉我我做错了什么吗? - (void)createSceneContents{ self.backgroundColor = [SKColor blackColor]; self.scaleMode = SKSceneScaleModeAspectFit; / 我对新游戏精灵有问题……
我的“赛车”在第一圈完美地跟踪了赛道,但从那时起,似乎它在每一圈结束时都会偏离.有人能告诉我我做错了什么吗?

- (voID)createSceneContents{    self.backgroundcolor = [SKcolor blackcolor];    self.scaleMode = SKScenescaleModeAspectFit;    // CREATING THE CAR AND THE TRACK    SKSpriteNode *myCar = [self newcar];    myCar.position = [[self trackShape] position];;    [self addChild:myCar];    SKShapeNode *track = [self trackShape];    track.position = CGPointMake(48,40);    [self addChild:track];}- (SKSpriteNode *)newcar{    // GENERATES A RECTANGLE FOR THE SPRITE NODE    SKSpriteNode *hull = [[SKSpriteNode alloc] initWithcolor:[SKcolor graycolor] size:CGSizeMake(20,50)];    CGPathref pathref = [[self bPath] CGPath];    // CAR SHOulD FolLOW THE TRACK    // OK ONLY ON THE FirsT LAP    SKAction *hover = [SKAction sequence:@[[SKAction followPath:pathref duration:20.0],]];    hull.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:hull.size];    hull.physicsBody.dynamic = NO;    [hull runAction: [SKAction repeatActionForever:hover]];    return hull;}-(SKShapeNode *)trackShape{    SKShapeNode *newshape = [[SKShapeNode alloc] init];    newshape.position = CGPointMake(48,40);    newshape.path = [[self bPath] CGPath];    newshape.fillcolor = [SKcolor clearcolor];    newshape.strokecolor = [SKcolor bluecolor];    newshape.linewidth = 8;    return newshape;}

这是路径…它都在同一个班级.

-(UIBezIErPath *)bPath{    UIBezIErPath* bezIErPath = [UIBezIErPath bezIErPath];    [bezIErPath movetoPoint: CGPointMake(48,40)];    [bezIErPath addlinetoPoint: CGPointMake(10.5,147.5)];    [bezIErPath addCurvetoPoint: CGPointMake(131.5,209.5) controlPoint1: CGPointMake(10.5,147.5) controlPoint2: CGPointMake(45.01,253.16)];    [bezIErPath addCurvetoPoint: CGPointMake(267.5,209.5) controlPoint1: CGPointMake(217.99,165.84) controlPoint2: CGPointMake(259.57,194.46)];    [bezIErPath addCurvetoPoint: CGPointMake(283.5,302.5) controlPoint1: CGPointMake(275.43,224.54) controlPoint2: CGPointMake(325.48,263.29)];    [bezIErPath addCurvetoPoint: CGPointMake(105.5,327.5) controlPoint1: CGPointMake(241.52,341.71) controlPoint2: CGPointMake(128.94,352.5)];    [bezIErPath addCurvetoPoint: CGPointMake(10.5,396.5) controlPoint1: CGPointMake(82.06,302.5) controlPoint2: CGPointMake(-27.5,333.95)];    [bezIErPath addCurvetoPoint: CGPointMake(239.5,448.5) controlPoint1: CGPointMake(48.5,459.05) controlPoint2: CGPointMake(195.5,463.67)];    [bezIErPath addCurvetoPoint: CGPointMake(283.5,40.5) controlPoint1: CGPointMake(399.5,40.5) controlPoint2: CGPointMake(375.39,205.99)];    [bezIErPath addCurvetoPoint: CGPointMake(153.5,78.5) controlPoint1: CGPointMake(191.61,-124.99) controlPoint2: CGPointMake(153.5,78.5)];    [bezIErPath addlinetoPoint: CGPointMake(48,40)];    [bezIErPath closePath];    return bezIErPath;}
解决方法 过了一会儿,这是我的 results

我废弃了你的汽车方法,并把它全部放在这里.

我不得不调整你的音轨的位置,但它似乎工作.

- (voID)createSceneContents{    self.backgroundcolor = [SKcolor blackcolor];    self.scaleMode = SKScenescaleModeAspectFit;    SKSpriteNode *hull = [[SKSpriteNode alloc] initWithcolor:[SKcolor graycolor] size:CGSizeMake(20,50)];    CGPathref pathref = [[self bPath] CGPath];    SKShapeNode *track = [self trackShape];    //track.position = // scrap me.. is set in track shape method    [self addChild:track];    hull.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:hull.size];    hull.physicsBody.dynamic = NO;    hull.position = CGPointMake(48,40);    [self addChild:hull];    SKAction *hover = [SKAction followPath:pathref asOffset:NO orIEnttopath:YES duration:5.0];    [hull runAction: [SKAction repeatActionForever:hover]];}

在trackShape方法中,将位置设置为0,0

newshape.position = CGPointMake(0,0);
总结

以上是内存溢出为你收集整理的ios7 – SpriteNode不遵循cgpath全部内容,希望文章能够帮你解决ios7 – SpriteNode不遵循cgpath所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1054699.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存