I downloaded a vector pdf image of 36x36 pixels, which when I zoom in does not pixelate. I added this image to the project in the "Assets.xcassets" folder and in "Scale Factors" I chose "Single Vector".
But it happens that I add it to my application (a game that I am making) in this way:
news = SKSpriteNode(imageNamed: "News")
news.setScale(7.6)
news.position = CGPoint(
x: CGRectGetMidX(self.frame),
y: CGRectGetMidY(self.frame) - 20
)
self.addChild(news)
And when I run the app on my iPhone, the image appears pixelated.
How can I make it so my image doesn't get pixelated?
You have to take into account that
Xcode
it does not use the vector image to use it directly. When you add an image in formatPDF
, what it doesXcode
when compiling is create all theassets
@1x
,@2x
and@3x
depending on the platforms where it will be used. Therefore, importing aPDF
will only make it easier to manage the images inXcode
.So that it does not look pixelated you have to import a
PDF
size of the size that is going to be displayed. For example, ifInterface Builder
I put a 40x40 image in (this would be@1x
) I have to import a 40x40 PDF image so that Xcode generates the 80x80 (@2x
) and 120x120 (@3x
) versions without pixelation.To work directly with vector images, you can use libraries such as SVGKit or SVGQuartzRenderer, although you must bear in mind that they do not implement 100% of the SVG standard. On the other hand, if you search a little there is probably another bookstore.