ios – SpriteKit背景PNG,Alpha显示黑色

前端之家收集整理的这篇文章主要介绍了ios – SpriteKit背景PNG,Alpha显示黑色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个用 Swift制作的Spritekit游戏,当它游戏结束时,我有一个背景是一个png文件,其alpha值为0.5ish(所以它的透视).我在photoshop中制作了它.

我用它来消除游戏细节,并将记分卡放在它的顶部.

当我在iPhone 6上使用它并运行iOS 9.2时,它运行良好,使细节变得迟钝并显示记分卡……但是当我在运行iOS 9.2的模拟器或运行iOS 8.4的iPhone 5C上运行它时,它只显示为黑色. ..覆盖整个游戏画面……

它的声明如下:

//alpha'sd png created in photoshop. approx. 0.3 alpha
    let backdrop = SKSpriteNode(imageNamed: "Background_Alpha") 

    backdrop.anchorPoint = CGPoint(x: 0.5,y: 1.0)
    backdrop.position = CGPoint(x: size.width/2,y: size.height)
    backdrop.name = "scoreScreen"
    backdrop.zPosition = Layer.UIBackground.rawValue
    worldNode.addChild(backdrop)

并像这样调用

backdrop.alpha = 0
    let drop = SKAction.fadeInWithDuration(kAnimDelay)
    drop.timingMode = .EaseInEaSEOut
    backdrop.runAction(SKAction.sequence([
        SKAction.waitForDuration(kAnimDelay),drop
        ]))

这是一个模拟器的屏幕截图…但正如我所提到的,它也发生在我的iPhone 5C上,8.4 …

simulator screenshot

黑色应该是透明的蓝色光线,允许玩家仍然在背景中看到游戏,但不是生动地……

有什么想法吗?

解决方法

所以 this question有一个答案说:

According to the documentation 07001:

Sprite Kit works only with solid colors. For best results,use the
preset colors provided by the platform class or a custom color defined
in the RGBA device color space

这是否仍然是真的,我不知道,但我所做的而不是使用alpha’d png只是使用Spritekit从头开始创建它并将其调用如下:

let backdrop = SKSpriteNode(color: 
                          SKColor(red: 29.0/255.0,green: 113.0/255.0,blue: 149.0/255.0,alpha: 0.3),//set alpha here
                                 size: size)

    backdrop.position = CGPoint(x: size.width/2,y: size.height/2)
    backdrop.name = "scoreScreen"
    backdrop.zPosition = Layer.UIBackground.rawValue
    worldNode.addChild(backdrop)                     //add it to world

    //because I set the alpha in the SKSpriteNode,//I can still animate it in from alpha=0 to alpha=0.3:

    backdrop.alpha = 0
    let drop = SKAction.fadeInWithDuration(kAnimDelay)
    drop.timingMode = .EaseInEaSEOut
    backdrop.runAction(SKAction.sequence([
        SKAction.waitForDuration(kAnimDelay),drop
        ]))

这现在可以在屏幕上的游戏中通过整个游戏显示透明的精灵到暗淡的场景.鉴于项目不再需要存储整个png图像,效率也更高.

我仍然有兴趣知道为什么它不起作用我原来的方式,但这是一个更少的解决方案.

猜你在找的iOS相关文章