不正常,开始和结束位置

时间:2014-05-07 02:27:55

标签: ios sprite-kit sknode skshapenode

我正在尝试在SKScene上绘制一些三角函数..我正在为屏幕中的每个点使用SKShapeNode,所以当它到达左侧时,我从父母那里删除。

问题在于,由于某种原因,它只会在屏幕的一部分上绘制,就像它被较小的视图所包含一样。屏幕上的位置与真实屏幕不匹配...例如,如果我放置它在100它实际上是在一个不同的地方..加上图形的区域的大小减少...

底部有一些代码

我希望有人可以帮助我!非常感谢你!

其他任何可能有用的问题,我会重新编辑帖子。

谢谢!

Example01 Example02

以下是一些代码:

    - (void) createTrigonometricFunction
{

    [self calculateFunction];


    CGMutablePathRef pathToDraw = CGPathCreateMutable();

    CGPathMoveToPoint(pathToDraw, NULL, groundOriginLocation.x,groundOriginLocation.y + groundPointPrevious.y);
    CGPathAddLineToPoint(pathToDraw, NULL, groundOriginLocation.x + 1,groundOriginLocation.y + groundPointCurrent.y);



    SKShapeNode * currentLine = [SKShapeNode node];

    currentLine.position = CGPointMake(groundOriginLocation.x,groundOriginLocation.y);
    currentLine.path = pathToDraw;
    CGPathRelease(pathToDraw);
    [currentLine setStrokeColor:[UIColor whiteColor]];
    currentLine.name = @"terrainLine";

    currentLine.lineWidth = 1;

    [currentScene addChild: currentLine];

    groundPointPrevious = groundPointCurrent;
    //NSLog(@"%f - %f",currentLine.position.x,currentLine.position.y);
}



- (void) calculateFunction
{
    groundDominio += 1;
    groundPointCurrent.x = groundOriginLocation.x;

    groundPointCurrent.y = 2*(sin(degreesToRadian(groundDominio)*2)/5*degreesToRadian(180))*cos(degreesToRadian(150) + degreesToRadian(groundDominio)*5)*sin(degreesToRadian(groundPointCurrent.x));
    groundPointCurrent.y = radianToDegrees(groundPointCurrent.y);

}


//The view controller:: (This is how I load it)


- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    //skView.showsFPS = YES;
    skView.showsNodeCount = YES;

    // Create and configure the scene.
    SKScene * scene = [MainGame sceneWithSize: skView.bounds.size];
    //scene.scaleMode = SKSceneScaleModeAspectFill;
    NSLog(@"%f  $$    %f",self.view.frame.size.height,self.view.frame.size.width);
    // Present the scene.
    [skView presentScene:scene];
}

1 个答案:

答案 0 :(得分:0)

你是在场景上还是在另一个节点上画画? 如果您正在绘制另一个节点,则绘图将关闭,因为节点的默认锚点是0.5,0.5(它固定到具有中心的场景)但是节点内的实际0.0位置不是它的中心。