c++ - 为什么在cocos2d中我们更喜欢使用 "CCFollow"而不是 "CCCamera"?

标签 c++ ios cocos2d-iphone

就我而言,我正在制作一款 2D 游戏,摄像机始终跟随我的角色,但会有场景限制,因此当他接近场景边界时我必须停止跟随他。我还必须处理相机比例,因此我必须决定是使用 CCFollow::actionWithTarget() 还是 CCCamera。

在 CCCamera.h 中它说:

Limitations:

- Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors)
using the camera.

- It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object.

- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate.

最后一句很有趣,为什么只在3D效果中使用它?看来 CCCamera 的生产商不推荐。我知道这是处理相机运动的捷径,但我只是不知道为什么最好不要在 2D 游戏中使用它。

最佳答案

如果您注意到,CCCamera.h 文件还显示:

Useful to look at the object from different views.
The OpenGL gluLookAt() function is used to locate the
camera.

OpenGL 红皮书中有一篇很好的文章介绍了相机的工作原理。我的理解是,相机的目的是设置初始方向,然后你通过更新模型矩阵来移动世界(我猜这就是 CCFollow 为你做的)。如果您仍然想使用相机,这里的答案可能会有所帮助:

moving CCCamera

关于c++ - 为什么在cocos2d中我们更喜欢使用 "CCFollow"而不是 "CCCamera"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118766/

相关文章:

c++ - 如何修改运行时加载的 DLL 的导入地址表

ios - 如何将就地编辑的内容传回之前的tableview controller(更新model)

ios - 我的 CCScene 行为异常?

c++ - 如何将整数数组转换为 SIMD vector

c++ - 是否需要为 C/C++ 中的文件 I/O 操作创建自己的缓冲区?

ios - NSDate 会根据设备的当前位置发生变化吗?还是独立的?

ios - SwiftUI TextEditor 初始内容大小错误

iphone - CClayer (cocos2d + box2d) 缩放/缩放问题

iphone - UITableView 和 UIScrollview 停止 cocos2d 动画

c++ - 如何设置c++应用程序窗口的图标和任务栏的图标?