【问题标题】:Not working right, start and end positon工作不正常,开始和结束位置
【发布时间】:2014-05-07 02:27:54
【问题描述】:

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

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

底部有一些代码

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

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

谢谢!

这是一些代码:

    - (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];
}

【问题讨论】:

    标签: ios sprite-kit sknode skshapenode


    【解决方案1】:

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

    【讨论】:

    • addChild 在我创建的 SKNode 的子类中,但我将孩子添加到我拥有游戏的 SKScene 的引用中。 createTrigonometricFunction 和 calculateFunction 是我的子类中的函数......你的意思是:CGMutablePathRef pathToDraw = CGPathCreateMutable(); CGPathMoveToPoint(); CGPathAddLineToPoint(); currentLine.path = pathToDraw;应该在 SKScene 中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多