Pygame, get key object from character

依然范特西╮ 提交于 2019-12-23 01:46:07

问题


I'm making a multiplayer platformer/shooter/brawl game with pygame and I'd like for the players to easily change their keybinds (such as from a config file).

I haven't been able to find a way to read a character string and use that as a transition to the pygame.K_xx objects as of now so I ask the community.

Any leads ?


回答1:


With the constants of this list you can use

getattr(pygame, 'K_'+ mychar)

to access a constant by name.



来源:https://stackoverflow.com/questions/46714719/pygame-get-key-object-from-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!