2
votes

For my game I am trying to create custom textures from two other textures. This is to allow for a varietly of colours, etc in my sprites.

To do this, I'm creating a sprite by adding both textures together, then applying this to a new SKTexture by using

SKTexture *texture = [self.view textureFromNode:newSprite];

This works great on the whole and I get a nice custom texture. Except when trying my game on Retina devices, where the texture is the correct size on the screen, but clearly a lower resolution.

The textures are all there and properly named so I don't believe that that is an issue.

Has anyone encountered this, or know how I can create the proper @2x texture?

2
you could also use the color property and/or compose a sprite of multiple sprites overlaying the main sprite, I don't see why you would need to create a new texture for that - LearnCocos2D
Well the parts that I'm making the textures from can't just be colored. They're specific designs that our artist has made up. So similar to the way Jetpack Joyride must combine it's different jetpacks and different outfits. - Stuart Welsh
Still, assuming that a jetpack consists of multiple, uniquely designed parts, you can create a sprite node for each part and combine them in a single SKNode, and perhaps colorize each individual part as needed and you'd get the same effect without needing to have this as a separate texture. Moreso you can then animate the individual parts, for example to make them come apart when crashing or to individually colorize them to show damage. - LearnCocos2D
I've noticed this as well. This is a real problem for people who are using textureFromNode to blit node hierarchies to textures that haven't been added to the scene, for particle effects etc. You can use drawViewHierarchyInRect on the SKView, but this requires the node hierarchies to already have been drawn. I don't know if it is a bug, or something to do with the size and then placement of the texture being returned. - Sam Keene

2 Answers

1
votes

I finally (accidentally) figured out how to fix this. The node which you are creating a texture from has to be added to the scene. Otherwise you will get a non-retina size for your texture.

It's not ideal as it would be nice to create textures without having to add them onto the screen.

0
votes

I've discovered another way of improving the fidelity of textures created from ShapeNodes, not quite related to this question - but useful intel.

Create your shape at x2 its size and width. Create all the fonts and other shapes at the same oversized ratio. Make sure your positioning is relative to this overall size, (e.g. don't use absolute sizes, use relative sizes to the container.)

When you create the texture as a sprite it'll be huge - but then apply

sprite.scale = 0.5; // if you were using 2x

I've found this makes it look much higher resolution, no graininess, no fuzziness on fonts, sharp corners.

I also used tex.filteringMode = SKTextureFilteringNearest;

Thus: it doesn't have to be added to the scene and then removed.