SKAction前进 [英] SKAction move forward

查看:24
本文介绍了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前进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆