【问题标题】:How come my SKSpriteNode is not appearing at the image's default resolution?为什么我的 SKSpriteNode 没有以图像的默认分辨率显示?
【发布时间】:2025-12-10 18:10:01
【问题描述】:

我有一个基本分辨率为 960 x 119 (base_ground_sprite) 的图像,我试图在调试器中在屏幕底部运行它。然而,当我运行调试器时,它似乎被缩放到更大的尺寸,因此变得模糊。

我是一个绝对新手,正在尝试使用新的 Sprite Kit 并且可以使用一些帮助。

请注意,此代码的基础来自 Ray Wenderlich 的 sprite kit 教程。

MyScene.m 中发生以下情况:

-(id)initWithSize:(CGSize)size {    
if (self = [super initWithSize:size]) {

    NSLog(@"Size: %@", NSStringFromCGSize(size));

    self.backgroundColor = [SKColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];


    self.player = [SKSpriteNode spriteNodeWithImageNamed:@"player"];
    self.player.position = CGPointMake(self.player.size.width/2, self.frame.size.height/2);
    [self addChild:self.player];

    self.ground = [SKSpriteNode spriteNodeWithImageNamed:@"base_ground_sprite"];
    self.ground.position = CGPointMake(0,0);
    self.ground.physicsBody.dynamic = YES;
    [self addChild:self.ground];

    self.physicsWorld.gravity = CGVectorMake(0,0);
    self.physicsWorld.contactDelegate = self;

}
return self;

}

【问题讨论】:

  • 你的资源图片最后有@2x 吗?如果你在做一个空白的 SK 项目时使用飞船的测试代码,飞船看起来很垃圾,把 2x 放在最后会更好。
  • 我尝试使用@2x,但它看起来并没有改变任何东西。我将进一步搜索文档。我想学习 Cocos2D 是一种选择,但我希望能多玩一些 Sprite Kit……

标签: ios objective-c ios7 sprite-kit


【解决方案1】:

self.player = [SKSpriteNode spriteNodeWithImageNamed:@"player"];行改为

self.player = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"base_ground_sprite"] size:CGSizeMake(960, 119)];

这只是手动设置大小。

【讨论】:

    最近更新 更多