如何检测用户最后一个场景?
-
10-10-2019 - |
题
我正在使用cocos2d,我想知道如何在用户按下按钮从我的pauselayer场景中访问我的设置场景之前,如何检测用户的最后一个场景。我需要知道,因为有2种以上的方法可以访问设置场景,因此我需要一个特殊的后退按钮才能返回用户持续的任何场景。另外,我可以有1个返回按钮可以返回最后一个场景的方法,而不是任何特定的场景。我该怎么做?
解决方案
编辑:根据您的代码样本,我建议以下内容,由于我缺乏测试设备:p。
首先,将方法添加到您的设置类中,称为 +(id)nodefromsource :( bool)bpausemenu。
+(id)nodeFromSource:(bool)bPauseMenu
{
if((self = [self node])
{
m_bPauseMenu = bPauseMenu;
}
return self;
}
添加bool m_bpausemenu;在类定义中。
在您在设置中为返回按钮分配的功能中,实现以下代码:
//for example...
-(void)backButtonPressed:(id)sender
{
if(m_bPauseMenu)
{
[[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:1.2f scene:[pauseLayer node]]];
}
else
{
//trigger a replaceScene back to the other menu here
//(MyOtherLayer is the classname of your non-pause-menu layer that you came from...
[[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:1.2f scene:[MyOtherLayer node]]];
}
}
更改pauselayer中的呼叫 - (void)设置:(id)发件人到:
[[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:1.2f scene:[Settings nodeFromSource:true]]];
无论您的其他呼叫以显示设置层的呼叫,请说:
[[CCDirector sharedDirector] replaceScene:[CCTransitionFlipAngular transitionWithDuration:1.2f scene:[Settings nodeFromSource:false]]];
我称其为节点的原因是,有一天您可以用某种参考来代替布尔,并允许您的层了解它们来自的层。
我希望这能做。我已经过了几次,看不到任何明显的错误...
不隶属于 StackOverflow