This project shows how to create a paged UIScrollView with Previews in Cocos2D. It looks like this (video)
Apple's UIScrollView paging doesn't support an arbitrary width argument. If you make a UIScrollView with a width smaller than the whole screen, then that view won't capture touches outside of that area.
Additionally, we are mixing Cocoa views and Cocos2d/OpenGL, and how they interact is not always obvious.
We create a subclass of CCMenu
and add panels as items. The CCMenu
is scrolled
as the UIScrollView
is scrolled. The UIScrollView
is set to be smaller than
the whole screen: this gives us previews on either side of the current page.
We create a full-screen TouchDelegatingView
under the UIScrollView
and use
that to delegate touches that lie outside the UIScrollView
.
There are a few custom classes mixed in, but that is the basic idea.
This project uses cocos2d as a referenced project. You can see that in
Project > Edit Project Settings > User Header Search Paths
we have the environment variable $(COCOS2D_SRC)
. You set up this variable in:
Xcode > Preferences > Source Trees
Then hit the plus '+' and add a variable COCOS2D_SRC
to point to your cocos2d installation.
Written by Nate Murray for Jacob's Shapes, an iPhone game for toddlers.
It uses ideas and code from the following sites:
- http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/
- http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html
2010-09-17 - fixed how ios 4.1 deals with canceling touches