我在SpriteKit玩了一会儿,想玩个棒形跑。由于缺乏经验,我相信我是以一种非传统的方式开始这一进程的。
我没有画出每一个单独的运动帧,而是加载了棒状图形的单独图像(即头部、膝盖、大腿、身体、手臂等),并告诉他们相应地移动。到目前为止,除了在跑步过程中膝盖的运动和旋转之外,所有的东西都很协调。
我的问题是:
当大腿在跨步中向后拉时,膝盖就会分离,并在旋转时沿着直线到达跨步的末端。
我的问题是:
有没有一种方法可以将大腿节点连接到小腿节点,就好像它们在运动时被固定在“膝盖”上一样?还是有更有效的方法?
这是我的一段代码,它可能比我以前描述的要多一些。

   func thigh_run(){
        //running config
        //DONT CHANGE!
        var thigh_rotation = CGFloat(M_PI)*0.8
        //Can Change :)
        var run_speed = NSTimeInterval(0.25)

        // reset the action sequence... basically
        let pos_nuetralize = SKAction.rotateByAngle(thigh_rotation/2, duration: run_speed)
        let neg_nuetralize = SKAction.rotateByAngle(-thigh_rotation/2, duration: run_speed)
        //strides
        let thigh_pull = SKAction.rotateByAngle(-thigh_rotation, duration: run_speed*2)
        let thigh_stride = SKAction.rotateByAngle(thigh_rotation/2, duration: run_speed)
        // for the opposite leg
        let b_thigh_pull = SKAction.rotateByAngle(-thigh_rotation/2, duration: run_speed)
        let b_thigh_stride = SKAction.rotateByAngle(thigh_rotation, duration: run_speed*2)

        //knee movement
        let stride = SKAction.sequence([thigh_stride, thigh_pull, pos_nuetralize])
        let pull = SKAction.sequence([b_thigh_pull, b_thigh_stride, neg_nuetralize])
        r_arm.runAction(SKAction.repeatActionForever(stride))
        f_leg_thigh.runAction(SKAction.repeatActionForever(stride))
        b_leg_thigh.runAction(SKAction.repeatActionForever(pull))
        //knee_run(run_speed)


    }

    func knee_run(speed: NSTimeInterval){

        let knee_stride = SKAction.moveTo(CGPointMake(f_leg_thigh.position.x+f_leg_thigh.size.height, f_leg_thigh.position.y), duration: speed)
        let knee_reset = SKAction.moveTo(CGPointMake(f_leg_thigh.position.x, f_leg_thigh.position.y-f_leg_thigh.size.height), duration: speed)
        let knee_pull_rotate = SKAction.rotateToAngle(CGFloat(M_PI)/2, duration: speed, shortestUnitArc: true)
        let knee_pull_rotate_half = SKAction.rotateToAngle(CGFloat(M_PI)*2, duration: speed, shortestUnitArc: true)
        let knee_pull_half = SKAction.moveTo(CGPointMake(f_leg_thigh.position.x-f_leg_thigh.size.height, f_leg_thigh.position.y/2), duration: speed)
        let knee_pull = SKAction.moveTo(CGPointMake(f_leg_thigh.position.x-f_leg_thigh.size.height, f_leg_thigh.position.y), duration: speed)




        //Grouping of the knee moving and rotating at the same time
        let knee_pull_group_half = SKAction.group([knee_pull_half, knee_pull_rotate_half])
        let knee_pull_group = SKAction.group([knee_pull, knee_pull_rotate])

        let f_knee_stride_seq = SKAction.sequence([knee_stride,knee_reset,knee_pull,knee_reset])
        let f_knee_pull_seq = SKAction.sequence([knee_pull_group_half, knee_reset, knee_stride, knee_reset])


        f_leg_calf.runAction(SKAction.repeatActionForever(f_knee_stride_seq))
        b_leg_calf.runAction(SKAction.repeatActionForever(f_knee_pull_seq))
    }

我知道这可能很难阅读,我已经把它记录得很好了。f_u前缀表示“前”腿,b表示“后”腿。不过,可以把它想象成右腿和左腿。
无论如何!提前谢谢!我很感激你的帮助和建议!如需进一步解释,请留言!:)

最佳答案

更有效的方法是使用SKPhysicsJoint将大腿节点连接到小腿节点。

10-06 07:34