精灵套件侧滚动 [英] Sprite kit side scrolling

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

问题描述

我开始使用 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 像素大小的背景图像.

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆