[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Blit method bug?



On Thu, May 25, 2017 at 1:06 PM, babaliaris <babaliaris.nikos@xxxxxxxxx> wrote:
> Hello!
>
> i have a problem with blit. When i try to blit a lot of images using a for
> loop (for example 800) after a certain amount, the blit is messing up the
> drawing.
>
> See the following video i made:  Blit Problem Video
> <https://www.youtube.com/watch?v=3L2tL5TW1S0>
>
> You can clearly see all my code in the video.
>
> Can anyone tell me if this is a bug or if not, what is the problem?
>


Let's be generous and say that this is not a bug, but rather a
technical limitation. Obviously pygame uses 16 bit integers for
coordinates internally, so that when you use coordinates higher than
65535, they wrap around to 0 again.
The question is, whether silly input values deserve silly output.
Personally, I see nothing wrong with that. I'm not sure you even could
attach more than 4 4k screens in a row to a modern computer, but that
would only amount to maximally quarter of the 65536 line which you
crossed in your video.

You can make sure that is the case by passing sensible values to your
blit function. For example, you could not blit at all if the
coordinates are outside the screen rectangle with the following
addition (to replace the blit line you already have):

image_pos = (x + i, y + i)
if screen.get_rect().colliderect(pygame.Rect(image_pos, image.get_size())):
    screen.blit(image, image_pos)

cheers!
mar77i