SKAction move forward

前端 未结 2 859
耶瑟儿~
耶瑟儿~ 2020-12-19 23:41

How do I get a SKNode to move forward?

I\'ve been able to get the node to move in a fixed direction using [SKAction moveByX:y:duration:] bu

相关标签:
2条回答
  • 2020-12-20 00:12

    I have thought about this as well. I want to make a node that can seem to be turning before proceeding. One way I have considered doing this is to have a child node attached the the "forward-most" portion of the node that is moving in the scene. Then I would calculate the distance of the tap form the child node. Does that make sense? Essentially, I would be able to calculate the front of the node from a tap anywhere in the scene.

    0 讨论(0)
  • 2020-12-20 00:27

    This will rotate, then towards where you tap

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    for (UITouch *touch in touches) {
    
        for (UITouch *touch in touches) {
    
            CGPoint location = [touch locationInNode:self];
    
            CGPoint diff = CGPointMake(location.x - _myPlayer.position.x, location.y - _myPlayer.position.y);
    
            CGFloat angleRadians = atan2f(diff.y, diff.x);
    
            [_myPlayer runAction:[SKAction sequence:@[
                                    [SKAction rotateToAngle:angleRadians duration:1.0],
                                    [SKAction moveByX:diff.x y:diff.y duration:3.0]
                                    ]]];
        }
    }
    }
    
    0 讨论(0)
提交回复
热议问题