Re: keyboard input in pygame extremely unreliable

2019-12-02 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

As others pointed out, how your processing the keyboard events is sub-optimal. Typically you should be tapping the event buffer only once per cycle, and either do all your checks then, or collect the results to pass off to other functions or classes. Generally, I tend to process key input into a list to pass off to other functions or classes as necessary, though there are other ways of structuring it. I've tweaked your code abit and changed it so it dumps the key event buffer into such a list, then do checks to see if desired keys are in it, and process it from there. I think you'll find it much more responsive:import pygame, pygame.locals as pl, pygame.time as time
import sys

def keyp():
 keys = []
 for event in pygame.event.get():
  if event.type == pygame.KEYDOWN:
   keys.append(event.key)
 return keys

def main():
pygame.init()
screen = pygame.display.set_mode((600, 400))
pygame.display.set_caption("play with pan")

x = 0
while True:
  keys = keyp()
  if pl.K_LEFT in keys:
   x-=1
   print(x)
  if pl.K_RIGHT in keys:
   x+=1
   print(x)
  if pl.K_ESCAPE in keys:
   pygame.quit()
   sys.exit()

main()

URL: https://forum.audiogames.net/post/482003/#p482003




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-12-02 Thread AudioGames . net Forum — Developers room : NicklasMCHD via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Hi @simterLucia's documentation can be found here.

URL: https://forum.audiogames.net/post/481995/#p481995




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-12-02 Thread AudioGames . net Forum — Developers room : Perry Simm via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Hi!I agree with Rastislav over why keys are dropped. You nailed it.Don't search the entire event history for one key, discarding other keys as you go. Instead, define a key event handler that deals with them all and dispatches them to where they are handled.Cheers Perry

URL: https://forum.audiogames.net/post/481989/#p481989




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

but they are pritty self explanitory

URL: https://forum.audiogames.net/post/481672/#p481672




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : simter via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

@11 i see that, but a lot of functions are not described, and just their names are standing there.

URL: https://forum.audiogames.net/post/481581/#p481581




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Hi there, pygame does have directect keyboard and window support...

URL: https://forum.audiogames.net/post/481547/#p481547




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Hmm, I see. Then just ignore my note on the timing, that should be okay, but what I said about key presses still remains.I'm wondering, doesn't pygame has a built-in method to check for a key state directly? Gaming libraries usually have such functionality, infact that was the way I was doing it all the time with DirectX or basic system libraries before I first learned about more advanced uses of events and developed much better solutions for capturing shortcuts.I would be surprised, if pygame didn't have such function. It could be exactly what you want.Best regardsRastislav

URL: https://forum.audiogames.net/post/481539/#p481539




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

it's not that hard, just ask around here if there are things that you can't understand. and by the way, if you look on the github, you can find the latest documentation. you can also generate your own documentation acoarding to instructions.

URL: https://forum.audiogames.net/post/481535/#p481535




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : simter via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

@9 yeah, but i can't find propper documentation for it.

URL: https://forum.audiogames.net/post/481523/#p481523




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Or if you reelly want to make life for your self more simple, use lucia. it's great!

URL: https://forum.audiogames.net/post/481513/#p481513




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

The function empties the event ... queue? Stack? So checking for a single event means that you miss all the other events. If you really want it to work like BGT, you need a dict to map keys to bools, and have a function that updates those for every iteration of your loop.Handling that with Python's scope rules seems kinda annoying, but probably easier than making a whole class for this. If your dict is called keys, you'd put "global keys" as the first line of your function. If it's a class method/property, disregard that.

URL: https://forum.audiogames.net/post/481507/#p481507




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

I, C. Unfortunately, your modifications would not work for reasons outlined above.  Still, E for effort.

URL: https://forum.audiogames.net/post/481493/#p481493




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : simter via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

@5 I modified your key pressing example from tutorial 2 so it works more like in bgt.@3 and 4, i am using the pygame.time, not the python time. This module indead waits secs, not ms. But thanks for the suggestion, it was just working like that in bgt so i thought it may work in py as well.

URL: https://forum.audiogames.net/post/481489/#p481489




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : simter via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

@5 Didn't i say that i modified this slightly?@3 and 4, i am using the pygame.time, not the python time. This module indead waits secs, not ms. But thanks for the suggestion, it was just working like that in bgt so i thought it may work in py as well.

URL: https://forum.audiogames.net/post/481489/#p481489




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

@1, could you please point out where in my guide did I show such a method? For the life of me, I can't find it.Your code also looks like it has several mistakes besides the wrong keyp function. I would recommend comparing it with my examples in the guide to see what is different and then proceeding from there.

URL: https://forum.audiogames.net/post/481466/#p481466




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Oh yeah, sorry for doubleposting, but this is important.I have just actually read, what you wrote, and I guess you are handling events in a wrong way.Imagine them like e-mails coming to your inbox, notifying you about some changes, like key presses. When you check newly arrived e-mail, you read its content and then throw it away.Now, what you actually wrote is, that with the keyp method, you are checking new e-mails, until you find one about a key press, and if that key press is of key, which you want to see, then you return true.But what if it's another key?Then you just throw it away, so the other callings of the keyp function have no idea, that their key was pressed.Because of this, chance of whether the key pressed by you will be recognized is related to which calling of keyp function will you hit in time. If the correctone, key will be classified, otherwise it will be just ignored.Best regardsRastislav

URL: https://forum.audiogames.net/post/481455/#p481455




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

Hi,5 is too too much. time.sleep is taking its first parameter in seconds, not milliseconds, like bgt's wait.So time.sleep(0.005) is what you most likely want to do, or some other value around that, 0.01 should work fine as well.Including no sleep will cause overuse of cpu, what could result in slower reactions.Try to include the sleep interval I mentioned. I didn't use pygame, but I think it could work just fine.And yeah, that indentation mistake regarding methods is true, everything under def should be indented, although I'm wondering if this isn't just a copy error, as Python should warn you about wrong indentation.Best regardsRastislav

URL: https://forum.audiogames.net/post/481451/#p481451




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : Ty via Audiogames-reflector


  


Re: keyboard input in pygame extremely unreliable

You didn't indent the first line in your functions

URL: https://forum.audiogames.net/post/481443/#p481443




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


keyboard input in pygame extremely unreliable

2019-11-30 Thread AudioGames . net Forum — Developers room : simter via Audiogames-reflector


  


keyboard input in pygame extremely unreliable

Hi. Sorry for another question after so short time. But how ever, I tried to build a small aplication tha allowes you to test pythons pan by using the arrow keys and escape to exit. Here's my key pressed funktion, it's from americranians py tutorial with a small modification.def keyp(key): for event in pygame.event.get():  if event.type == pygame.KEYDOWN: #A key event that has been detected   if event.key == key:    return TrueHow ever, if you add more then 1 key to the while loop the input starts geting really unreliable, keeps dropping keys, and you have to press every key a thun of times so it gets accepted. It's geting even worse if you include a wait statement. Here's my code. I used carters sound ans soundpositioning class.import pygame, pygame.locals as pl, pygame.time as timeimport sysimport sound, sound_positioning as spdef keyp(key): for event in pygame.event.get():  if event.type == pygame.KEYDOWN:    if event.key == key:    return Truedef main(): pygame.init() screen = pygame.display.set_mode((600, 400))  pygame.display.set_caption("play with pan")s=sound.sound() s.load("sound.mp3") x=0 s.play_looped() while True:  time.wait(5)  sp.position_sound_1d(s,0,x,2,2)  if keyp(pl.K_LEFT)==True:   x-=1  if keyp(pl.K_RIGHT):   x+=1  if keyp(pl.K_ESCAPE):   sys.exit()main()right now the keys are almost not responding at all cause the wait statement is in there. Can anyone please tell me what i am doing wrong? Greatings and thanks, simter.

URL: https://forum.audiogames.net/post/481441/#p481441




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector