- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我目前正在为 iOS 编写 Cocos2d 游戏。
在这个游戏中,我创建了一个 GameState 单例以保存我的游戏状态(项目详细信息和位置、持续时间、分数等)。
我的主要 CCScene 包含一个 -(void) saveData:
方法,当从正在运行的游戏中调用时(玩家点击 backToMenu 按钮 -> -(void) backToMenu:
),相应地执行:
我们被送回菜单,因为 GameState.sharedState -> PLAYING = true
,出现了一个 Resume 按钮,允许我们继续当前游戏。
到这里为止,它按预期工作。
现在,如何从 appController
的方法 applicationWillEnterBackground
调用方法 -(void) backToMenu:
?
我尝试调用 [[CCDirector sharedDirector] runningScene]
但它以某种方式崩溃,在恢复时也是如此,这意味着我什至不确定我是否保存了正确的内容。
预先感谢您的帮助。
最佳答案
在 AppDelegate.h 中添加:
@class CCLayer;
@interface AppController : NSObject <UIApplicationDelegate, CCDirectorDelegate,UIGestureRecognizerDelegate>
{
CCLayer *mCurrentLayer;
}
@property (nonatomic, retain) CCLayer *currentLayer;
在 AppDelegate.mm 中添加:
@implementation AppController
@synthesize currentLayer = mCurrentLayer;
在你的图层初始化类中使用它。在所有场景方法中。
@implementation MyMainMenu
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
MyMainMenu *layer = [MyMainMenu node];
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
app.currentLayer = layer;
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
你可以在项目的任何地方检查..
在 appDelegate 中
-(void) applicationDidEnterBackground:(UIApplication*)application
{
if([self.currentLayer isKindOfClass:[MyMainMenu class]])
MyMainMenu *mm = (MyMainMenu*) self.currentLayer;
[mm calFunction];
}
在其他类中:
-(void)callUpdateButtonsInLayer
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
if([app.currentLayer isKindOfClass:[MyMainMenu class]])
{
MyMainMenu *mm = (MyMainMenu*) app.currentLayer;
[mm calFunction];
}
}
关于objective-c - 从 AppController 调用正在运行的 CCLayer 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12668545/
在阅读 cocoa 教程时,我注意到一些教程使用 AppDelegate 和一些 AppController 来定义打开各种窗口的 IBActions使用NSWindowController的子类。
如何在 app/app_controller.php 中调用 app_controller.php 中的函数在 app/plugins/media/models/behaviors/transfer.
在很多cakephp中的Acl组件的教程中我得到了在 AppController 或所有其他继承 AppController 的 Controller 中添加组件的指令...... 但问题是 var
我正在尝试按照本教程进行操作: https://angular.github.io/router/getting-started 为什么 AppController.$routeConfig 未定义?
我正在制作一个应用程序,该应用程序生成 JsonObjectRequest 并使用 Android 的 Volley 网络库从 URL 检索 JSON 数据。 AppController.java p
我刚改为使用 Typescript,但我一启动应用程序就收到错误消息。 这是我定义 AppController 的方式: app.controller('appController', AppCont
我正在使用 CakePHP 3。我一直在寻找使我的应用程序模块化的方法,有人建议我使用插件来做到这一点。所以我决定试一试。请看我之前的问题:Modular Directory Structure Wi
我正在尝试呈现错误模板(例如 error400.ctp),但默认布局(站点页眉和页脚)依赖于 AppController 中设置的组件和变量。我如何告诉 Cake 在呈现错误页面时使用 AppCont
我一直想知道为什么我的错误页面导致了我网站的某些页面不渲染,但后来我意识到这是因为 AppError extendsErrorHandler 而不是 AppController。这造成了一些变数我在
AppController 中未检测到 ajax 请求。 我已经打印了 params 数组。这是示例。 CakeRequest Object( [params] => Array
我将 CacheHelper 添加到我的应用程序中。在我的 APP/Config/core.php 中有 Configure::write('Cache.check', true); 在 APP/Co
我在导入 Firebase 时收到此错误“禁用模块时使用‘@import’”。 #import "GameKit/GKLocalPlayer.h" #import "GameKit/GKScore.h
我有一个名为AppController的类,我在 AppDelegate 中有以下方法,当选择菜单项时会调用该方法。 -(IBAction)selectSug:(id) sender { Ap
我使用的是 XCode 4,请注意,在设置新的 Cocoa 应用程序项目时,您会获得一个 AppDelegate.m 和 .h 文件,以及一个 .nib (.xib)。使用 alt-command-r
我正在尝试在 AppController 中对没有关联模型的表运行查询。我不想使用模型,因为这个查询会在每个请求上触发,我想使用模型会让它变慢一点。 我在一个论坛中发现,这可以通过 CakePHP 1
任何人都可以告诉我这个错误的来源是什么。我已经尝试了我在网上找到的所有解决方案,但都无济于事。我刚刚安装了一个 cakePHP 框架,但在 index.cpt 页面上出现了这个错误... 错误: fa
我目前正在为 iOS 编写 Cocos2d 游戏。 在这个游戏中,我创建了一个 GameState 单例以保存我的游戏状态(项目详细信息和位置、持续时间、分数等)。 我的主要 CCScene 包含一个
我正在为一个使用 CakePHP 2.3 的新站点编写单元测试。一切都很顺利,除了一件事。我想测试 beforeFilter() 和 beforeRender() 函数。 beforeFilter()
我想知道是否有可能在 AppController 和我的应用程序的其他 Controller 之间添加另一个抽象 Controller ? 这样我的 Controller ,例如UsersContro
我有一个功能,我希望我的所有 Controller 都能使用,所以我在 AppController 中定义了它。现在这个函数将做的部分事情与 Controller 无关,所以它应该在模型中,但由于这是
我是一名优秀的程序员,十分优秀!