I know that to get a pixel color in PyGame I use get_at
.
But I have a huge background image and a good part of it stays outside of the pygame delimited screen area.
For example, a 1000x1000 image inside a 500x500 screen will only have 50% visible, the rest will be "off" the screen. So I need to access this part OUTSIDE the pygame screen.
But if I refer to get_at
with a coordinate greater or less than the dimensions of the screen, Pygame gives an error:
IndexError: pixel index out of range
import pygame
W = 600
H = 400
pygame.init()
screen = pygame.display.set_mode([W, H])
image = pygame.image.load('huge_background.png').convert_alpha()
screen.blit(image, [-5000, -420])
pygame.display.update()
screen.get_at([100, -5]) # gera o erro "IndexError: pixel index out of range"
Would anyone know how I can access a pixel beyond the visible area of the pygame screen?
This is a simulation of vehicles within a track.
Here is the pygame screen currently visible (1600 x 600). The 3 lines (in magenta) are the collision "detectors":
Andhereisthebackground(track)thatwillscrollaccordingtothepositionofthecar(8000x8000):
Thiswouldbeascreenview(quotedinred)andtheoverallplanewiththebackgroundimage(track):
Thus,collisiondetectorlinesmayexceedthepygame'sscreenboundaries,butmust"read" the outer pixels to detect the collision.