ios - Cocos2d游戏两个场景之间的ReplaceScene

标签 ios cocos2d-iphone

我构建了一个战舰游戏,其中玩家和计算机轮流以 10X10 网格发射炸弹。

我正在为 iphone 使用 cocos2d 2.0。

我有两个场景,PlayerSceneAIScene

在 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/

相关文章:

ios - 如何使用 FQL 从群组中获取群组管理员的帖子

ios - 在 Swift 的 NSObject 子类的初始化器中调用 super.init()

iphone - Cocos2d removeChild 不工作

iphone - 如何通过parentviewcontroller将数据从一个 View 传递到另一个 View

ios - iAd 的 URL 结构

ios - Admob bannerView 请求错误 : No ad to show

ios - 在 Cocos2D 3.0 中可以删除的情况下检查 CCNode 是否有父节点

objective-c - 仅在特定设备上部署 iOS

iphone - 用于 iPhone 游戏开发的 Cocos2d 中的图层与场景

ios - 未知类型名称 UIBezierPath