- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个添加了一些元素的简单场景。
现在我想专注于一个带有 mask 的特定元素,并在与我想要专注的元素相同的位置切割一个整体。非常类似于我们在某些游戏上看到的,当它们第一次启动时显示某种教程。
基本上,我添加了一个带alpha=0.7
的全屏层(这样用户仍然可以看到所有内容),然后在特定位置添加一个圆圈作为该层的子层并设置blendMode=
。减去它从这个全屏层“切”出一个圆圈,所以在这个圆圈内你有一个清晰的 View 。
将所有元素添加到屏幕后,我有以下代码。
// before this code i added some basic elements like circles and backgrounds
let mask = SKSpriteNode(color: .blackColor(), size: self._screenSize)
mask.anchorPoint = CGPoint.zero
mask.position = CGPoint.zero
mask.zPosition = 100
mask.alpha = 0.7
let circle = SKShapeNode(circleOfRadius: Constants.Config.playersize*2)
circle.fillColor = .blackColor()
circle.lineWidth = 0
let circle_mask = SKSpriteNode(texture: SKView().textureFromNode(circle, crop: circle.frame))
circle_mask.blendMode = .Subtract
circle_mask.zPosition = 101
// now show the layer with alpha=0.7 and the circle mask being at the same position as my player element i want to focus on
mask.addChild(circle_mask)
circle_mask.position = player.position
self.addChild(mask)
但是这个只是加了全屏层,没有圆孔。看起来它忽略了 circle_mask 节点。我做错了什么?
我的计划还包括不断移动圆形蒙版以聚焦于此场景中的其他元素。我认为。减去它应该只从它的父节点减去,它是 alpa=0.7
的全屏层,对吧?
我刚刚尝试使用 SKCropNode。将全屏层作为子层添加到裁剪节点中,然后将圆指定为蒙版。但现在它几乎切掉了所有东西,只显示了我的全屏图层的一个圆圈,我实际上需要这个裁剪节点的反转结果。
blendMode 的问题在于它在最终的帧缓冲区上运行,但我需要的是仅在父节点上运行它,因此在使用 .Subtract 时它不会剪切节点后面的所有内容
最佳答案
下面是一个关于如何创建一个打洞的半透明层的例子:
-(注意:.subtract 混合模式不考虑 Sprite 的 alpha,因此您需要使用裁剪节点)
self.backgroundColor = .red
//Our transparent overlay
let fullScreen = SKSpriteNode(color: .black, size: self.size)
fullScreen.position = CGPoint.zero
fullScreen.zPosition = 100
fullScreen.alpha = 0.7
//let's make a mask to punch circles in our shape
let mask = SKSpriteNode(color: .white, size: self.size)
mask.position = CGPoint.zero
mask.zPosition = 100
mask.alpha = 1
let circle = SKShapeNode(circleOfRadius: 20*2)
circle.fillColor = .white
circle.lineWidth = 0
circle.alpha = 1
//let circle_mask = SKSpriteNode()
circle.blendMode = .subtract
mask.addChild(circle)
//let's create the node to place on screen
let crop = SKCropNode()
crop.maskNode = mask
crop.addChild(fullScreen)
self.addChild(crop)
关于swift - SpriteKit : Howto make holes in layer with blendMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40699926/
我是 Keras 新手,我正在尝试获取 Keras 中的权重。我知道如何在 Python 中的 Tensorflow 中执行此操作。 代码: data = np.array(attributes, '
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我尝试在单击时向 map 添加新标记,并尝试保存标题和描述以在标记悬停时显示,但出现以下错误: Cannot read property 'add Layer' of undefined Javasc
我想要一个传单图层控件,我可以在其中选择一个基础图层,并使这个基础图层本身成为一个 LayerGroup,我可以从中选择要显示的子图层。我正在考虑一个设置,我单击一个单选按钮来选择基础层(层组),然后
我在 GIMP Script-fu 和过程浏览器中遇到了一个简单的问题。 我正在尝试在具有 40 层的图像中向上/向下移动一个层。让我们调用图像 test.xcf 和所述层 Chromask-snap
我有一个(非常大的)脚本在 InDesign 中运行,该脚本在某一时刻将库资源放置到页面上,然后将其移动到特定图层。此脚本在我们这里的所有计算机上都运行良好,但仅当当时 InDesign 中没有打开其
在一些使用 tf2 的 Tensorflow 教程(例如 Neural Machine Translation with Attention 和 Eager essentials )中,他们定义了自定
现在我无法解决依赖性,怎么了? 公司会更改名称吗?但是,我在他们的网站上看到它,但没有“com.layer.atlas:layer-atlas”,但是我的应用程序包含此依赖项,谁能告诉我原因? 最佳答
我使用 Keras 并尝试将两个不同的层连接成一个向量(向量的第一个值是第一层的值,另一部分是第二层的值)。 其中一层是密集层,另一层是嵌入层。 我知道如何合并两个嵌入层或两个密集层,但我不知道如何合
我正在开发一个类来创建各种对称 AE。我现在把这个类移植到TF 2.0,比我想象的要复杂。但是,我使用层和模型的子类来实现此目的。因此,我想将多个 keras 层分组为一个 keras 层。但如果我想
我正在为 CAGradient 设置动画 let gradientChangeAnimation = CABasicAnimation(keyPath: "colors") gradientC
什么是使用 OOP 在业务逻辑对象和数据库之间分层的良好设计? 最佳答案 这些中的任何一个都可以( from Fowler's POEAA ): 数据源架构模式: 表数据网关:充当数据库表网关的对象。
我正在尝试将一些 UIImages 渲染成一张我可以保存在我的相册中的图像。但是好像 layer.renderInContext 没有考虑图层蒙版? 当前行为:照片保存,我看到了 mosaicLaye
哇,这完全令人困惑,而且 dojo 1.8 文档似乎是围绕构建层的完整 clusterf**k。有人知道那里发生了什么吗? 在构建脚本示例配置文件中,示例 amd.profile.js 有 profi
我的 spacemacs 是 0.200.3@25.1.1 每次启动spacemacs时都会收到警告,如何解决? Warnings: - dotspacemacs-configuration-laye
引用是这样的: There's no problem in Computer Science that can't be solved by adding another layer of abstr
我正在使用 Keras 并且有一个自定义层,但是当我使用它时,会发生以下错误,我不知道问题是什么。你能帮我解决这个问题吗?奇怪的是,当我在另一个系统上使用相同的代码时,没有出现此错误! import
我应该什么时候使用 Input我什么时候应该使用 InputLayer ?在 source code有一个描述,但我不确定它是什么意思。 输入层: Layer to be used as an ent
我正在尝试构建一个可以在音频和视频样本上进行训练的模型,但出现此错误 ValueError:请使用“Layer”实例初始化“TimeDistributed”层。您传递了:Tensor("input_1
我正在实现一个需要支持 mask 的自定义 tf.keras.layers.Layer。 考虑以下场景 embedded = tf.keras.layer.Embedding(input_dim=vo
我是一名优秀的程序员,十分优秀!