새로운 게임 스프라이트에 문제가 있습니다 ... 내 "차"가 첫 번째 랩에서 완벽하게 트랙을 따라 갔지만 그 이후부터는 모든 랩의 끝에 오프셋이 나타나는 것으로 보입니다. 누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까?SpriteNode가 cgpath를 따르지 않습니다
- (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;
}
에 위치를 설정 이것은 나를 난처한 상황에 빠진! – DogCoffee