在SceneKit中,从RunAction的完成处理程序调用时,SCNAction挂起 [英] In SceneKit SCNAction hangs when called from completion handler of RunAction

查看:136
本文介绍了在SceneKit中,从RunAction的完成处理程序调用时,SCNAction挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从RunAction的完成处理程序中调用SCNAction似乎会挂起SceneKit.

Calling an SCNAction from the completion handler of RunAction seems to hang SceneKit.

触摸事件或旋转设备似乎可以解除挂起.

A touch event or rotating the device seems to unblock the hang.

要复制:

1)使用旋转太空船启动时获得的默认SceneKit项目.

1) Take the default SceneKit project you get on startup with the rotating spaceship.

2)替换动画代码:

ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 2, 0, 1)));

具有:

        ship.RunAction(SCNAction.RotateBy(0, 2, 0, durationInSeconds: 3.0f), delegate
        {
            Console.WriteLine("DONE ROTATE");
            ship.RunAction(SCNAction.MoveBy(1, 0, 0, durationInSeconds: 3.0f), delegate
            {
                Console.WriteLine("DONE MOVEBY");
            });
        });

3)在模拟器或真实设备上运行(问题都相同)

3) Run on the simulator or real device (the problem is the same on both)

4)结果是:

  • 宇宙飞船旋转正常

  • Spaceship rotates OK

完成旋转完成打印

现在挂了

点击屏幕(或将设备旋转至横向),然后进行移动,然后将完成的移动打印出来.

Tap the screen (or rotate the device to landscape) and then the move happens OK and DONE MOVEBY is printed out.

我正在使用C#和Mac上的Visual Studio,但我怀疑它也在Xcode中发生.

I'm using C# and Visual Studio for Mac, but I suspect it happens using Xcode too.

这是SceneKit中的错误吗?如何解决?

Is this a bug in SceneKit? How can a workaround be done?

也许这是此处所述的相同问题:

Maybe this is the same issue as described here:

SCNAction完成处理程序等待执行手势

推荐答案

之所以会发生这种情况,是因为默认情况下SceneKit不会连续渲染.当点击屏幕时,场景将改变,并且将渲染一个新的帧.这就是rotateBy动作之后没有立即触发moveBy动作的原因.

This happens because by default SceneKit is not rendering continuously. When tapping the screen the scene is changed and a new frame will be rendered. That's why the moveBy action is not triggered immediately after the rotateBy action.

尝试将SCNViewrenderContinuously属性设置为true,如下所示:

Try setting SCNView's renderContinuously property to true like so:

scnView.rendersContinuously = true
ship.runAction(SCNAction.rotateBy(x: 0, y: 2, z: 0, duration: 3.0)) {
    print("DONE ROTATE")
    ship.runAction(SCNAction.moveBy(x: 1, y: 0, z: 0, duration: 3.0), completionHandler: {
        print("DONE MOVEBY")
        scnView.rendersContinuously = false
    })
}

这篇关于在SceneKit中,从RunAction的完成处理程序调用时,SCNAction挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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