background preloader

Games

Facebook Twitter

Gameplay - free 3D game engine. Cocos2d-x. Cocos2d-x - CCScrollView - Semi Paging. Unlike UIScrollView in iOS, there is no paging in CCScrollView, and this would be inconvenient for those who want to make a stage selection scene like Angry Birds. There are different approaches to achieve the scrolling, or the effect of scrolling.

The first one is the false scrolling, by placing buttons on both the left and right of the screens, which users can tap the buttons to navigate the pages. However users cannot scroll by dragging, which is a more direct reaction when people want to scroll. The second one is to show up a native scroll view(iOS: UIScrollView - Android: ScrollView) on top of a CCLayer. The third one is to modify the code of CCScrollView a bit to achieve the paging functionality. To have paging we need to provide the page size, and also tell the scroll view whether to have the paging effect or not. When scrolling ends CCScrollView would call relocateContainer, therefore we would have our paging code there.

How to use pthread | Cocos2d-x. Now, you can use pthread in cocos2d-x, but there are some limitations. Don’t call any functions which invokes Ref::retain(), Ref::release() or Ref::autorelease(), because AutoreleasePool are not thread-safe. Please refer to Reference Count and AutoReleasePool in Cocos2d-x for more details. Cocos2d-x use AutoreleasePool every where in its framework, so my suggestion is that, don’t invoke any cocos2d-x API in a new thread except Data Structures.If you want to load resources in a new thread, you can use TextureCache::addImageAsync()pthread_cond_wait() seems have a bug, it can not wait at the first time, but works properly in subsequence.

If we make retain(), release() and autorealese() thread-safe, then mutex would be required. For the reason that cocos2d-x framework releases the autorelease pool at each end of message loop, using mutex may cause performance issue. By the way, OpenGL context is not thread-safe, which you should always keep in mind. Spine: 2D skeletal animation for games. SpiderMonkey - Mozilla.