Swift - How to work with vector images in games?

1

Download a pdf vector image of 36x36 pixels, to which when I zoom it does not pixelate. This image is added to the project in the folder "Assets.xcassets" and in "Scale Factors" I chose "Single Vector".

But I happen to add it to my application (a game I'm doing) like this:

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 application on my iPhone, the image appears pixelated.

How can I do it so that my image does not become pixelated?

    
asked by albertcito 21.01.2016 в 01:24
source

1 answer

1

You have to keep in mind that Xcode does not use the vector image to use it directly. When you add an image in PDF format what Xcode does when compiling is to create all the assets @1x , @2x and @3x depending on the platforms where it will be used. Therefore, importing a PDF will only facilitate the management of images in Xcode .

So that it does not look pixelated, you have to import a PDF of the size that will be displayed. For example, if in Interface Builder I put a 40x40 image (this would be @1x ) I have to import a 40x40 PDF image for Xcode to generate the 80x80 ( @2x ) and 120x120 ( @3x ) versions without pixelation .

To work directly with vector images you can use libraries like SVGKit or SVGQuartzRenderer although you have to keep in mind that they do not implement 100% of the SVG standard. On the other hand, if you are looking for a little, there probably will be some more bookstore.

    
answered by 21.01.2016 / 08:49
source