2

I'm tring to synchronize cocos2D layer objects with the map, I managed to get it working by adjusting the glView to the visibleMapRect of the MKMapView. I can zoom, move, my objects are following the map. But, there is a small and annoying lag between the MKMapView and the cocos2D Layer.

I'm synchronizing it at each display loop.

Method:

1) Retrieve the MKMapView.visibleMapRect

2) Set the glViewPort

3) Do an orthographic projection to adjust my layer to the MapView.

I already tried others methods, like moving the cocos2D layer with touch and then move the coordinates of my map according to the touch, still laggy.

Even disabling acceleration and deceleration of the MapView doesn't remove the lag.

Thanks.

iMart1n
  • 21
  • 1

1 Answers1

0

Shot in the dark: we know that iOS devices use optimizations to speed up rendering while scaling. This is true for Safari browser, when you zoom in you actually only zoom in on the image that is currently being displayed as the browser window's contents. Only after you stop the pinch motion does the device update the view.

You'll see this specifically with text on older devices. When the device re-renders the contents with the new scale factor, the text suddenly becomes sharp and crisp again. I believe the same optimization is done in MKMapView.

You might want to check if the visibleMapRect values are actually updated during the zoom, and whether they accurately reflect the current zoom level or not.

The other issue I can imagine is that the framerate with MKMapView + Cocos2D is simply low. And specifically zooming might consume a lot of CPU power. You might want to enable the cocos2d FPS display to see what the framerate is.

Another trick that's necessary to allow smooth scrolling of views in cocos2d (particularly complex views like UITableView) is to reduce cocos2d's max framerate (animationInterval) and/or to run the rendering of the gl view on a separate thread. Your issue may simply be a variation of this issue: UIScrollView pauses NSTimer until scrolling finishes

Note that this also occurs with DisplayLink director. The info in this question did the trick for me.

Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thanks, I'm already in another thread. I'm trying to investigate other solutions such as tile mapping and others things. – iMart1n Aug 14 '12 at 07:18