右转游戏

时间:2018-03-08 09:36:11

标签: python tkinter rotation tkinter-canvas

我正在尝试制作一个玩家在球场上移动的游戏,我有一个Triange向前移动但我需要在按下按键时让它旋转。有谁知道我怎么做这个

#player
Tx = 125
Ty = 515
BLx = 115
BLy = 545
BRx = 135
BRy = 545
player = playarea.create_polygon(Tx, Ty, BLx, BLy, BRx, BRy, fill="red", outline = "black")

#moving
def moveup(master):                          
    global Tx, Ty, BRx, BRy, BLx, BLy
    Ty=Ty-4
    BRy=BRy-4
    BLy=BLy-4
    playarea.coords(player, Tx, Ty, BRx, BRy, BLx, BLy)  
    window.after(10, moveup, master)
moveup(window)

1 个答案:

答案 0 :(得分:0)

您再次使用坐标改变方向

import sys
if 3 == sys.version_info[0]: ## 3.X is default if dual system
    import tkinter as tk     ## Python 3.x
else:
    import Tkinter as tk     ## Python 2.x

root = tk.Tk()

canvas = tk.Canvas(root, width=400, height=400)
canvas.grid()

start_x=10
start_y=start_x+90
player = canvas.create_polygon(start_x, start_y, start_x, start_y+50,
                start_x+300, start_y+50, fill="red", outline = "black")
tk.Button(root, text="Quit", command=root.quit,
          bg="orange").grid(row=10)

print(canvas.coords(player))
start_y=start_x
root.after(1000, canvas.coords, player, start_x+300, start_y,
                      start_x+300, start_y+50, start_x, start_y+50)
root.mainloop()