我只有一个包含以下变量的场景:
widthOfScene = self.size.width
heightOfScene = self.size.height
var constLabelPosition = CGPoint(x:witdhOfScene*0.6, y: heightOfScene*0.95)
var dynamLabelPosition = CGPoint(x: constLabelPosition.x * 0.1, y: constLabelPosition.y)
即使我决定在几个月内更改 constLabelPosition
,我也希望我的 dynamLabel 始终位于 constLabel 右侧的 10%。
我的代码不工作。 dynamLabel
总是在 constLabel
的中间...有没有办法实现这种动态标签位置?
最佳答案
抱歉,这似乎只是对 dynamicLabelPosition 的 x 位置的简单计算错误。
你确定你不是这个意思:
var dynamLabelPosition = CGPoint(x: constLabelPosition.x + constLabelPosition.x * 0.1, y: constLabelPosition.y)
关于ios - 如何在 Swift 的 Spritekit 中创建动态位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47667290/