I have created a UIScrollView in a cocos2d application. I am adding sprites dynamically, over 3 pages. On the first page, touch works perfectly on a sprite, however if I use the scroll view and navigate to the second page, touch does not work quite right... the sprite will respond to the touch when I touch the screen, approximately the amount I have scrolled to the left. If I scroll back to the first page, touch works perfectly for a sprite. Any ideas? I am using the following tutorial: http://getsetgames.com/2009/08/21/cocos2d-and-uiscrollview/ :)
A:
I think some code might be useful:-
I am using the exact code from your demo...
CocosOverlayScrollView and CocosOverlayViewController
I am creating the CocosOverlayViewController in my layer:-
CocosOverlayViewController *scrollView = [CocosOverlayViewController alloc];
[[[Director sharedDirector] openGLView] addSubview:scrollView.view];
I am creating the layer in my scene:-
Scene *scene = [Scene node];
GridLayer *layer = [GridLayer node];
[scene addChild: layer z:-1];
[scene setTag:12];
I am creating the sprites in my layer:-
myImage.position = ccp(53 * (coordinate.x + 0.52), 57 * (coordinate.y + 1.45));
[myImage runAction:[FadeIn actionWithDuration:0.3]];
myImage.relativeAnchorPoint = YES;
[self addChild:myImage z:-1];
The sprite is using the TouchesDispatcher and the touches are resolved in the class.
If I use the cocos2d moveto function on the layer I can touch a sprite and it responds so I know it works, things just get a little odd when I use the UIScrollView.
I hope you understand my problem and can help, all the best :)
Carl
Carl
2010-03-17 22:24:18