如何从SKTexture获取原始图像比例?

我在Swift中使用sprite-kit并使用SKTexture(rect:inTexture:)函数设置纹理。 我没有使用内置的纹理图集,而是使用SKTexture(imageNamed:)创建父纹理(纹理图集)。 这是因为我的数据文件中已有地图集和子纹理位置(以像素为单位),而不是单独的图像。

因此,当图像为@ 2x(大小为像素尺寸的一半.size()时, SKTexture对象的SKTexture .size()是正确的。 我通过除以大小来计算子矩形坐标(在单位坐标中,0-1),但我需要知道原始图像比例,以便我可以将像素尺寸除以它。

这是我的代码很好地工作:

 // Create the texture as a sub-rect of the parent texture if let parentTexture = textures[parentTextureId] { let size = parentTexture.size() var subRect = CGRectFromString(subRectString) subRect = CGRectMake( (subRect.origin.x / 2) / size.width, (size.height - ((subRect.origin.y / 2) + (subRect.size.height / 2))) / size.height, (subRect.size.width / 2) / size.width, (subRect.size.height / 2) / size.height) let texture = SKTexture(rect: subRect, inTexture: parentTexture) textures[textureId] = texture } 

问题是我不得不对所有这些/ 2调整进行硬编码。 如何获得纹理的原始图像比例(或实际像素尺寸),以便我可以正确计算子矩形而无需硬编码?