Since upgrading my iPad mini to iOS 12.2 and xcode to 10.2, I've had the following problem...
SKTexture.cgImage() returns an image the size of the visible image rather than the original image that the SKTexture was created with. I need to get a CGImage the size of the texture, and not just the visible pixels.
A very simple example... I have a 32x32 png image that the bottom 16 pixels are clear (alpha of 0) and all of the top 16 rows are a solid color (it's a rectangle filling the top 16 rows). I have imported it into an .xcassets file in xcode. I have a TileSet (.sks file) where I've included the png as a texture of a tile definition. If I look at the properties of the png in xcode, it says it is 32x32px. If I look at the properties of the tile definition it says it is 32x32px. Everything good so far.
I need to examine the pixels of the CGImage of the resulting texture during runtime. I do this by loading the SKTexture from the SKTileSet made in xcode designers, and doing SKTexture.cgImage(). At the time this happens, the SKTexture object reports a size of 32x32 as expected, but the CGImage that comes back is 32x16. It would appear that something has decided that only the top 16 pixels are actually being used (i.e. visible) and therefore the CGImage should be 32x16, and not 32x32 like the SKTexture, or even the original png used to create the texture.
This is a problem for two reasons...
1. I want the image that starts off as 32x32 to always be 32x32, for consistency. I'm showing these textures in an SKTileMapNode and the ones which it thinks are 32x16 get stretched undesirably in the tile map node cells. e.g. my 32x16 rectangle gets stretched double across the height to fill the 32x32 squares in the tile map node.
2. I can't even find out where amongst the 32x32 texture the 32x16 area should be showing. It would be nice if something could at least tell me "yeah it's coming back as 32x16 but that's because we're offsetting it by 0,0".
So the question is either...
A. How do I get the CGImage from the SKTexture without it automatically cropping it? i.e. a 32x32 SKTexture always returning a 32x32 CGImage.
OR
B. How do I stop it automatically cropping images when applied to SKTextures?
Many thanks for any pointers or help. This is driving me crazy as it has broken my entire game in many ways!