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

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

问题描述

所以我正在使用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];

弄乱我的场景物理。

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

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

任何人都有任何建议吗?

Anyone have any suggestions?

推荐答案

好的,我发现了一个非常糟糕的解决方案。您需要做的就是在展示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];

我在内部假设这样做物理引擎的方式是sprite kit物理将正常运行。不幸的是,我不相信这个解决方案,因为有一天它可能无法正常工作,因此我的整个游戏都会受到影响。

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 Framework中获得的一些有趣的物理效果。

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 Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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