Hi babaliaris,

Glad to see you're trying out pygame.  Just a suggestion, but even though
you can see the code in the video, it's still a good idea to paste or
provide a link to it in your email.

This is something I've encountered before. It doesn't really have anything
to do with the number of images you're blitting (only a very small
percentage of those are even being written to the screen, see?) It's a
limitation due to the coordinates being 16-bit integers.  When those go
past  32,767 (for signed, which allow negative and positive values), it
starts back at -32,767 and continues until we hit positive values you would
see on the screen.  Since those are starting at an odd number, you end up
with the 'offset' images you see in your output.

Python 3 supports much larger numbers.  iirc, the default for an integer is
as much as a full Long -- so it should match the maximum allowable value
for your environment.  Pygame is still using 16-bit integers for blitting,
though.  One thing to remember is that all of those very large values are
wayyyy outside the coordinates you are actually using in your display
600x600 window.  Anyway, you will want to do something like storing the
absolute location of an object and also the location (rect) of a 'camera'.
Then you can do a calculation to find where you should display the object
(if at all) by finding out where it is in relation to your camera rect.  I
usually keep track of 2 rectangles per object; a hrect (as in "hit" rect)
for absolute value / collisions, and a rect that is its location in
relation to the camera (and named 'rect' so it will be used by the sprite
group's draw method). Something like..

class Thing(pygame.sprite.Sprite):
def __init__(self, x, y):
    self.x, self.y = x, y
    self.image = pygame.image.load("dude.png")
    self.rect = self.image.get_rect()

    self.hrect = self.rect.copy()

    self.hrect.topleft = self.x, self.y
...
def update(self, camera):
    # logic to update self.x and self.y goes here

    self.hrect.topleft = self.x, self.y
    self.rect.topleft = self.x - camera.x, self.y - camera.y



Hope that helps.

On Thu, May 25, 2017 at 7:06 AM, babaliaris <babaliaris.ni...@gmail.com>
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?
>
> Thank you.
>
>
>
> --
> View this message in context: http://pygame-users.25799.x6.
> nabble.com/Blit-method-bug-tp3039.html
> Sent from the pygame-users mailing list archive at Nabble.com.
>

Reply via email to