summary refs log tree commit diff stats
path: root/Classes/CocosOverlayScrollView.m
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-08-23 07:52:24 -0400
committerStarla Insigna <starla4444@gmail.com>2011-08-23 07:52:24 -0400
commitc9337218ef1660360097928c753bde1c79775618 (patch)
tree3cd6f9926cbe092c98776673800b830eef27ca01 /Classes/CocosOverlayScrollView.m
parent2ac50443ddbf69b7594808ba4e6de49eecbc0b84 (diff)
downloadcartcollect-c9337218ef1660360097928c753bde1c79775618.tar.gz
cartcollect-c9337218ef1660360097928c753bde1c79775618.tar.bz2
cartcollect-c9337218ef1660360097928c753bde1c79775618.zip
Added scrolling to level selection screen
Using http://www.xcombinator.com/2010/09/08/a-paging-uiscrollview-in-cocos2d-with-previews/ as a base, I was able to implement a paging scroller for the level selection screen so players can swipe through available levels and choose one to play.

At this point, the level selection screen is practically done--the only other thing I want to add is a UIPageControl to interact with the scrolling and give the player an indication of how many levels there are.

Refs #207
Diffstat (limited to 'Classes/CocosOverlayScrollView.m')
-rwxr-xr-xClasses/CocosOverlayScrollView.m99
1 files changed, 99 insertions, 0 deletions
diff --git a/Classes/CocosOverlayScrollView.m b/Classes/CocosOverlayScrollView.m new file mode 100755 index 0000000..dcf5571 --- /dev/null +++ b/Classes/CocosOverlayScrollView.m
@@ -0,0 +1,99 @@
1//
2// CocosOverlayScrollView.m
3// shapes
4//
5// Created by Nate Murray on 8/23/10.
6// Copyright 2010 LittleHiccup. All rights reserved.
7//
8
9#import "CocosOverlayScrollView.h"
10
11@implementation CocosOverlayScrollView
12@synthesize targetLayer;
13
14// Configure your favorite UIScrollView options here
15-(id) initWithFrame: (CGRect) frameRect numPages: (int) numPages width: (float) width layer: (CCNode*) layer {
16 if ((self = [super initWithFrame: frameRect])){
17 self.contentSize = CGSizeMake(width*numPages, 320);
18 self.bounces = YES;
19 self.delaysContentTouches = NO;
20 self.delegate = self;
21 self.pagingEnabled = YES;
22 self.scrollsToTop = NO;
23 self.showsVerticalScrollIndicator = NO;
24 self.showsHorizontalScrollIndicator = NO;
25 [self setUserInteractionEnabled:TRUE];
26 [self setScrollEnabled:TRUE];
27 self.targetLayer = layer;
28 // self.canCancelContentTouches = YES;
29 }
30 return self;
31}
32
33-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
34{
35 if (!self.dragging)
36 {
37 // UITouch* touch = [[touches allObjects] objectAtIndex:0];
38 // CGPoint location = [touch locationInView: [[touch view] superview]];
39 // CCLOG(@"touch at l.x:%f l.y:%f", location.x, location.y);
40
41 [self.nextResponder touchesBegan: touches withEvent:event];
42 [[[CCDirector sharedDirector] openGLView] touchesBegan:touches withEvent:event];
43 }
44
45 [super touchesBegan: touches withEvent: event];
46}
47
48-(void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
49{
50 if (!self.dragging)
51 {
52 [self.nextResponder touchesEnded: touches withEvent:event];
53 [[[CCDirector sharedDirector] openGLView] touchesEnded:touches withEvent:event];
54 }
55
56 [super touchesEnded: touches withEvent: event];
57}
58
59-(void) touchesCancelled: (NSSet *) touches withEvent: (UIEvent *) event
60{
61 // if (!self.dragging)
62 // {
63 // CCLOG(@"CocosOverlayScrollView touchesEnded not dragging");
64 [self.nextResponder touchesCancelled: touches withEvent:event];
65 [[[CCDirector sharedDirector] openGLView] touchesCancelled:touches withEvent:event];
66 // }
67 [super touchesCancelled: touches withEvent: event];
68}
69
70
71- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
72{
73 // TODO - Custom code for handling deceleration of the scroll view
74}
75
76- (void)scrollViewDidScroll:(UIScrollView *)scrollView
77{
78 CGPoint dragPt = [scrollView contentOffset];
79 dragPt = [[CCDirector sharedDirector] convertToGL:dragPt];
80
81 dragPt.y = dragPt.y * -1;
82 dragPt.x = dragPt.x * -1;
83
84 CGPoint newLayerPosition = CGPointMake(dragPt.x, dragPt.y);
85
86 [targetLayer setPosition:newLayerPosition];
87}
88
89- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
90{
91 // CGPoint dragPt = [scrollView contentOffset];
92 // etc.
93}
94
95-(void) dealloc {
96 self.targetLayer = nil;
97 [super dealloc];
98}
99@end \ No newline at end of file