简体   繁体   English

在Tkinter中旋转图像进行游戏

[英]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. 我正在使用Tkinter画布在python中创建游戏,并且需要在游戏中旋转精灵,我尝试使用PIL的'image'.rotate()但是质量损失过高,其性能不会超过在开始严重滞后之前要进行20次转换。 Can this be fixed or are there any other options aside from making 100s of images by hand? 除了可以手动制作100张图像外,是否可以解决此问题? 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 增量= 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. 编辑:和TKinter是GUI应用程序,而不是游戏。 I recommend Pygame instead. 我推荐使用Pygame。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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