首先,使用场景的默认大小 - 您不需要缩放或更改它们的大小,这很糟糕。
接下来,只需使用最近邻缩放方法预先缩放精灵(例如在 Photoshop 中) - 这可以保持像素分离并且不会引入抗锯齿。
例如,如果您有原始的 32x32 资源,请将其缩放到 64x64 或 128x128 并在游戏中使用它。它看起来会很棒。
另一种方法是让资源保持原始大小,但在运行时缩放它们。
这里 SKSpriteNode 的 .xScale 和 .yScale 属性就派上用场了。
但如果你缩放你的精灵,它就会失去其清晰度——抗锯齿伪像将会出现在各处。
您有两种方法来处理这个问题 - 首先创建纹理并将其过滤方法设置为最近的邻居,如下所示:
texture.filteringMode = SKTextureFilteringNearest;
但这很快就会失控,所以我建议改用 SKTextureAtlas 上的类别:
SKTextureAtlas+NearestFiltering.h
#import <SpriteKit/SpriteKit.h>
@interface SKTextureAtlas (NearestFiltering)
- (SKTexture *)nearestTextureNamed:(NSString *)name;
@end
SKTextureAtlas+NearestFiltering.m
#import "SKTextureAtlas+NearestFiltering.h"
@implementation SKTextureAtlas (NearestFiltering)
- (SKTexture *)nearestTextureNamed:(NSString *)name
{
SKTexture *temp = [self textureNamed:name];
temp.filteringMode = SKTextureFilteringNearest;
return temp;
}
@end
这样你就可以通过调用这个方法来创建SKSpriteNodes:
SKSpriteNode *temp = [[SKSpriteNode alloc] initWithTexture:[self.atlas nearestTextureNamed:@"myTexture"]];