我有一个应用程序,使用SpriteKit和发射器粒子(sks),我发现这是不现实的场景工具包的粒子。因此,我希望将其合并到SKScene中,但我不确定这是否可行。所以我决定创建一个SCNScene和粒子。然而,我想添加一个背景图像和唯一的3D效果将是粒子。有人能帮我为我的SCNScene设置背景图像吗?传统上,我会像这样把它添加到SKScene中,但是我在网上找不到任何SceneKit的帮助。
let backgroundNode = SKSpriteNode(imageNamed: "backgroundImage")
backgroundNode.size = view.frame.size
backgroundNode.position = CGPointMake(view.frame.size.width/2, view.frame.height/2)
self.addChild(backgroundNode)提前谢谢你
发布于 2015-08-14 16:49:51
let scnScene = SCNScene()
scnScene.background.contents = UIImage(named: "earth.jpg")发布于 2016-02-05 05:57:30
基本上和@ answer的答案一样,但我可以使用一系列不同的技术来设置梯度背景。仍然非常简单和有用。
const CGFloat DIVISOR = 255.0f;
CIColor *bottomColor = [CIColor colorWithRed:(CGFloat)0xee / DIVISOR green:(CGFloat)0x78 / DIVISOR blue:(CGFloat)0x0f / DIVISOR alpha:1];
CIColor *topColor = [CIColor colorWithRed:0xff / DIVISOR green:0xfb / DIVISOR blue:0xcf / DIVISOR alpha:1];
SKTexture* textureGradient = [SKTexture textureWithVerticalGradientofSize:scnview.frame.size topColor:topColor bottomColor:bottomColor];
UIImage* uiimageGradient = [UIImage imageWithCGImage:textureGradient.CGImage];
self.background.contents = uiimageGradient;其中"self“是SCNScene的一个子类。
这个例子需要这里的纹理类别:https://gist.github.com/Tantas/7fc01803d6b559da48d6
发布于 2020-01-31 06:02:15
我试着用@ answer回答。但是,当我将图像文件放在scnassets中时,图像并没有加载。但是当我把文件放到xcassets中时,它就起作用了。
scnScene.background.contents = UIImage(named: "earth")https://stackoverflow.com/questions/31994834
复制相似问题