奇怪的 SpriteKit + UIDynamics 错误 [英] Strange SpriteKit + UIDynamics Bug

查看:13
本文介绍了奇怪的 SpriteKit + UIDynamics 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用 SpriteKit 开发游戏.为了让游戏更有趣,我决定使用 UIDynamicAnimator 为我的游戏中的 UIKit 元素添加一些物理效果.一切都很好,除了有一个主要问题.当我像这样分配/初始化 UIDynamicAnimator 时:

So I'm developing a game using SpriteKit. And to make the game more interesting I decided to use UIDynamicAnimator to add some physics to the UIKit elements within my game. Everything works great except there is one major problem. The moment I alloc/init a UIDynamicAnimator like so:

animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];

我游戏中的物理实体完全抵消了.即使我没有指定参考视图,物理仍然会偏移.

The physics bodies in my game get completely offset. Even if I don't specify a reference view the physics still get offset.

奇怪的是,我在一个完全独立的 ViewController 中创建 UIDynamicAnimator,所以它不像共享相同的参考视图或类似的东西.

What's strange is that i'm creating the UIDynamicAnimator in a completely separate ViewController so it's not like it's sharing the same reference view or something like that.

更新:甚至像这样简单地创建 UIDynamicItemBehavior 的行为:

Update: Even the act of simply creating a UIDynamicItemBehavior like so:

UIDynamicBehavior* a = [[UIDynamicBehavior alloc] init];

弄乱了我场景的物理特性.

messes up my scene's physics.

我假设这是 SpriteKit 和 UIDynamics 共享的物理引擎的内部错误.

I'm assuming this is an internal bug with the physics engine that SpriteKit and UIDynamics share.

大家有什么建议吗?

推荐答案

好的,我找到了一个非常 hacky 的解决方案.您需要做的就是在展示您的 SKScene 之前以某种方式使用 UIDynamics 框架.例如,在呈现场景之前简单地运行这行代码将消除同时使用 SpriteKit 和 UIDynamics 导致的奇怪的物理错误:

Ok I found a pretty hacky solution. All you need to do is use the UIDynamics framework in some way before presenting your SKScene. For example, simply running this one line of code before presenting your scene will remove the weird physics bug caused by simultaneously using SpriteKit and UIDynamics at the same time:

UIDynamicBehavior* a = [[UIDynamicBehavior alloc] init];

我假设在内部这会使物理引擎准备好精灵套件物理行为正常的方式.不幸的是,我不相信这个解决方案,因为它可能有一天会不起作用,我的整个游戏都会因此而受到影响.

I'm assuming internally this prepares the physics engine in such a way that sprite kit physics will behave normally. Unfortunately I do not trust this solution because it might not work one day and my entire game would suffer because of it.

因此,作为 UIDynamics 框架的替代方案,我决定只使用 UIView Animation 来复制我通过 UIDynamics 框架获得的一些有趣的物理效果.

So as an alternative to the UIDynamics framework I've decided to just use UIView Animation to replicate some of the interesting physics effects that I got with the UIDynamics Framework.

为 IOS 8 编辑根据 Doctordoder 的说法,这个 bug 在 iOS 8 中仍然存在,而且这个解决方法仍然有效.

EDIT FOR IOS 8 According to doctordoder, this bug still exists in iOS 8, and this workaround still works.

这篇关于奇怪的 SpriteKit + UIDynamics 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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