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

[pygame] Re: PyGame Windows Key Behaviour



Thanks, it's scrolling fine now on different machines.

Greets
Thomas

On 1 Feb., 09:58, Brian Fisher <br...@xxxxxxxxxxxxxxxxxxx> wrote:
> Hey Thomas,
>    Ian Mallet's guess was correct and his solution will fix it.
>
> You are moving the paddle based on key down events coming in, It looks like
> you were counting on:
>     pygame.key.set_repeat(1,1)
> to provide you with key down events every frame, but it doesn't work out
> that way. I added prints to your code to see how the objects were moving,
> and both paddles move by the same amount each time they move, but sometimes
> the player paddle moves only 2 out of 3 frames (i.e. the player paddle moves
> slower), hence the speed difference you were seeing.
>
> What you want is to move the paddle when the appropriate key is held down -
> namely when you've had a down event without an up event yet. key_pressed()
> is a shortcut way to get that info.
>
> On Mon, Jan 31, 2011 at 11:51 PM, Thomas <pummer.tho...@xxxxxxxxx> wrote:
> > Hi there, thanks for fast responses
>
> > @ Julian: Equal means exakt the same function with the same
> > playerspeed variable - but under other conditions:
> > it compares the position of the cpuplayer and the ball and rearranges
> > the cpuplayer
> > def move_player_a(ball_y):
> >    global a_y
> >    if a_y + 31 > ball_y and a_y > 0:
> >        #up
> >        a_y += seconds * playerspeed * -1
> >    elif a_y + 31 < ball_y and a_y + 95 < 360:
> >        #down
> >        a_y += seconds * playerspeed * 1
>
> > i will have to take a look at framerates
> > thanks for that hint
>
> > @ Ian: i will also check pygame.key.get_pressed(). thx
>
> > @ Brian: The complete code is herehttp://pastebin.com/ic44uvfU
> > code was growing with my pygame knowledgement, so it isn't as nice as
> > i would like to have it ;)
> > but as additional info, pictures where used as background and as bars