Ios SKSpriteNode UIColor比较
我正在尝试创建一个简单的突破游戏。 有不同颜色的块。我使用这些差异为块设置新属性。例如:一个蓝色方块在球击中它后会变成白色方块。白色方块将消失 到目前为止,我的代码是:Ios SKSpriteNode UIColor比较,ios,swift,sprite-kit,skspritenode,Ios,Swift,Sprite Kit,Skspritenode,我正在尝试创建一个简单的突破游戏。 有不同颜色的块。我使用这些差异为块设置新属性。例如:一个蓝色方块在球击中它后会变成白色方块。白色方块将消失 到目前为止,我的代码是: let crashedBlock = againstBody.node! as! SKSpriteNode // againstBody is the body which touches the ball switch crashedBlock.color { case UIColor(red: 6/255, gree
let crashedBlock = againstBody.node! as! SKSpriteNode // againstBody is the body which touches the ball
switch crashedBlock.color {
case UIColor(red: 6/255, green: 123/255, blue: 178/255, alpha: 1.0):
crashedBlock.color = UIColor(red: 7/255, green: 151/255, blue: 218/255, alpha: 1.0)
break
case UIColor(red: 7/255, green: 151/255, blue: 218/255, alpha: 1.0):
crashedBlock.color = UIColor(red: 18/255, green: 175/255, blue: 248/255, alpha: 1.0)
break
case UIColor(red: 18/255, green: 175/255, blue: 248/255, alpha: 1.0):
crashedBlock.color = UIColor(red: 136/255, green: 215/255, blue: 251/255, alpha: 1.0)
break
case UIColor(red: 136/255, green: 215/255, blue: 251/255, alpha: 1.0):
crashedBlock.color = UIColor(red: 176/255, green: 228/255, blue: 253/255, alpha: 1.0)
break
case UIColor(red: 176/255, green: 228/255, blue: 253/255, alpha: 1.0):
crashedBlock.color = UIColor(red: 215/255, green: 242/255, blue: 254/255, alpha: 1.0)
break
case UIColor(red: 215/255, green: 242/255, blue: 254/255, alpha: 1.0):
crashedBlock.color = UIColor.white
break
case UIColor.white:
blocks.remove(againstBody.node!)
againstBody.node?.removeFromParent()
break
default: break
}
当我打印块的颜色时,我得到一个(1,1,1,1),所以它一定是白色的。但它甚至没有进入我的白色切换框。甚至不要基于颜色进行检查,使用某种标识符,如
userData[“colorType”]=1
同样在swift中,您不需要中断cases@Knight0fDragon你能举一个使用标识符的例子吗?我更喜欢使用可用颜色的枚举,甚至不要基于颜色进行检查,使用某种标识符,如userData[“colorType”]=1
同样在swift中,您不需要中断cases@Knight0fDragon你能举一个使用标识符的例子吗?我更喜欢使用可用颜色的枚举