我构建了一个战舰游戏,其中玩家和计算机轮流以 10X10 网格发射炸弹。
我正在为 iphone 使用 cocos2d 2.0。
我有两个场景,PlayerScene
和 AIScene
。
在 Playerscene.m 中,我使用
[[CCDirector sharedDirector] replaceScene:[CCTransitionSlideInR transitionWithDuration:1.0 scene:[AIScene sceneWithPositions:otherpos andHits:otherhits andOtherPositions: rects andOtherHits: prev]]];
在玩家选择位置后前进到 AIScene。
这很好用。
但是,在AIScene中,我使用了一个
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[CombatScene sceneWithParameters:OtherPositions andHits:OtherHits andOtherPositions: Positions andOtherHits: Hits]]];
要返回,这是行不通的。比赛仍在 AIScene 进行。
但是,我可以触摸屏幕,游戏会向我闪烁 PlayerScene
和我刚刚放置的炸弹,然后返回到 AIScene
。
怎么了?
最新信息:我在 AIscene 中添加了一个按钮来触发 replaceScene 事件并且它起作用了。但是,如果我将它添加到 onEnter() 方法的末尾,它就不起作用。
最佳答案
您不能在 onEnter 方法(也不是 init 方法)中替换场景。换句话说,您不能从当前仍在替换另一个场景的场景中调用 replaceScene。
您可以安排一次选择器,然后从安排的选择器调用 replaceScene。只有在场景被替换后,替换才会发生。
关于ios - Cocos2d游戏两个场景之间的ReplaceScene,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18827728/