2012-04-12 59 views
2

就我而言,我正在制作一款2D游戏,相机总是会跟随我的角色,但会有场景限制,所以当他几乎在场景边界附近时,我不得不停止跟随他。我也必须处理相机的比例,所以我必须决定是否使用CCFollow :: actionWithTarget()或CCCamera。为什么我们更喜欢在cocos2d中使用“CCFollow”而不是“CCCamera”?

在CCCamera.h它说:

限制:

- 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游戏中使用它。

+0

你有没有找到合适的人来澄清这一点?我有类似的疑问,并且很高兴知道你是否解决了这些疑虑。 – mm24 2012-10-29 09:24:12

回答

2

如果你注意到,在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

相关问题