Spa*_*Dog 33 iphone ipad ios sprite-kit
有没有办法让SKScene的背景透明,并通过透明度将该场景呈现在另一个场景上.
想法是让所呈现的场景的背景如下:
self.backgroundColor = [SKColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];
Run Code Online (Sandbox Code Playgroud)
什么可以看到背后的场景变暗.但这样做并不奏效.背景呈现完全不透明.
有没有办法做到这一点?
Jer*_*kin 75
在iOS 8中,您可以设置场景的SKView以允许透明度并将场景的背景颜色设置为具有透明度.然后会看到SKView背后的视图.
UIView *parentView = ...;
[parentView addSubview:backgroundView];
[parentView addSubview:skViewWithScene];
skViewWithScene.allowsTransparency = YES;
scene.backgroundColor = [UIColor clearColor];
[skViewWithScene presentScene:scene];
Run Code Online (Sandbox Code Playgroud)
小智 7
透明度仅适用于iOS 8,必须检查iOS 7
在ViewController中将透明度设置为:
SKView *skView = (SKView *)self.mySKView;
SKScene *skScene = [MyScene sceneWithSize:skView.bounds.size];
skScene.scaleMode = SKSceneScaleModeAspectFill;
skView.allowsTransparency = YES;
[skView presentScene: skScene];
Run Code Online (Sandbox Code Playgroud)
在MyScene.m中将背景设置为清晰的颜色:
self.scene.backgroundColor = [UIColor clearColor];
迅捷3
@IBOutlet var gameScene: SKView!
func setupGameScene(){
if let scene = SKScene(fileNamed: "GameScene") {
scene.scaleMode = .aspectFill
scene.backgroundColor = .clear
gameScene.presentScene(scene)
gameScene.allowsTransparency = true
gameScene.ignoresSiblingOrder = true
gameScene.showsFPS = true
gameScene.showsNodeCount = true
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12981 次 |
| 最近记录: |