我很好奇我将如何为我的游戏展示像素艺术.现在我只是调整的SKScene是sceneWithSize:CGSizeMake(256, 192),这是正确的做法还是有贝斯特的方式去这样做这类工作的?
首先,使用默认大小的场景 - 您不需要缩放或更改其大小,这很糟糕.
接下来,使用最近邻比例方法预先缩放精灵(例如在Photoshop中) - 这样可以保持像素分离并且不会引入抗锯齿.
因此,例如,如果您拥有原始32x32资产,请将其缩放为64x64或128x128并在游戏中使用它.它会看起来很棒.
另一种方法是使资源具有原始大小,但在运行时缩放它们.
SKSpriteNode的.xScale和.yScale属性派上用场.
但是如果你扩展你的精灵它会失去它的清脆度 - 抗锯齿工件将全部出现.
您有两种方法可以解决这个问题 - 首先创建纹理并将其过滤方法设置为最近邻居,如下所示:
texture.filteringMode = SKTextureFilteringNearest;
Run Code Online (Sandbox Code Playgroud)
但这很快失控,所以我建议使用SKTextureAtlas上的类别:
SKTextureAtlas + NearestFiltering.h
#import <SpriteKit/SpriteKit.h>
@interface SKTextureAtlas (NearestFiltering)
- (SKTexture *)nearestTextureNamed:(NSString *)name;
@end
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
这样,您可以通过调用此方法来创建SKSpriteNodes:
SKSpriteNode *temp = [[SKSpriteNode alloc] initWithTexture:[self.atlas nearestTextureNamed:@"myTexture"]];
Run Code Online (Sandbox Code Playgroud)