Cocos2d: dividing screen into 2 scenes

Go To StackoverFlow.com

0

Hi so I'm designing an iPhone application which requires 3 seperate scenes, one on the top, one in the middle (main) and one on the bottom which will hide and unhide according to user actions.

This is a requirement because I need the middle (main) scene to change upon a swipe gesture and the top/bottom scene to remain unchanged.

How can I do this?

PS:

I've looked the few questions/solutions and none give a straight-forward answer. I just need some real help, if that's alright!

2012-04-04 21:53
by steve
you mean layers..not scene...right? if you mean scene..be more specific about the layout of your scenes..the question is unclea - skytz 2012-04-04 22:04
Well from what I understand, layers are created but implemented into the application as scenes by adding the CCLayer object to the CCScene object prior to going with that scene. Basically I need the screen in 3 sections, allowing 1 to be changed without the other 2 being changed at all. How can I do this in cocos2d is my question I guess. Thanks for the comment - steve 2012-04-04 22:14
yea..but you can create different size layers and more than 1 per scene..and arrange them in whatever order you want (even outside of the screen - skytz 2012-04-04 22:16
Yeah I know, but can I switch a layer within the scene without affecting the other layers AT ALL, not even reloading identical layers - steve 2012-04-04 22:30
of course you can...just remove the layer..and add a new layer at the same positio - skytz 2012-04-04 22:32
Oh, you see I never considered that to be an option. Could I have transitions on the changing layer too - steve 2012-04-04 22:35
transitions as..scene transitions..i dont think so..but you can use CCMoveTo again.I mean..make the new layer outside the screen and move it to the left (lets say) at the same time the layer on the screen moves outside. You can use fadein, fadeout and whatever you can think of...its just a tric - skytz 2012-04-04 22:38


1

well..easiest way i can think of is to make 3 layers in the same screen..and position them as you want

its easy enough to create a layer,

to change it's size just use [ <layer> setContentSize:...] , to change it's position: <layer>.position=....

and to detect which layer is touched:

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{
  CGPoint location = [self convertTouchToNodeSpace: touch];
if (CGRectContainsPoint(<layer1>.boundingBox, location))
{
  CCLog(@"touched 1st layer");
  return YES;
}
if (CGRectContainsPoint(<layer2>.boundingBox, location))
{
  CCLog(@"touched 2nd layer");
  return YES;
}
 return NO;
}

also...for the 3rd layer just use CCMoveTo to move the layer on and off the screen

2012-04-04 22:29
by skytz
Thank you! I have created prototype applications which feature multiple layers per scene. But with this approach, can I change one of the layers without affecting the other 2 layers at all? Thanks very much for your reply btw. : - steve 2012-04-04 22:32


0

Try it. may it should be helpful to you.

 -(void) registerWithTouchDispatcher
 {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
  }
2012-04-10 05:43
by Ayaz
Ads