我应该继承 CCSprite、CCNode 还是 NSObject? [英] Should I subclass CCSprite, CCNode, or NSObject?

查看:14
本文介绍了我应该继承 CCSprite、CCNode 还是 NSObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到某些文本似乎总是从 CCSprite 子类化.我在某处读到这样做不好,最好从基本的东西开始.我想了解职业游戏开发者在游戏结构方面做了什么.即子类 CCSprite 或在 NSObject 类 ETC 中添加 CCSprite.

I see that certain texts always seem to subclass CCSprite. I read somewhere that it is not good to do that and that it is better to start with something basic. I wanted to find out what the pro game developers do in terms of game structure. That is subclass CCSprite or add CCSprite in a NSObject class ETC.

我希望我的问题有意义.

I hope my question makes sense.

推荐答案

你的问题绝对有道理.

这基本上是一个架构问题.如果您的游戏主要基于动画",我会选择 CCSprite 的子类.如果您的游戏主要基于某种逻辑,可能是 RPG 或其他任何东西,那么屏幕表示实际上只是游戏状态的可能视图之一.因此,在我看来,它应该是代表游戏状态的对象树中的对象的一部分.

It's fundamentaly an architecture question. If your game is mainly based on "animation", I'd go for subclassing CCSprite. If your game is mainly based on some logic, maybe a RPG or whatever else, then the screen representation is in fact just one of the possible views of the game state. Therefore, it should be, in my opinion, part of an object in the tree of objects that represents your game state.

换句话说:如果你的游戏状态本质上是一个场景,那么子类 CCSprite,因为 Cocos2D 在管理场景方面可能比你好得多.如果您的游戏状态是其他",您可能应该考虑构建您自己的该状态表示,并使您的精灵成为游戏对象的一部分.如果您决定更改渲染,这也将允许您切换"图形引擎.例如,您可能正在 Cocos2D 中使用 2D 表示形式制作 RPG.过了一会儿,你把你的演示展示给育碧,他们爱上了它,并给你 2000 万美元来完成它,但他们要求 3D 渲染.如果你想继承 CCSprite,你必须重做所有的游戏.如果您打算将 CCSprite/CCNode 集成到 NSObject 派生类中,那么您就可以开始了.

In other words: if your game state is essentially a scene, then subclass CCSprite, because Cocos2D is probably way better than you at managing scenes. If your game state is "something else", you probably should consider building your own representation of that state, and make your sprite part of your game object. This will also allow you to "switch" graphics engines if you decide to change rendering. For example, you might be doing a RPG with a 2D representation in Cocos2D. After a while, you show your demo to Ubisoft and they fall in love with it and give you 20 million dollars to finish it, but they request a 3D rendering. If you went for subclassing CCSprite, you have to redo all the game. If you went for integrating the CCSprite/CCNode in a NSObject-derived class, you're good to go.

当然,这个例子有点夸张了……例子:D

Of course, that example is slightly exaggerated for the purpose of ... example :D

这篇关于我应该继承 CCSprite、CCNode 还是 NSObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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