Skip to content

Commit

Permalink
Added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jashmenn committed Sep 8, 2010
1 parent 51fb069 commit 8b5989b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Classes/Scenes/HCUPPanelScene.h
Expand Up @@ -19,7 +19,7 @@
int nextWorld_;
BOOL transitioning_;
CocosOverlayScrollView* scrollView;
TouchDelegatingView* scrollViewContainer;
TouchDelegatingView* touchDelegatingView;
UIPageControl* pageControl;
}

Expand Down
23 changes: 11 additions & 12 deletions Classes/Scenes/HCUPPanelScene.m
@@ -1,20 +1,19 @@
/*
* HSLevelSelectionScene2.m
* shapes
* HCUPPanelScene.m
* Jacob's Shapes
*
* Created by Nate Murray on 7/24/10.
* Copyright 2010 YetiApps. All rights reserved.
* Copyright 2010 LittleHiccup. All rights reserved.
*
* Huge thanks to the the authors of following urls:
* http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/
* http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html
*/

#include "HCUPPanelScene.h"
#import "NMPanelMenu.h"
#import "NMPanelMenuItem.h"
#import "TouchDelegatingView.h"

// http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/
// http://blog.proculo.de/archives/180-Paging-enabled-UIScrollView-With-Previews.html

@implementation HCUPPanelScene

+(id) scene
Expand Down Expand Up @@ -115,24 +114,24 @@ - (void) onEnter
//
// Note that we're only concerned with a horizontal iPhone. If your game is
// vertical, change accordingly
scrollViewContainer = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
touchDelegatingView = [[TouchDelegatingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView = [[CocosOverlayScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, totalPanelWidth)
numPages: numberOfPages
width: totalPanelWidth
layer: panels];
scrollViewContainer.scrollView = scrollView;
touchDelegatingView.scrollView = scrollView;

// this is just to pre-set the scroll view to a particular panel
[scrollView setContentOffset: CGPointMake(0, currentWorldOffset * totalPanelWidth) animated: NO];

// Add views to cocos2d
// We called it a TouchDelegatingView, but it actually isn't containing anything at all.
// In reality it is just taking up any space under our ScrollView and delegating the touches.
[[[CCDirector sharedDirector] openGLView] addSubview:scrollViewContainer];
[[[CCDirector sharedDirector] openGLView] addSubview:touchDelegatingView];
[[[CCDirector sharedDirector] openGLView] addSubview:scrollView];

[scrollView release];
[scrollViewContainer release];
[touchDelegatingView release];

[super onEnter];
}
Expand All @@ -158,7 +157,7 @@ - (void) visit {
- (void) onExit
{
[scrollView removeFromSuperview];
[scrollViewContainer removeFromSuperview];
[touchDelegatingView removeFromSuperview];
[super onExit];
}

Expand Down
39 changes: 39 additions & 0 deletions README.mkd
@@ -0,0 +1,39 @@
# Paging UIScrollView with Previews in Cocos2D

This project shows how to create a paged UIScrollView with Previews
in Cocos2D. It looks like this:

!Resources/iphone-preview.jpg!

[Watch the video!](youtube).

# The Problem

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.

# Basic Idea

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.

# Credits

Written by Nate Murray for [Jacob's Shapes](http://www.littlehiccup.com), 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


Binary file added Resources/iphone-preview.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b5989b

Please sign in to comment.