如何使用 Sprite Kit 减慢运行 SKAction followPath 以获得慢动作效果的 SKSpriteNode? [英] How can I slow down a SKSpriteNode that is running SKAction followPath for a slow motion effect using Sprite Kit?

查看:49
本文介绍了如何使用 Sprite Kit 减慢运行 SKAction followPath 以获得慢动作效果的 SKSpriteNode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上希望动作是运行的,然后在动作的中间创建一个慢动作效果,然后再把它从慢动作中拿出来.有没有人对如何做到这一点有任何好的反馈?我曾考虑过手动创建操作并使用更新方法,但我觉得这可能有点矫枉过正.我希望有一个更简单的解决方案.

I basically want the action to be running and then in the middle of the action create a slow motion effect and then later bring it out of slow motion. Does anyone have any good feedback of how this might be done? I've thought about creating the action manually and using an update method, but I feel like that might be overkill. I was hoping for a simpler solution.

我的另一个想法是停止动作,然后以较慢的持续时间重新开始,但我认为它不会停留在相同的路径上,而且可能看起来很奇怪.

The other thought I have is to stop the action and then start it again at a slower duration, but I don't think it will stay on the same path and it will probably look weird.

这是我用来创建动作的代码.

This is the code I'm using to create the action.

CGMutablePathRef cgpath = CGPathCreateMutable();
CGPathMoveToPoint(cgpath,NULL, mysprite.position.x, mysprite.position.y);
CGPathAddCurveToPoint(cgpath, NULL, cp1.x, cp1.y, cp2.x, cp2.y, e.x, e.y);
[mysprite runAction:[SKAction sequence:@[[SKAction followPath:cgpath asOffset:NO orientToPath:YES duration:3]]]];
CGPathRelease(cgpath);

推荐答案

每个节点都有一个 speed 属性:

Each node has a speed property:

应用于节点及其执行的所有操作的速度修饰符后代.

A speed modifier applied to all actions executed by a node and its descendants.

讨论
默认值为 1.0,表示所有操作都运行以他们的正常速度.如果您设置不同的速度,时间将显示为对于在节点及其上执行的所有操作,运行得更快或更慢后裔.例如,如果您将速度值设置为 2.0,操作将运行快两倍.

Discussion
The default value is 1.0, which means that all actions run at their normal speed. If you set a different speed, time appears to run faster or slower for all actions executed on the node and its descendants. For example, if you set a speed value of 2.0, actions run twice as fast.

您可以将其设置为小于 1 的值,以使操作运行得更慢.您甚至可以设置动画以逐渐减慢速度:

You could set this to a value smaller than 1 to make the action run slower. You can even animate the speed to gradually slow down:

[mySprite runAction:[SKAction speedTo:0.5 duration:1.0]];

这篇关于如何使用 Sprite Kit 减慢运行 SKAction followPath 以获得慢动作效果的 SKSpriteNode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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