Spritekit:如何使游戏屏幕视图随着节点“跳跃"而向上移动沿着y轴? [英] Spritekit: how to make game screen view move upwards as node "jumps" along the y axis?

查看:73
本文介绍了Spritekit:如何使游戏屏幕视图随着节点“跳跃"而向上移动沿着y轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以发布一个示例代码,说明当我的玩家节点跳跃"到 y 轴时如何让我的游戏屏幕向上移动.和涂鸦跳跃一样吗?目前它显然只是直接从屏幕顶部跳出来.

could someone please post an example code of how i could make my game screen move up as my player node "jumps" up the y axis. the same as doodle jump? at the moment it obviously just jumps straight out of the top of the screen.

任何帮助让我的平台"节点从父节点中移除自己,然后在我向上移动屏幕时它们离开视图底部时重新出现也会有所帮助.

any help with making my "platform" nodes remove themselves from the parent and then reapear when they go out the bottom of the view as i move up the screen would help aswell.

最后一件事,我如何向初始视图添加多个节点.[自己添加孩子:节点]只做一个.

and one last thing, how do i add more than one node to the initial view. [self add child:node] only makes one.

我知道这些可能是业余问题,那是因为我是业余的.

i know these are probably amateur questions, and thats because I'm an amateur.

推荐答案

Pieter 的回答可能是最有帮助的,但我会尽量回答您提出的第二和第三个问题,因为 sangony 涵盖了第一个问题.

Pieter's answer is probably going to be the most help, but I'll try to answer the second and third questions you asked, since sangony covered the first.

要移除掉屏幕的平台,在实例化平台节点时使用node.name = @"platform";,然后在update方法中检查它们相对于worldNode的当前位置,像这样:

To remove platforms that have fallen off the screen, use node.name = @"platform"; when instantiating the platform nodes, and then check their current positions relative to the worldNode in the update method, like this:

-(void)update:(NSTimeInterval)currentTime
{
    [self enumerateChildNodesWithName:@"platform" usingBlock:^(SKNode *node, BOOL *stop) {
        if(node.position.y < _worldNode.position.y-(self.size.height/2))
            [node removeFromParent];
    }];
}

要将多个节点添加到场景中,您必须在多个节点上多次使用 [self addChild:node];,或者手动实例化每个节点,或者迭代地设置它们.如果您希望平台具有相当统一的模式,那么 for 循环可能是完成此任务的正确方法.您还可以通过将从屏幕底部掉落的节点移到屏幕顶部,而不是将它们完全移除,从而以更少的节点总数来完成此操作.

To add multiple nodes to the scene, you have to use [self addChild:node]; multiple times, on multiple nodes, either instantiating each node manually, or setting them up iteratively. If you want the platforms in fairly uniform patterns, a for loop is probably the right way to get this done. You could also get this done with fewer total nodes by moving the ones that have fallen off the bottom of the screen up to just off the top of the screen, instead of removing them entirely.

这篇关于Spritekit:如何使游戏屏幕视图随着节点“跳跃"而向上移动沿着y轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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