Best method for multiplayer split-screen

Forums Programming cocos2d support (graphics engine) Best method for multiplayer split-screen

This topic contains 3 replies, has 3 voices, and was last updated by  araker 2 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
June 29, 2011 at 12:37 pm #232768

jtrubridge
Participant
@jtrubridge

Hi all,

I am currently making an iPad platform game using Cocos2d and are planning on including multiplayer split-screen. I have done some initial work creating multiple layers, scaling them down and rotating them. This works fine except it is a bit of a pain having to put everything I create in the two layers. i.e. If I want a sprite in the ‘world’, I then need to add it to both players layers, the same for particle effects, tilemaps etc…

Is there a better way to do this?

I would have thought that I could have one layer (my world) and then have two separate views of it using different viewports. Unfortunately OpenGL knowledge isn’t great and I’m not too sure how best to do this using Cocos2d? Has anybody done this before and got a tutorial or any sample code? I’ve searched google but haven’t been able to find anything that useful.

Thanks in advance

James

July 26, 2011 at 5:21 pm #336254

tsaintthomas
Participant
@tsaintthomas

I’ve also done the same (each “game” is on a rotated/scaled layer) and I am wondering if there is a more efficient way as well.

July 26, 2011 at 6:44 pm #336255

jtrubridge
Participant
@jtrubridge

I’ve changed the way I’m doing it now. I’ve overridden the visit function for the layer to setup two viewports of the same layer and rendering it twice (once into each view port). Between each render ([super visit]) I adjust the position of the layer because that’s how I’m doing the camera.

-(void) visit
{
glPushMatrix();

// Setup the top viewport
glViewport (0, 0, clippingRegion.size.width/2, clippingRegion.size.height);

glRotatef(180.0f,0.0f,0.0f,1.0f);
glTranslatef(-clippingRegion.size.height,-clippingRegion.size.width,0.0f);

self.position = [self viewportCameraPos:0]; // Get the position of the layer for the 1st camera view
[super visit];

glPopMatrix();

glPushMatrix();

// Setup the bottom viewport
glViewport (clippingRegion.size.width/2, 0, clippingRegion.size.width/2, clippingRegion.size.height);

self.position = [self viewportCameraPos:1]; // Get the position of the layer for the 2nd camera view
[super visit];

// Return to the full-screen viewport
glViewport (0, 0, clippingRegion.size.width, clippingRegion.size.height);

glPopMatrix();
}

July 26, 2011 at 6:44 pm #336256

araker
Moderator
@araker

You can use glViewPort for creating multiple views. Edit I see jtrubridge posted a fine snippet.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.