繁体   English   中英

我如何更改精灵的位置,同时仍然能够在PYGAME中移动精灵(带有self.x和self.y)

[英]how do i change the position of my sprite while still being able to move it (with self.x and self.y) in PYGAME

我正在用pygame制作游戏,并且在达到某个y值后需要在屏幕底部重置my.player。 我可以通过将Sprite类中的self.y和self.x变量设置为等于我想要的坐标来使其工作,但是由于其固定在那些位置,因此sprite无法移动。 有什么帮助吗?

问题可能是,用于固定子画面位置的命令在第一次“激活”后卡在了循环中。 例如:这样的一部分

stop = False
spritepositionfixed = True
while not stop:
    if y > #Your Max Y value:
        spritepositionfixed = True
    if spritepositionfixed:
        sprite.x = coordinatex
        sprite.y = coordinatey

总是在第一次到达y坐标之后设置精灵位置。 您应该将其更改为以下内容:

stop = False
while not stop:
    if y > #Your Max Y value:
        sprite.x = coordinatex
        sprite.y = coordinatey

希望它有帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM