7 Replies - 3755 Views - Last Post: 05 August 2010 - 09:51 AM Rate Topic: -----

#1 Guest_bigfeesh*


Reputation:

Problem using pygame.display.update

Posted 04 August 2010 - 08:56 AM

Hi,
I've been trying to understand the pygame.display.update function in the context of only updating 'dirty' rectangles.
An example of how I've been calling the function is:
pygame.display.update(pygame.Rect(0, 0, 50, 50))

However, I am finding this doesn't update that 50x50 rectangle from the origin as expected but still updates the whole display as if there was no argument.
Any ideas? Is pygame.Rect an appropriate rectangle to use?
Here is the very basic code I've been testing. Thanks for any advice.

import sys, pygame
size = width, height = 500, 500
pygame.init()

Surface = pygame.display.set_mode(size)

pygame.display.init

#Draw a red rectangle first                                                                                                       
pygame.draw.rect(Surface, (255, 0, 0), (0,0,300,300))
pygame.display.update()
#Draw a smaller green one and update only half it's length so only half should appear?                                            
pygame.draw.rect(Surface, (0, 255, 0), (0,0,100,100))
pygame.display.update(pygame.Rect(50, 50, 50, 50))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        continue



Is This A Good Question/Topic? 0

Replies To: Problem using pygame.display.update

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 317
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Problem using pygame.display.update

Posted 04 August 2010 - 01:03 PM

View Postbigfeesh, on 04 August 2010 - 07:56 AM, said:

Hi,
I've been trying to understand the pygame.display.update function in the context of only updating 'dirty' rectangles.
An example of how I've been calling the function is:
pygame.display.update(pygame.Rect(0, 0, 50, 50))

However, I am finding this doesn't update that 50x50 rectangle from the origin as expected but still updates the whole display as if there was no argument.
Any ideas? Is pygame.Rect an appropriate rectangle to use?
Here is the very basic code I've been testing. Thanks for any advice.

import sys, pygame
size = width, height = 500, 500
pygame.init()

Surface = pygame.display.set_mode(size)

pygame.display.init

#Draw a red rectangle first                                                                                                       
pygame.draw.rect(Surface, (255, 0, 0), (0,0,300,300))
pygame.display.update()
#Draw a smaller green one and update only half it's length so only half should appear?                                            
pygame.draw.rect(Surface, (0, 255, 0), (0,0,100,100))
pygame.display.update(pygame.Rect(50, 50, 50, 50))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        continue



The pygame.display.update function takes a rectangle or a list of rectangles as its argument(s) so you are correct in using this.

Your code works, from my tests anyway, you have drawn a green rectangle 100 x 100 from the origin, which is placed in the top left of the screen, then you update the screen but from (50, 50) which is in the centre of that green rectangle, if you wanted to show the rectangle half the size in the same place, you would use:

pygame.display.update( pygame.Rect(0, 0, 50, 50) )


Remove the parameter from your second update to see the difference it makes, I believe you have perhaps placed it incorrectly.

This post has been edited by Simown: 04 August 2010 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_bigfeesh*


Reputation:

Re: Problem using pygame.display.update

Posted 05 August 2010 - 04:38 AM

Thanks for your reply. I think I may have been unclear. The rectangle portion to be updated I placed at (50, 50) just so it would be clear that only this portion was being updated. The result should mean there is no part of the green square at the origin. When I run the code it is as if I have run the second pygame.display.update without a rectangle in the argument.

To be more clear I simplified the code. I now:
1. Initialise the display.
2. Draw a green square the size of the window on to the surface.
3. pygame.display.update a square whose length is half the window size and the green square I drew.

From this I would expect to see displayed:
- A green square from (0, 0) covering an area that is a quarter of the window.

What I actually get is a green square covering the whole window as if I'd used, pygame.display.update()

Simown, it is strange that it the first code appears to perform correctly for you. Passing a rectangle to this function is definitely not working for me.

Thanks again for any help. Here is the simplified code below:

import sys, pygame

size = width, height = 500, 500

pygame.init()

Surface = pygame.display.set_mode(size)

pygame.display.init

#Draw a green square the size of the window on to Surface.                                            
pygame.draw.rect(Surface, (0, 255, 0), (0, 0, width, height))
#Update only the top left quarter of the window 
pygame.display.update(pygame.Rect(0, 0, width/2, height/2))

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        continue


Was This Post Helpful? 0

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 317
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Problem using pygame.display.update

Posted 05 August 2010 - 06:01 AM

I copied your code exactly and this is the result I got, which is as you described:

Posted Image

Is that correct?

Can I ask what operating system you are using, and with which version of python?

This post has been edited by Simown: 05 August 2010 - 06:03 AM

Was This Post Helpful? 0
  • +
  • -

#5 Guest_bigfeesh*


Reputation:

Re: Problem using pygame.display.update

Posted 05 August 2010 - 07:15 AM

View PostSimown, on 05 August 2010 - 05:01 AM, said:

I copied your code exactly and this is the result I got, which is as you described:

Posted Image

Is that correct?

Can I ask what operating system you are using, and with which version of python?


Yes, that's exactly what I hoped to see.
I don't. I get a fully green window!

I am using Mac OS X 10.6.4, Python 2.7, Pygame 1.9.1

Thanks again for your reply and help Simown.
Was This Post Helpful? 0

#6 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 317
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Problem using pygame.display.update

Posted 05 August 2010 - 08:50 AM

I am unable to test it on Mac OS but I may have found the problem:

The packages on the pygame site linked directly in downloads work with Python 2.4, 2.5 or 2.6. Did you download one of these packages from the site?

And note: "These are packages for the python from python.org, not the system python."

I would advise trying Python 2.6 and the download from the site, and seeing if that fixes your problem.

I have tested it on Linux and Windows using Python 2.6 and Pygame 1.9.1 and it seems to work.

This post has been edited by Simown: 05 August 2010 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#7 Guest_bigfeesh*


Reputation:

Re: Problem using pygame.display.update

Posted 05 August 2010 - 09:37 AM

Downloaded Python 2.6, and reinstalled pygame with one of the meta-packages on the pygame site. It works now as you suggested it would!

Thank you very much for your clear help - much appreciated.
Was This Post Helpful? 0

#8 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 317
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Problem using pygame.display.update

Posted 05 August 2010 - 09:51 AM

Great :) Glad to help. Just post back here if you have any more questions or anything really!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1