gpt4 book ai didi

swift - 在 Sprite Kit 动画中运行简笔画

转载 作者:行者123 更新时间:2023-11-28 05:29:38 24 4
gpt4 key购买 nike

我在 SpriteKit 中玩了一点,并试图让一个火柴人跑起来。由于我缺乏经验,我相信我是以一种非常规的方式开始这个过程的。

我没有画出每个单独的运动帧,而是加载了简笔画的单独图像(即头部、膝盖、大腿、 body 、 ARM 等)并告诉它们相应地移动。到目前为止,除了在运行过程中膝盖的运动和旋转之外,一切都吻合在一起。

我的问题是:

当大腿在步幅中向后拉时,膝盖会分离,并在旋转时沿着一条直线到达步幅的末端。

我的问题是:

有没有办法将大腿节点连接到小腿节点,就好像它们在运动时连接在“膝盖”上一样?还是有更有效的方法?

这是我的代码片段,它可能比我之前的代码更具描述性。

   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_ 前缀代表“front”leg,b 代表“back”_leg。然而,将其视为右腿和左腿。

无论如何!提前致谢!我感谢任何帮助或提示!评论任何进一步的解释! :)

最佳答案

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

关于swift - 在 Sprite Kit 动画中运行简笔画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com