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

Re: [pygame] If statements paused at click hold on window title bar?!



"since one sprite is moved by time, and the other is moved by your code
executing, they move based on different conditions and there you go."

Both sprites are moved based on distance_moved, which is a variable resulting from the pygame.time.Clock() instance times the speed, so both variables have the same conditions, unless I misunderstood your statement.



Brian Fisher <brian@xxxxxxxxxxxxxxxxxxx> wrote:
in windows, when people are clicking the title bar they are moving the
window (even if not moving the mouse). And by default, moving or
resizing blocks in your message loop (basically this line doesn't
return in the way you'd like: "for event in pygame.event.get():")

since one sprite is moved by time, and the other is moved by your code
executing, they move based on different conditions and there you go.

There is a way to get an app in windows to not be blocked by event
processing like that (something about calling your update from a
particular message or returning the right value from some weird barely
documented message or something like that) but I can't remember the
exact thing there off the top of my head - I think pyglet had trouble
with this and found a resolution. Pygame may be able to do the same,
but it may require some SDL changes or unpleasant hacks.


On Feb 12, 2008 9:30 AM, Gabriel Hasbun wrote:
> Probably you already noticed this.
>
> I am using Windows XP pro, no service pack, python 2.4 and pygame 1.7.1 ,
> ran this script:
>
> import pygame
> from pygame.locals import *
> from sys import exit
>
> background_filename='sushiplate.jpg'
> sprite_filename = 'fugu.png'
> pygame.init()
> screen = pygame.display.set_mode((640,480),0,32)
> background = "">> sprite = pygame.image.load(sprite_filename).convert_alpha()
>
> # Our clock object
> clock = pygame.time.Clock()
>
> # X coordinate of our sprite
> x1 = -sprite.get_width()
> x2 = -sprite.get_width()
> # Speed in pixel(s) per second
> speed = 250.
>
> frame_num = 0
>
> while True:
> for event in pygame.event.get():
> if event.type == QUIT:
> exit()
>
> screen.blit(background,(0,0))
> screen.blit(sprite,(x1,50))
> screen.blit(sprite,(x2,250))
>
> time_passed_in_sec = clock.tick(30)/1000.
> distance_moved = time_passed_in_sec*speed
> x1+=distance_moved
>
> if (frame_num%5)==0:
> x2 = x2+distance_moved*5.
>
> if x1>screen.get_width() or x2>screen.get_width() :
> x1, x2 = -sprite.get_width(),-sprite.get_width()
>
> frame_num+=1
> pygame.display.update()
>
> When I press and hold the mouse on the window title bar, the first sprite
> (The one with x value blited = x1) advances, while the second one (The one
> with x value blited = x2) is stuck in the same old x2 value, which makes me
> think that the
>
>
> if (frame_num%5)==0:
> x2 = x2+distance_moved*5.
>
> statements are not read while the mouse button is pressed in the window's
> title. Also when I leave it for about 5 seconds, when I am sure value of x1
> should be > screen.get_width() , the sprites are drawn from
>
> x1, x2 = -sprite.get_width(),-sprite.get_width()
>
> after I release the mouse button. The same happens if I leave the mouse
> button from ~3 seconds up. It makes me think the if statement is not read as
> well
>
> if x1>screen.get_width() or x2>screen.get_width() :
> x1, x2 = -sprite.get_width(),-sprite.get_width()
>
>
>
>
> Hope you have any ideas why this happens, and if you've experienced same
> issues in other OSs and on Windows but with python 2.5 and pygame 1.8.
>
> Cheers.
>
>
> ________________________________
> Looking for last minute shopping deals? Find them fast with Yahoo! Search.


Looking for last minute shopping deals? Find them fast with Yahoo! Search.