本文介绍了雪碧套件侧面滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Sprite工具包,我想知道如何创建无限的侧面滚动游戏?我阅读了Sprite工具包文档,并阅读了场景的预处理过程.据说如果内容比场景大,我们可以重新调整场景的位置.我尝试了一下,但是它起作用了,但是当我滚动浏览整个背景图像时,我开始看到场景的默认背景.如何创建无限背景?谁能指出我有关他的问题的正确文档或文章?谢谢.

I started working with Sprite kit and I Was wondering how can I create an infinite side scrolling game? I read the Sprite kit documentation and I read through the pre-processing of the scene. It's stated that we can readjust the scene's position in case the content is larger then the scene. I tried it and it works however, when I scroll through out the entire background image, I start seeing the default background of the scene. How can I create the infinite background? Can anybody point me to the right documentation or articles that talk about his issue? Thank you.

推荐答案

类似的内容应该可以帮助您入门:

Something like this should get you started:

添加背景图片...

for (int i = 0; i < 2; i++) {
    SKSpriteNode * bg = [SKSpriteNode spriteNodeWithImageNamed:@"background"];
    bg.anchorPoint = CGPointZero;
    bg.position = CGPointMake(i * bg.size.width, 0);
    bg.name = @"background";
    [self addChild:bg];
}

使用您的更新方法.

[self enumerateChildNodesWithName:@"background" usingBlock: ^(SKNode *node, BOOL *stop) {
    SKSpriteNode *bg = (SKSpriteNode *) node;
    bg.position = CGPointMake(bg.position.x - 5, bg.position.y);

    if (bg.position.x <= -bg.size.width) {
        bg.position = CGPointMake(bg.position.x + bg.size.width * 2, bg.position.y);
    }
}];

这来自 RW 中的示例,他的示例使用了1136 px的背景图像大小.

This is from an example in RW his example used background image size of 1136 px.

这篇关于雪碧套件侧面滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:34