Move camera with finger drag

Hi,

i’m pretty used to move a camera in opengl setting glOrtho every frame the camera is different than the last.
How is this behavior usually implemented in cocos2dx or cocos2d?

The idea would be to me able to move the camera dragging the finger on the screen.

Thanks!

Hi,

It is implemented in a cocos2d moving layer, is method setPosition (only 2d)
Everyone offset occurring by calling glTranslatef(is openGL method)
You can look at examples of cocos2d / test / parallax.
Look at parallax.

I thought glTranslate was not valid/usable in opengl es 2.0

Parallax nodes work correctly with this method, right? (cannot test it right now as i’m not at home)
If i assume that initial camera position (center of the screen) is 0, 0 moving it to 100, 100 would mean moving the layer ~~100,~~100?

I guess it makes sense. I’ve been trying to avoid moving all objects for faking camera movement as i’m using box2d and it doesn’t behave as well if you start teleporting things around :stuck_out_tongue:

Thanks a lot

No need to move everyone objects, you need only move the main display layer.
In boks2d in debug mode will be displayed incorrectly because the physical world at notchanges moved layer
(change the position of physical objects is a bad idea)

As box2d will see the same coordinates there won’t be a problem.

Thanks