2012-04-12 29 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

相關問題