什么是在Sprite Kit中显示像素艺术的最佳方式?

时间:2014-06-16 23:07:31

标签: sprite-kit pixel

我很好奇我将如何为我的游戏展示像素艺术。现在我只是将SKScene的大小调整为sceneWithSize:CGSizeMake(256, 192)这是正确的方法,还是有一种方法可以用来做这类任务?

1 个答案:

答案 0 :(得分:6)

首先,使用默认大小的场景 - 您不需要缩放或更改它们的大小,这很糟糕。

接下来,只需使用最近邻比例方法预先缩放精灵(例如在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"]];
相关问题