gpt4 book ai didi

sprite-kit - 教程中的 SpriteKit : How do you highlight a section of the scene,?

转载 作者:行者123 更新时间:2023-12-05 05:25:55 25 4
gpt4 key购买 nike

我正在尝试在游戏中创建一个教程,它遍历 UI 的各个部分并突出显示它们,同时使场景的其余部分变暗。

我想我可以用 Sprites 和 SKBlendMode 来做,但是苹果引用指南中对这些的解释很差。

有什么想法吗?

最佳答案

实现此目的的一种方法是通过 SKSpriteNode 组合您想要的“cookie”,然后创建一个纹理以将其“按原样”渲染到新的 SpriteNode,然后它将作为一个整体与场景融合。

在这个简单的示例中,我使用了一个矩形来突出显示,但您可以将该节点设为任何节点类型或图像,并相应地调整 alpha 值。

正常绘制场景,然后添加以下代码:

// dim the entire background of the scene to 70% darker
SKSpriteNode* background = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0
green:0
blue:0
alpha:0.7]
size:self.frame.size];

// make a square of 100,100. This could be an image or shapenode rendered to a spritenode
// make the cut out only dim 20% - this is because no dim will look very harsh
SKSpriteNode* cutOut = [SKSpriteNode spriteNodeWithColor:[UIColor colorWithRed:0
green:0
blue:0
alpha:0.2]
size:CGSizeMake(100,100)];

// add the cut out to the background and make the blend mode replace the colors
cutOut.blendMode = SKBlendModeReplace;
[background addChild:cutOut];

// we now need to make a texture from this node, otherwise the cutout will replace the underlying
// background completely

SKTexture* newTexture = [self.view textureFromNode:background];
SKSpriteNode* newBackground = [SKSpriteNode spriteNodeWithTexture:newTexture];

// position our background over the entire scene by adjusting the anchor point (or position)
newBackground.anchorPoint = CGPointMake(0,0);
[self addChild:newBackground];

// if you have other items in the scene, you'll want to increaes the Z position to make it go ontop.
newBackground.zPosition = 5;

关于sprite-kit - 教程中的 SpriteKit : How do you highlight a section of the scene,?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com