Split Screen Problem

Hello, I am trying to write some code to display a game of mine with a split screen that'll show each player. My idea was to write a piece of code in the paintComponent method that sets the origin of the graphics component to the correct place so that the first player (indexed 0) will be shown at the left half of the screen and the second player (indexed 1) will be shown at the right half of the screen. My code is similar to:

for (int i=0; i<players.size(); i++){

Player p = players.get(i);

int xMin=Math.min(Math.max(p.x-cameraWidth/2,0),width-cameraWidth);

int yMin=Math.min(Math.max(p.y-cameraHeight/2,0),height-cameraHeight);

g.setClip(cameraWidth*i,0,cameraWidth,cameraHeight);

//Making sure only the player's half will be painted this time!

g.translate(xMin-cameraWidth*i,yMin);//Moving the origin

paintStuff();//Here goes some irrelevant code that paints the actual map

g.translate(cameraWidth*i-xMin,-yMin);//Restoring the Origin

}

The problem is that when I wanted the areas from 0 to cameraWidth, for example, to be painted on the right side of the screen, I set the origin to minus cameraWidth so that the first half of the screen would not have anything to paint but this seems not to work. Am I getting something wrong?

With Thanks,

laginimaineb.>

[1670 byte] By [laginimaineba] at [2007-11-27 1:01:16]
# 1

I figured it out. Here is the corrected code if anybody needs it:

for (int i=0; i<players.size(); i++) {

Player p = players.get(i);

int xMin=Math.min(Math.max(p.x-cameraWidth/2,0),width-cameraWidth);

int yMin=Math.min(Math.max(p.y-cameraHeight/2,0),height-cameraHeight);

g.setClip(cameraWidth*i,0,cameraWidth,cameraHeight);

//Making sure only the player's half will be painted this time!

g.translate(-xMin+cameraWidth*i,-yMin); //Moving the origin

paintStuff(); //Here goes some irrelevant code that paints the actual map

g.translate(-cameraWidth*i+xMin,+yMin); //Restoring the Origin

}

>

laginimaineba at 2007-7-11 23:36:08 > top of Java-index,Other Topics,Java Game Development...