我和一个朋友在repl.it上开始学习pygame编程。我们想制作一款像老式的指针式冒险游戏那样的“真正”项目,但是我们遇到了人物移动的问题。如果我们在屏幕上的某个地方点击鼠标,人物就会“瞬间传送”到那里,但我们希望它看起来尽可能平滑。
因此,我们希望消除人物“瞬间传送”的问题,并改为将人物从当前位置以逐帧过渡到鼠标位置。
我们已经尝试减慢while循环的速度,这样每次执行while循环时都可以将人物投影出来,但这会导致整个网站崩溃。我们还尝试在repl.it之外进行操作,以防止该网站存在问题,但那里也没有解决问题。
因此,我们希望消除人物“瞬间传送”的问题,并改为将人物从当前位置以逐帧过渡到鼠标位置。
我们已经尝试减慢while循环的速度,这样每次执行while循环时都可以将人物投影出来,但这会导致整个网站崩溃。我们还尝试在repl.it之外进行操作,以防止该网站存在问题,但那里也没有解决问题。
#PMC = Character
#mpos = the mouse position
#mstate= the state of the mouse buttons (0 if nothing is pressed, 1 if a mouse
#button is pressed)
#charspeed = the speed at which the character moves (=1px)
```
#---PMC movement when mouse click-----------------------
#---x,y = mpos x2,y2 = characterpos
if mstate == (1,0,0):
#print('x: ', x, ' y: ', y, ' x2: ', x2, ' y2: ', y2) #debugging_positions
while x2 != x:
if x2>x:
x2-=charspeed
screen.blit(pmc, (x2-46, y2-184))
if x2<x:
x2+=charspeed
screen.blit(pmc, (x2-46, y2-184))
while y2 != y:
if y2>y:
y2 -= charspeed
screen.blit(pmc, (x2-46, y2-184))
if y2<y:
y2 += charspeed
screen.blit(pmc, (x2-46, y2-184))
if mstate[0]: do stuff
。 - user12291970screen.blit(pmc, (x2-46, y2-184))
,而不是在您所展示的问题中的while
和if
语句中执行。 - user12291970