gpt4 book ai didi

ios - Sprite Kit,灰色背景而不是图像

转载 作者:行者123 更新时间:2023-11-29 10:31:46 25 4
gpt4 key购买 nike

我似乎无法让我的背景显示图像。

代码如下:

@implementation GameScene

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

self.anchorPoint = CGPointMake(0.5, 0.5);

SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];
[self addChild:background];
}
return self;
}

@end

- (void)viewDidLoad
{
[super viewDidLoad];

// 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.
GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];
scene.scaleMode = SKSceneScaleModeResizeFill;

// Present the scene.
[skView presentScene:scene];
}

最佳答案

我认为问题在于当您 unarchiveFromFile: 而不是尝试在您的场景中使用 didMoveToView: 时,initWithSize: 实际上并未被调用。

-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"Background"];
[self addChild:background];
}

希望对您有所帮助。

关于ios - Sprite Kit,灰色背景而不是图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29239827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com