严重的SpriteKit UIColor bug在iPhone 5S [英] Serious SpriteKit UIColor bug on iPhone 5S

查看:151
本文介绍了严重的SpriteKit UIColor bug在iPhone 5S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用SKSpriteNodes及其颜色时发现了一个严重的Swift-Bug。

I've found a serious swift-bug in SpriteKit while working with SKSpriteNodes and their colors.

此代码在iPhone 5S以外的所有iPhone上都可以正常工作: / p>

This code works fine on all iPhones beside the iPhone 5S:

var color1 = UIColor(red: 123/255, green: 123/255, blue: 123/255, alpha: 1)
var color2 = UIColor(red: 123/255, green: 123/255, blue: 123/255, alpha: 1)

var sprite = SKSpriteNode(color: color1, size: CGSizeMake(100, 100))

if(sprite.color == color2){
     println("Same color")
}

正如你所看到的,两种颜色是绝对的。但是在iPhone 5S模拟器上,if没有被调用。

As you see, the two colors are the absolut same. But on the iPhone 5S simulator, the if isn't called.

有其他人也有同样的问题,可以提供解决方案吗?

Has somebody else the same problem and can provide a solution?

推荐答案

p>您正在比较指针值,而不是实际的颜色。看到这些是UIColor实例,你必须使用isEqual(显示ObjC代码,因为我不知道它在Swift中看起来像什么 - 或者Swift实际上是在后台使用isEqual)进行比较:

You are comparing pointer values, not the actual color. Seeing that these are UIColor instances, you have to compare them using isEqual (showing ObjC code as I don't know what it looks like in Swift - or perhaps Swift is in fact using isEqual behind the scenes):

if ([sprite.color isEqual:color2])

如果UIColor正确实现,它将比较实际的颜色值,而不是指针。

If implemented correctly by UIColor this will compare the actual color values rather than the pointers.

这篇关于严重的SpriteKit UIColor bug在iPhone 5S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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