Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you scale SKSpirteNode without anti aliasing

I am trying to scale an SKSpriteNode object without smoothing/anti-aliasing (I'm using pixel-art so it looks better pixelated).

Is there a property I need to set to do this? This is the code I am using to render the sprite:

SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"objects"];
SKTexture *f1 = [atlas textureNamed:@"hero_1.png"];

SKSpriteNode *hero = [SKSpriteNode spriteNodeWithTexture:f1];
[self addChild: hero];

hero.scale = 6.0f;

The image is scaled correctly but blurry/smoothed out. This is hero_1.png enter image description here.

like image 592
Edwin Iskandar Avatar asked Oct 05 '13 01:10

Edwin Iskandar


1 Answers

Try,

SKTexture *texture = [SKTexture textureWithImageNamed:@"Fak4o"];
texture.filteringMode = SKTextureFilteringNearest;
SKSpriteNode *newHero = [SKSpriteNode spriteNodeWithTexture:texture];
newHero.position = CGPointMake(200, 200);
[newHero setScale:50];
[self addChild:newHero];

SKTextureFilteringNearest

Each pixel is drawn using the nearest point in the texture. This mode is faster, but the results are often pixelated.

Swift:

sprite.texture!.filteringMode = .Nearest
like image 56
DogCoffee Avatar answered Sep 28 '22 16:09

DogCoffee