简体   繁体   中英

Rotate image in tkinter for game

I am creating a game in python using Tkinter canvases, and I need to rotate a sprite in the game, I have attempted using PIL's 'image'.rotate() however the loss of quality is far too high and it wont perform more than about 20 transforms before it starts to lag badly. Can this be fixed or are there any other options aside from making 100s of images by hand? Here is my code:

shipPIL = shipPIL.rotate(math.degrees(increment), expand=True)
shipTex = ImageTk.PhotoImage(shipPIL)
canvas.itemconfig(self.object, image=shipTex)

increment = pi/20

You really should be saving the original image as a clean copy, and rotating it starting from the original each time. Depending on what you're doing, it may also be a good idea to cache the various rotations somewhere instead of calculating it each time.

EDIT: and TKinter is for GUI applications, not games. I recommend Pygame instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM