在 Sprite Kit 中显示像素艺术的最佳方式是什么? [英] What Is The Best Way To Display Pixel Art In Sprite Kit?

查看:79
本文介绍了在 Sprite Kit 中显示像素艺术的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇我将如何为我的游戏显示像素艺术.现在我只是将 SKScene 的大小调整为 sceneWithSize:CGSizeMake(256, 192) 这是正确的方法还是有更好的方法来进行这种排序任务?

I'm curious to how I would display pixel art for my game. For now i'm just resizing the SKScene to be sceneWithSize:CGSizeMake(256, 192) is this the correct way or is there a bester way to go about doing this sort of task?

推荐答案

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

First, use the default sizes of scenes - you do not need to scale or change their sizes, this is just bad.

接下来只需使用最近邻缩放方法预先缩放您的精灵(例如在 Photoshop 中) - 这样可以保持像素分离并且不会引入抗锯齿.

Next just scale your sprites either beforehand (in Photoshop for example) using nearest neighbor scale method - this keeps pixels separate and does not introduce antialias.

例如,如果您有原始的 32x32 资源,请将其缩放到 64x64 或 128x128 并在游戏中使用.它看起来很棒.

So for example if you have original 32x32 asset, scale it to 64x64 or 128x128 and use it in game. It will look great and all.

另一种方法是拥有原始大小的资产,但在运行时对其进行缩放.

Another way is to have assets at original size, but scale them at runtime.

这里 SKSpriteNode 的 .xScale 和 .yScale 属性就派上用场了.

Here .xScale and .yScale properties of SKSpriteNode come in handy.

但是如果你缩放你的精灵,它会失去它的脆度——抗锯齿伪影会到处出现.

But if you scale your sprite it will lose its crispiness - antialiasing artifacts will appear all over.

您有两种方法来处理这个问题 - 首先创建纹理并将它们的过滤方法设置为最近的邻居,如下所示:

You have two ways to deal with this - either create textures first and set their filtering method to nearest neighbour like so:

texture.filteringMode = SKTextureFilteringNearest;

但这很快就会失控,所以我建议改用 SKTextureAtlas 上的类别:

But this gets out of hand fast, so I suggest using the category on SKTextureAtlas instead:

SKTextureAtlas+NearestFiltering.h

SKTextureAtlas+NearestFiltering.h

#import <SpriteKit/SpriteKit.h>

@interface SKTextureAtlas (NearestFiltering)

- (SKTexture *)nearestTextureNamed:(NSString *)name;

@end

SKTextureAtlas+NearestFiltering.m

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:

This way you can create SKSpriteNodes by calling this method:

SKSpriteNode *temp = [[SKSpriteNode alloc] initWithTexture:[self.atlas nearestTextureNamed:@"myTexture"]];

这篇关于在 Sprite Kit 中显示像素艺术的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆