1

我正在尝试在 SKScene 上绘制一些三角函数。我正在为屏幕中的每个点使用 SKShapeNode,因此当它到达左侧时,我会从父级中删除 if。

问题是,由于某种原因,它只在屏幕的一部分上绘制,就好像它被一个较小的视图包含一样。屏幕上的位置与真实屏幕不匹配......例如,如果我把它放在 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];
}
4

1 回答 1

0

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

于 2014-05-07T15:02:32.597 回答