你如何在不使用turtle.goto(x,y)但是turtle.speed(speed)和的情况下让乌龟移动turtle.heading(angle)?我正在制作的游戏需要这个。鼠标在哪里,我想让它朝那个方向移动。但是当我改变它时,它会去那个地方然后去我的鼠标:import turtlescreen = turtle.Screen()screen.title("Test")screen.bgcolor("white")screen.setup(width=600, height=600)ship = turtle.Turtle()ship.speed(1)ship.shape("triangle")ship.penup()ship.goto(0,0)ship.direction = "stop"ship.turtlesize(3)turtle.hideturtle()def onmove(self, fun, add=None): if fun is None: self.cv.unbind('<Motion>') else: def eventfun(event): fun(self.cv.canvasx(event.x) / self.xscale, -self.cv.canvasy(event.y) / self.yscale) self.cv.bind('<Motion>', eventfun, add)def goto_handler(x, y): onmove(turtle.Screen(), None) ship.setheading(ship.towards(x, y)) #this is where you use the x,y cordinates and I have seat them to got to x,y and set heading ship.goto(x,y) onmove(turtle.Screen(), goto_handler)onmove(screen, goto_handler)如果你只setheading和speed它只是变成这样并不会移动。如果您尝试使用此代码,它会起作用 - 正是我使用ship.goto(x, y)它使它转到(x, y). 但是当您在移动时更换鼠标时,它首先会移动(x, y)到您的新鼠标位置。我几乎只想让它跟随鼠标,但我不能那样做。
添加回答
举报
0/150
提交
取消