我正在尝试在SK中循环我的背景图片,问题是背景很长,所以我将图片拆分为瓷砖,我将其与代码粘贴在一起。我想循环这个巨大的背景,但我不知道如何,循环背景的常规方法没有用,因为我的背景由多个节点组成。 /强>
这是我用来将节点渲染在一起的方法。
- (SKNode *) createBackgroundNode
{
// 1
// Create the node
SKNode *backgroundNode = [SKNode node];
// 2
// Go through images until the entire background is built
for (int nodeCount = 0; nodeCount < 20; nodeCount++) {
// 3
NSString *backgroundImageName = [NSString stringWithFormat:@"Background%02d", nodeCount+1];
SKSpriteNode *node = [SKSpriteNode spriteNodeWithImageNamed:backgroundImageName];
// 4
node.anchorPoint = CGPointMake(0.5f, 0.0f);
node.position = CGPointMake(160.0f, nodeCount*64.0f);
// 5
backgroundNode.name =@"background";
[backgroundNode addChild:node];
}
// 6
// Return the completed background node
return backgroundNode;
}
然后在我的更新方法中,我使用此代码通过在所需方向上移动背景图层位置来一次移动所有图块。
[self enumerateChildNodesWithName:@"background" usingBlock: ^(SKNode *node, BOOL *stop) {
SKSpriteNode *bg = (SKSpriteNode *) node;
bg.position = CGPointMake(0.0f, -((_player.position.y - 200.0f)/10));
}];
问题是,我无法获得背景图层的大小只有位置(至少我认为我不能)所以我不知道我如何无缝循环所有这些瓷砖?
我最好想在一堂课中完成所有这些,但任何有用的建议都将不胜感激!