就我而言,我正在制作一款 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 为你做的)。如果您仍然想使用相机,这里的答案可能会有所帮助:
关于c++ - 为什么在cocos2d中我们更喜欢使用 "CCFollow"而不是 "CCCamera"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10118766/