SpriteKit 和 JSTileMap
SpriteKit and JSTileMap
我很难理解 JSTileMap 如何与 SpriteKit 和 Tiled 一起工作。
问题与像素和点有关,也与使用基于屏幕比例因子的 JSTileMap 加载适当的图块集有关。
项目中的文件结构
在我的项目中,有些文件具有以下结构,这代表我的低分辨率地图(1024x768 像素,32x32 像素图块):
- 名为 SD 的文件夹
- 级别-1.tmx
- 文件夹 tmx-levels-sd.atlasc
- tmx-levels-sd.1.png
- tmx-levels-sd.plist
在这种情况下,当我在非视网膜模拟器上加载 level-1.tmx 时,一切都正确定位。当我 运行 在 Retina 模拟器上使用相同的配置时,一切都很好,但瓷砖被缩放了。因为质量受到影响。
那么,如何在需要时加载高分辨率图块集?
另一种方案
我还尝试通过为每个级别使用两个版本的地图(低分辨率和高分辨率)来解决这个问题。这实际上是我试图避免但仍然可以接受的:
对于这种情况,我有这样结构的文件(地图是 2048x1536 和 64x64px 的图块):
- 名为 SD 的文件夹
- 级别-1.tmx
- 文件夹 tmx-levels-sd.atlasc
- tmx-levels-sd.1.png
- tmx-levels-sd.plist
- 名为 HD 的文件夹
- 一级-hd.tmx
- 文件夹 tmx-levels-hd.atlasc
- tmx-levels-hd.1.png
- tmx-levels-hd.plist
我想我的地图的高分辨率版本适合大小为 2048x1536 且分块大小加倍的地图吗?同样如您所见,我的项目中根本没有@2x tilesets(我猜我们不能在 Tiled 编辑器和 JSTileMap 中使用 @2x 后缀?)。
此配置的问题是所有内容都已更改(位置和图块大小加倍)。 JSTileMap 可能与点一起工作,与像素一起平铺,最重要的是有一个已知的 iPad simulator bug related to texture atlases 这让我很难理解是什么导致了高分辨率地图的问题。
有人可以澄清一下关于一起使用 JSTileMap、SpriteKit 和 Tiled 的这些事情吗?谢谢!
收到你的消息了
首先,您需要@1x 和@2x 版本的图块(精灵)。因此,如果您有一个名为 myTiles 的地图集,您将需要:myTiles.png & myTiles@2x.png.
我使用纹理打包器创建了精灵 sheet。我添加了 @2x 图像,然后在导出时创建了一个 @1x 版本。
在 Tiled 中仅使用 @1x 版本,因此您将使用 myTiles.png
如果您的地图是 32x32,则您的 @1x 版本将为 32x32,您的 @2x 版本将为 64x64
忘记 SD 和 HD 文件夹,只使用 1 个名为 say Levels 的文件夹
这里你需要:
级别-1.tmx,
tmx-levels-sd.1.png,
tmx-levels-sd.1@2x.png
主关卡文件夹下可以有子文件夹。由您决定,但您必须同时拥有 png 的 @1x 版本和 @2x 版本,并且您不能只复制 @1x 或 @2x 版本。 @1x 版本必须是基于 32x32 的图块,@2x 版本必须是它的两倍 (64x64)。在 tmx 文件本身中,您不会加载 @2x 版本,因为这会弄乱您的关卡。
** 所以您的游戏将在 32x32 的图块集上运行。 sprite kit 将做的是将视网膜显示器上的像素加倍,因此为此您需要有可用的 @2x 版本,否则它会升级您的 @1x 版本并且图块看起来会很大且像素化。所以尽量不要混淆整个像素到点的东西。
代码示例:
GameViewController(加载场景):
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentLevel = 1;
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
// Create and configure the scene.
LevelScene *scene = [[LevelScene alloc]initWithSize:skView.bounds.size level:self.currentLevel];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
LevelScene(加载 JSTileMap):
#import "LevelScene.h"
#import "SKTAudio.h"
#import "JSTileMap"
#import "Player.h"
@interface LevelScene()
@property (nonatomic, assign) NSUInteger currentLevel;
@property (nonatomic, strong) SKNode *gameNode;
@property (nonatomic, strong) JSTileMap *map;
@property (nonatomic, strong) Player *player;
@property (nonatomic, assign) NSTimeInterval previousUpdateTime;
@implementation LevelScene
-(id)initWithSize:(CGSize)size level:(NSUInteger)currentLevel {
if ((self = [super initWithSize:size])) {
self.currentLevel = currentLevel;
self.gameNode = [SKNode node];
[self addChild:self.gameNode];
NSString *levelName = [levelDict objectForKey:@"level"];
self.map = [JSTileMap mapNamed:levelName];
[self.gameNode addChild:self.map];
return self;
}
我很难理解 JSTileMap 如何与 SpriteKit 和 Tiled 一起工作。
问题与像素和点有关,也与使用基于屏幕比例因子的 JSTileMap 加载适当的图块集有关。
项目中的文件结构
在我的项目中,有些文件具有以下结构,这代表我的低分辨率地图(1024x768 像素,32x32 像素图块):
- 名为 SD 的文件夹
- 级别-1.tmx
- 文件夹 tmx-levels-sd.atlasc
- tmx-levels-sd.1.png
- tmx-levels-sd.plist
在这种情况下,当我在非视网膜模拟器上加载 level-1.tmx 时,一切都正确定位。当我 运行 在 Retina 模拟器上使用相同的配置时,一切都很好,但瓷砖被缩放了。因为质量受到影响。 那么,如何在需要时加载高分辨率图块集?
另一种方案
我还尝试通过为每个级别使用两个版本的地图(低分辨率和高分辨率)来解决这个问题。这实际上是我试图避免但仍然可以接受的:
对于这种情况,我有这样结构的文件(地图是 2048x1536 和 64x64px 的图块):
- 名为 SD 的文件夹
- 级别-1.tmx
- 文件夹 tmx-levels-sd.atlasc
- tmx-levels-sd.1.png
- tmx-levels-sd.plist
- 名为 HD 的文件夹
- 一级-hd.tmx
- 文件夹 tmx-levels-hd.atlasc
- tmx-levels-hd.1.png
- tmx-levels-hd.plist
我想我的地图的高分辨率版本适合大小为 2048x1536 且分块大小加倍的地图吗?同样如您所见,我的项目中根本没有@2x tilesets(我猜我们不能在 Tiled 编辑器和 JSTileMap 中使用 @2x 后缀?)。
此配置的问题是所有内容都已更改(位置和图块大小加倍)。 JSTileMap 可能与点一起工作,与像素一起平铺,最重要的是有一个已知的 iPad simulator bug related to texture atlases 这让我很难理解是什么导致了高分辨率地图的问题。
有人可以澄清一下关于一起使用 JSTileMap、SpriteKit 和 Tiled 的这些事情吗?谢谢!
收到你的消息了
首先,您需要@1x 和@2x 版本的图块(精灵)。因此,如果您有一个名为 myTiles 的地图集,您将需要:myTiles.png & myTiles@2x.png.
我使用纹理打包器创建了精灵 sheet。我添加了 @2x 图像,然后在导出时创建了一个 @1x 版本。
在 Tiled 中仅使用 @1x 版本,因此您将使用 myTiles.png
如果您的地图是 32x32,则您的 @1x 版本将为 32x32,您的 @2x 版本将为 64x64
忘记 SD 和 HD 文件夹,只使用 1 个名为 say Levels 的文件夹
这里你需要:
级别-1.tmx, tmx-levels-sd.1.png, tmx-levels-sd.1@2x.png
主关卡文件夹下可以有子文件夹。由您决定,但您必须同时拥有 png 的 @1x 版本和 @2x 版本,并且您不能只复制 @1x 或 @2x 版本。 @1x 版本必须是基于 32x32 的图块,@2x 版本必须是它的两倍 (64x64)。在 tmx 文件本身中,您不会加载 @2x 版本,因为这会弄乱您的关卡。
** 所以您的游戏将在 32x32 的图块集上运行。 sprite kit 将做的是将视网膜显示器上的像素加倍,因此为此您需要有可用的 @2x 版本,否则它会升级您的 @1x 版本并且图块看起来会很大且像素化。所以尽量不要混淆整个像素到点的东西。
代码示例:
GameViewController(加载场景):
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentLevel = 1;
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
// Create and configure the scene.
LevelScene *scene = [[LevelScene alloc]initWithSize:skView.bounds.size level:self.currentLevel];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
LevelScene(加载 JSTileMap):
#import "LevelScene.h"
#import "SKTAudio.h"
#import "JSTileMap"
#import "Player.h"
@interface LevelScene()
@property (nonatomic, assign) NSUInteger currentLevel;
@property (nonatomic, strong) SKNode *gameNode;
@property (nonatomic, strong) JSTileMap *map;
@property (nonatomic, strong) Player *player;
@property (nonatomic, assign) NSTimeInterval previousUpdateTime;
@implementation LevelScene
-(id)initWithSize:(CGSize)size level:(NSUInteger)currentLevel {
if ((self = [super initWithSize:size])) {
self.currentLevel = currentLevel;
self.gameNode = [SKNode node];
[self addChild:self.gameNode];
NSString *levelName = [levelDict objectForKey:@"level"];
self.map = [JSTileMap mapNamed:levelName];
[self.gameNode addChild:self.map];
return self;
}