1

I'm trying to graph some trigonometric functions on an SKScene.. I'm using an SKShapeNode for each point in the screen so when it reaches the left side I remove if from the parent.

The problem is that, for some reason it only draws on a portion of the screen as if it were contained by a smaller view.. The position on the screen is not matching the real screen... for example if I place it at 100 it is actually at a different place.. Plus the size of the area where it graphs is reduced...

There is some code at the bottom

I hope someone could help me! Thank you very much!

Anything else that might help ask and I'll re-edit the post.

Thank you!

Example01 Example02

Here is some code:

    - (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];
}
GKTon
  • 61
  • 5

1 Answers1

0

Do you draw on the scene or on another node?
If you are drawing on another node, your drawing will be off since the default anchor point for node is 0.5, 0.5 (it is pinned to scene with its center) but the actual 0.0 position inside the node is not its center.

Dvole
  • 5,725
  • 10
  • 54
  • 87
  • The addChild is inside a subclass of SKNode that I made, but I'm adding the child to the reference of the SKScene where I have the game. createTrigonometricFunction and calculateFunction are functions inside my subclass... Do you mean: CGMutablePathRef pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(); CGPathAddLineToPoint(); currentLine.path = pathToDraw; Should be in the SKScene? – GKTon May 07 '14 at 23:22