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

时间:2013-06-07 01:18:31

标签: python pygame

我在游戏中制作游戏,需要在达到某个y值后重置屏幕底部的my.player。我可以通过设置sprite类中的self.y和self.x变量等于我想要的坐标来实现这一点,但是精灵不能移动,因为它被固定到那些位置。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

问题可能是在第一次“激活”后,用于修复精灵位置的命令卡在循环中。 例如: 像这样的部分

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

希望它有所帮助:)

相关问题