简体   繁体   English

如何在不使用抗锯齿的情况下缩放SKSpirteNode

[英]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). 我试图在不进行平滑/抗锯齿的情况下缩放SKSpriteNode对象(我使用的是像素艺术,因此看起来像素化更好)。

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 这是hero_1.png 在此处输入图片说明 .

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 SKTextureFiltering最近

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

Just a note, if you create a SKSpriteNode instead of SKTexture , you can set the SKTextureFilteringNearest like in the following example: 请注意,如果创建一个SKSpriteNode而不是SKTexture ,则可以像下面的示例一样设置SKTextureFilteringNearest

SKSpriteNode *asteroid = [SKSpriteNode spriteNodeWithImageNamed:@"o1"];
asteroid.size = CGSizeMake(36, 24);
asteroid.position = CGPointMake(startX, startY);
asteroid.name = @"obstacle";
// >>>
asteroid.texture.filteringMode = SKTextureFilteringNearest;
// <<<
[self addChild:asteroid];

try this: 尝试这个:

hero.xscale = 6.0f;
hero.yscale = 6.0f;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM