[英]Moving a Sprite Back and Forth in pygame
I have the sprite going from on end of the screen to the other, but now I want it to go back and forth forever. 我让精灵从屏幕的另一端移到另一端,但是现在我希望它可以一直来回移动。 Any ideas? 有任何想法吗?
u = 1 #u is the x coordinate
if u < 430: #480 is the window siz, i want it to stop at 430
u += 5 # Move up by 5
Should I add my whole code so it is easier? 我应该添加整个代码,这样更容易吗?
You can use a delta variable: 您可以使用增量变量:
delta = 5
u = 1
and have it adjusted to switch directions: 并进行调整以切换方向:
u += delta
if u >= 430:
delta = -5
elif u < 50:
delta = 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.