Problem with Overlapped Textures and Transparent Pixels

Sorry if this is the wrong place to post, but like many others have pointed out there is no spot in pre-release for xcode 7 questions (please move message if I'm wrong).


I am building a single image by overlapping two or more images.


I'm using a texture atlas containing layer 1, 2, 3, etc

I set the anchor point to 0,0

I draw the first image

I load the next image

set the anchor to 0,0

and draw it on top of the first.


the first image is 14 pixels wide and 14 pixels tall (no transparent pixels)

the second image is also 14 pixels wide and 14 pixels tall, but it has a fully transparent pixel around it (so the actual image is 12x12)


In xcode 6 I would see the second image centered on top of the first.

in xcode 7 I see the second image position in the bottom left corner of the first image. It appears to be cropping out the blank pixels.


I know in the past people have suggested using a 1% alpha pixel rather than fully transparent to work around this issue. However, I did not have this issue in xcode 6.


So why is xcode 7 cropping out the fully transparent pixels? It's positioning the second image like it is a 12x12 image (removing the top, right, left and bottom rows and columns of transparent pixels)


What's more puzzling is that when I look a the image sizes it properly reports them both at 14x14 pixels. Texture size also reports 14x14


Here is the code I'm using (rough):


texgen = img_atlas.textureNamed("img1")
texgen.filteringMode = SKTextureFilteringMode.Nearest
let bm1: SKSpriteNode = SKSpriteNode(texture: texgen)
       
texgen = img_atlas.textureNamed("img2")
texgen.filteringMode = SKTextureFilteringMode.Nearest
let bm2: SKSpriteNode = SKSpriteNode(texture: texgen)
       
bm1.anchorPoint = CGPoint(x: 0.0, y: 0.0)
bm2.anchorPoint = CGPoint(x: 0.0, y: 0.0)
       
bm1.position = CGPoint(x: 0, y: 0)    
bm2.position = CGPoint(x: 0, y: 0)
       
canvasNode.addChild(bm1)
canvasNode.addChild(bm2)


the two images should be right on top of each other with the edges/border of the first around the second image.


======>


On a seperate note, does anyone know if you can now mix and match nearest and linear when using texture atlases in xcode 7? In 6 if I set nearest, everything was nearest, if I set linear, everything was linear (I know you can get around this with tricks, but I'm not a fan of hacks)

And the problem with Swift is? Sound like the Graphics & Games subforum would be a better place to ask.

It definitely seems like something SpriteKit users would be able to help more with, but I would guess that collision detection might be a cause of the "cropping" of the transparent bits of the texture.


Have you tried using the:


Create a sprite with an SKTexture and the specified size.

@param texture the texture to reference for size and content

@param size the size of the sprite in points


convenience init(texture: SKTexture?, size: CGSize)


initializer instead, and specifying the size?

Tia, sorry... as I stated, I wasn't sure if I was posting to the correct forum or not. I did not notice the issue with xcode 6, I am noticing it with xcode 7. Because my project required an upgrade/compatability check (from what I read... to a new version of swift) I assumed the issue would either be a change in swift or a bug in xcode. If anyone can move this post for me to the correct forum please do.


LCS, I appreciate the response. I have tried specifying the pixel size manually.

When I load the textures outside the atlas they overlap perfectly. Unfortunately that results in a much slower program. I am curious however about your mention of collision detection maybe causing the cropping?

No reason to be sorry. I just was wondering how Swift was somehow involved 😉

I read about SpriteKit and texture atlases a bit more, and it looks like the trimming is considered a feature rather than a bug.


https://developer.apple.com/library/ios/recipes/xcode_help-texture_atlas/AboutTextureAtlases/AboutTextureAtlases.html

"Those new images are automatically rotated and trimmed to fit the maximum number of images into a single file..."



So it sounds like you would need to use the 1% alpha workaround you mentioned above, or use the default centered anchor point on the sprite and textures.

Appreciate the link, and I do understand that the textures are packed together as tightly as possible to make an efficient atlas. However... in previous versions of xcode even though the atlas didn't show the transparent pixels, it was keeping track of the size properly and would return the images back to you exactly as they were before they were put into the atlas (including transparent portions). As I mentioned above I find it strange that when I ask for the size it says 14x14 (not 12x12) but it's rendering at 12x12. Frustrating. I'm hoping it's just a bug like the many other issues I'm running into (ex: generating a physics body from a texture apparently creates garbage). Appreciate the response(s)!

Problem with Overlapped Textures and Transparent Pixels
 
 
Q