gpt4 book ai didi

ios - Sprite 套件 : How to add scene on top of running scene

转载 作者:行者123 更新时间:2023-12-01 18:16:09 26 4
gpt4 key购买 nike

所以我正在努力将我的 cocos2d 游戏移植到 Sprite Kit。

在 cocos2d 中有两种情况,我会在整个游戏场景中叠加一个菜单。第一种情况是暂停,第二种情况是游戏结束。

在 cocos2d 游戏结束时我做了

CCScene *runningScene = [[CCDirector sharedDirector] runningScene];
WaveEndLayer *waveEndedLayer = [[WaveEndLayer alloc] initWithWon:didWin];
[waveEndedLayer setOpacity:0];
[runningScene addChild:waveEndedLayer z:kZHUD];
CCFadeTo *fadeIn = [CCFadeTo actionWithDuration:0.5 opacity:255];
[waveEndedLayer runAction:fadeIn];

WaveEndLayer 类上有一些 CCMenuItems,cocos2d 负责将触摸事件传递给它们的处理程序。

在 sprite kit 中做这样的事情的正确方法是什么?

我的游戏结束类应该从( SKNodeSKViewSKScene)继承什么?

我尝试使用 SKScene ,但你不能有 2 个正在运行的场景(或者我错了吗?),所以我将小时候的场景添加到主游戏场景中。但是触摸事件仅在主游戏场景中被调用,而不是在游戏结束场景中被调用。所以我尝试了类似的东西
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];

if (_gameOver)
{
[_gameOverScene touchAtLocation:location];
}
}

但是为了简单起见,当我重新启动关卡时,我不会重置所有内容的状态,我只是再次插入游戏场景,它不喜欢它,因为它在技术上仍在运行。

无论如何,覆盖需要触摸事件的菜单的正确方法是什么?

最佳答案

所以我最终使用了一个 SKNode 来结束我的游戏。

我在其init 中将层作为子层添加到我的游戏场景中。方法。

_gameOverLayer = [[GameOverLayer alloc] initWithSize:size];
_gameOverLayer.alpha = 0;
[self addChild:_gameOverLayer];

我的游戏结束方法如下所示:
- (void)gameOver
{
_gameOver = YES;
SKAction *fade = [SKAction fadeInWithDuration:0.5];
[_gameOverLayer runAction:fade];
}

然后我在我的游戏场景中改变了我的触摸方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];

if (_gameOver)
{
[_gameOverLayer touchesEnded:touches withEvent:event];
return;
}
...
}

一切正常,游戏结束出现在正在运行的游戏之上,并且可以获得输入。

关于ios - Sprite 套件 : How to add scene on top of running scene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800975/

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