我应该子类CCSprite,CCNode或NSObject? [英] Should I subclass CCSprite, CCNode, or NSObject?

查看:86
本文介绍了我应该子类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.

推荐答案

你的问题肯定是有道理的。

Your question definitely 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。过一会儿,你向Ubisoft展示你的演示,他们爱上它,给你20万美元完成它,但他们要求一个3D渲染。如果你去子类化CCSprite,你必须重做所有的游戏。如果你想在一个NSObject派生类中集成CCSprite / CCNode,你很好。

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天全站免登陆