Best way to zoom and pan a 2D cocos2d iphone game

Chris picture Chris · Oct 15, 2010 · Viewed 7.6k times · Source

What's the best way to implement a pan-able zoomable game map with Cocos2d for iPhone. It would be like Mobile Safari except with a game map that doesn't fit completely on screen. Or like how it's done with Angry Birds, Cut the rope, etc.

This would not be a side scrolling game, just a fixed game area that you can zoom in/out of.

I'm new so if there are tutorials for this that would be great.

Thanks

Answer

KomodoDave picture KomodoDave · Apr 23, 2011

You absolutely should not follow the advice by Joao Caxaria, who seems to have unnecessarily reimplemented the entire UIGestureRecognizer API himself!

You can simply use UIKit's available gesture recognizers and attach them to the sharedDirector's openGLView, as specified in the chosen answer in the link below. These allow for pan, pinch, tap etc. detection. You can even use a UILongPressGestureRecognizer to detect dragging.

cocos2d-iOS - Gesture recognisers