I hope this is the correct place to post this, but I have been having some issues. I am new to this site and to python/pygame so please humor me.
My game is suppose to have a four way split screen so that four players can compete against each other at once. The way I went about creating this is by making an "action_surface" that acts as the main canvas and four subsurface's that are positioned into four quadrants. As I create each subsurface object, I store it into a list so that each "camera" (aka. subsurface) can be easily accessed. Here is the code for that:
Camera.py
import pygame, random
class Camera:
cameras = []
def __init__(self, screen, action_surface, screen_size):
self.screen = screen
self.surface = action_surface.subsurface(pygame.Rect(0,0,screen_size[0]/2,screen_size[1]/2))
Camera.cameras.append(self.surface)
cam_count = len(Camera.cameras)
print(cam_count)
print(Camera.cameras)
@staticmethod
def update(screen, screen_size):
for s in range(0,100):
pygame.draw.rect(Camera.cameras[1], (0,255,255), pygame.Rect(s*100, s*100, 10, 10))
pygame.draw.rect(Camera.cameras[3], (0,0,255), pygame.Rect(s*110, s*110, 10, 10))
if len(Camera.cameras) > 0:
for i in range(0, len(Camera.cameras)):
if (i%2==0):
screen.blit(Camera.cameras[i], (0, ((i/2)*(screen_size[1]/(len(Camera.cameras)/2)))))
else:
screen.blit(Camera.cameras[i], ((screen_size[0]/2), (((i/2)-0.5)*(screen_size[1]/(len(Camera.cameras)/2)))))
In theory, what this should allow me to do is access each camera from their index and draw to the individually. Unfortunately, this is not what happens.
In reality, when I select any of the camera's and attempt to draw art, all the cameras (surfaces) are updated with a duplicate copy of such art!
As you might be able to tell, this is not the desired effect I am going for. But, none the less this has happened. I am hoping that maybe somebody with more experience than me can give some insight on how to fix this problem.
Thanks.