> 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
> See the following video i made: Blit Problem Video
> 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())):
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..
Thank's both of you! I didn't know that pygame uses 16 bits integers (I thought it was 32 bits every integer i put in the blit coordinates).
I already thought to blit only images which the rectangle of it is at least inside the screen resolution.
(Excuse me for my english).
For example (How do i input code by the way?):
for sprite in all_game_objects:
I'm just trying to create a wrapper for pygame that will work as a game engine similarly to the Unity Game Engine (but only for 2d games creation), thats why i'm trying to master pygame because i had problems like fps drop, and this one.
On Thu, May 25, 2017 at 6:54 PM, babaliaris <[hidden email]> wrote:
> Thank's both of you! I didn't know that pygame uses 16 bits integers (I
> thought it was 32 bits every integer i put in the blit coordinates).
How comes you'd think such a thing? Python itself already ships
variable sized integers and keeps track of their size...
> I already thought to blit only images which the rectangle of it is at least
> inside the screen resolution.
> (Excuse me for my english).
Read my email again. I think I covered that already .