pygame,从角色获取关键对象

编程入门 行业动态 更新时间:2024-10-26 20:28:35
本文介绍了pygame,从角色获取关键对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用pygame制作多人平台游戏/射击游戏/斗殴游戏,我希望玩家可以轻松地更改其键绑定(例如从配置文件中更改).

到目前为止,我还没有找到一种读取字符串并将其用作到pygame.K_xx对象的过渡的方法,所以我问社区.

有线索吗?

解决方案

具有此列表您可以使用

getattr(pygame, 'K_'+ mychar)

按名称访问常量.

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 ?

解决方案

With the constants of this list you can use

getattr(pygame, 'K_'+ mychar)

to access a constant by name.

更多推荐

pygame,从角色获取关键对象

本文发布于:2023-11-25 08:51:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629115.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角色   对象   关键   pygame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!