如何应正确看起来简单的游戏架构? [英] How should correctly look the simple game architecture?

查看:147
本文介绍了如何应正确看起来简单的游戏架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我正在试图建立一个游戏的UIKit是由三个MVCS的(现在):主要应用程序委托类(UINavigationController的属性),Menu类(UIViewController的使用XIB文件)和游戏内容类(也与厦门国际银行文件的UIViewController)。显然,游戏需要加载游戏状态的方法,preparing播放,暂停游戏和保存游戏状态。恕我直言,这些方法都属于游戏内容MVC,所以我把它们放在那里。

Currently, I'm trying to build a game with UIkit that consists of the three MVCs (for now): main application delegate class (with UINavigationController property), Menu class (UIViewController with xib file) and game content class (also UIViewController with xib file). Obviously, the game needs methods for loading the game state, preparing to play, pausing the game and saving the game state. IMHO, these methods belong to game content MVC, so I put them there.

现在,一切都清楚了,当这个过程是平的:应用程序启动,导航控制器初始化,菜单弹出,你这是一点击,游戏开始。不过,我想了解如何在游戏程序进入后台或终止处理这种情况。我看到那些漂亮的方法,如applicationDidBecomeActive,applicationWillResignActive,applicationWillTerminate中的主要应用程序委托类文件,我相信我的游戏应用程序架构的设计应在使用游戏preP东西这些方法的一种方式。什么是你的意见,我必须有一个属性(指向游戏内容类)的主要应用程序委托类才能访问游戏preP的方法呢?还是我必须要重新设计我的游戏内容的MVC?

Now, everything is clear when the process is flat: app starts, navigation controller initializes, menu pops, you are making a click, game starts. But I'm trying to understand how to handle the situation when the game app enters the background or terminates. I see those nice methods such as "applicationDidBecomeActive", "applicationWillResignActive", "applicationWillTerminate" in the main app delegate class file, and I believe my game app architecture should be designed in a way that uses those methods for game prep stuff. What is your opinion, do I have to have a property (pointing to game content class) on main app delegate class in order to access game prep methods? Or do I have to redesign my game content mvc?

更新:我的游戏内容类alloc'ed,init'ed并分配给主要的游戏应用程序属性(暂停,保存在applicationWillResignActive,applicationDidBecomeActive ...状态等)。主要的应用程序委托类的方法将处理所有的preparation东西。此外,我的菜单类还分(有产权),以同样的游戏内容对象,因为我有一个新游戏,恢复游戏按钮,在菜单上。现在,我应该如何重新启动游戏从主菜单中选择新游戏按钮?我想删除的游戏内容对象,然后分配/初始化新的。但问题是,如果我松开老分配/从菜单类init'ing新的游戏内容对象(以及分配给菜单类属性),那么我怎么才能通过引用该对象的主要应用程序委托类?我必须有一个指针从我的菜单对象属性app,主要委托对象?我猜的游戏内容应该是那种单身...

Update: My game content class is alloc'ed, init'ed and assigned to the main game app property (for pausing, saving state and etc in applicationWillResignActive, applicationDidBecomeActive...). The main app delegate class methods will handle all the preparation stuff. In addition, my menu class also points (have a property) to the same game content object, because I have a "new game", "resume game" buttons on the menu. Now, how should I restart the game from the main menu "new game" button? I would like to "delete" game content object and then alloc/init the new one. But the problem is, if I'm releasing the old and alloc/init'ing the new game content object from the menu class (and assigning to menu class property) then how can I pass the reference to that object to main app delegate class? Do I have to have a pointer to app main delegate object from my menu object property? I guess the game content should be kind of a singleton...

推荐答案

你在想要使用UIApplicationDelegate信号很正确,这就是他们的东西。例如:

You're quite right in wanting to use the UIApplicationDelegate signals, that's what they're for. For example:

-(void)applicationDidBecomeActive:(UIApplication*)app {
  [my_game resume]; // ...or whatever
}
-(void)applicationWillResignActive:(UIApplication*)app {
  [my_game suspend]; // ...or whatever
}

您应该不需要改变任何东西在你的游戏内容,以适应这种(除非你做的是一个非常糟糕的工作,开始用!)。请务必在初始化 -application游戏内容:didFinishLaunchWithOptions:

You shouldn't need to change anything in your game content to adapt to this (unless you did a really lousy job of it to begin with!). Make sure to initialise the game content in -application:didFinishLaunchWithOptions:.

这篇关于如何应正确看起来简单的游戏架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆