本文介绍了SKAction向前迈进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得 SKNode 继续前进?

我已经能够获得节点使用 [SKAction moveByX:y:duration:] 以固定方向移动,但我希望它朝相对于其面向的方向移动。

I've been able to get the node to move in a fixed direction using [SKAction moveByX:y:duration:] but I want it to move in a direction relative to the direction its facing.

我希望每个节点转45度然后向前走50像素。

I am looking to make each node turn 45 degrees then "walk" forward 50 pixels.

看起来很简单我就是无法找到它。

It seems simple enough I just am not able to find it.

推荐答案

这将旋转,然后朝你点击的位置

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

这篇关于SKAction向前迈进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:17