使用pygame tranform.flip时两个弧线
这是我的第一个真实代码项目。我正在尝试为学校的数学项目创建一个崩溃项目。
我目前的问题是,当我翻转弧线时,它绘制了2个单独的弧。我不知道为什么这样做,但是如果有人可以提供帮助,这将不胜感激。
这是我的代码:
import pygame
from math import sin, cos, radians
grid = pygame.image.load('grid3.jpg')
wn = pygame.display.set_mode((600, 600))
wn2 = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
r = 600
a = 0
b = 0
def x_y(r, i, a, b):
return (int(r * cos(radians(i)) + a), int(r * sin(radians(i)) + b))
for i in range(0, 90, 1):
clock.tick(30)
pygame.draw.line(wn, (255, 255, 255), x_y(r, i, a, b), x_y(r, i+1, a, b), 10)
wn2.blit(wn, (0,0))
wn.blit(grid,(0,0))
wn2.blit(pygame.transform.rotate(wn2, -90), (0, 0))
wn = pygame.transform.flip(wn2, True, False)
pygame.display.update()
This is my first real code project. I am trying to create a Crash gambling project for a math project at School.
My current problem is that when I flip my arc it draws 2 separate arcs. I don't know why it does this but if anyone can help it would be much appreciated.
Here is my code:
import pygame
from math import sin, cos, radians
grid = pygame.image.load('grid3.jpg')
wn = pygame.display.set_mode((600, 600))
wn2 = pygame.display.set_mode((600, 600))
clock = pygame.time.Clock()
r = 600
a = 0
b = 0
def x_y(r, i, a, b):
return (int(r * cos(radians(i)) + a), int(r * sin(radians(i)) + b))
for i in range(0, 90, 1):
clock.tick(30)
pygame.draw.line(wn, (255, 255, 255), x_y(r, i, a, b), x_y(r, i+1, a, b), 10)
wn2.blit(wn, (0,0))
wn.blit(grid,(0,0))
wn2.blit(pygame.transform.rotate(wn2, -90), (0, 0))
wn = pygame.transform.flip(wn2, True, False)
pygame.display.update()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您画 ,它不会删除其他现有元素。以此代码为例:
执行此代码,您会看到2个正方形,即使您的
更新
d在屏幕上,也不会阻止第一个仍然出现第一个。作为显示表面也是透明的表面,
blit
将显示面条to to to Plose Surese删除其内容。为此,您可以调用 功能。
对您的代码进行一些可选的(但我建议)的一些改进:
pygame.display.flip()
而不是 不断崩溃pygame.display.update()
(当您只想更新WN
和WN2
是指同一表面。使用pygame.surface.surface
用于创建其他表面。变换
将其更改整个屏幕,因为调试时可能会令人困惑。我希望有帮助!
When you draw onto a display
Surface
, it won't remove the other existing elements. Take this code as an example:When executing this, you will see 2 squares appear, the second one being drawn not preventing the first one from still appearing, even though you
update
d the screen.As a display surface is also a transparent surface,
blit
ting a display Surface onto another will not erase its content.To do that, you can call the
Surface.fill
function.A few optional (but some I recommend) improvements to your code:
pygame.display.flip()
instead ofpygame.display.update()
(the latter is useful when you want to only update part of the screen)wn
andwn2
are referring to the same surface. Usepygame.Surface
for creating other surfaces.transform
ing it, as this can be confusing when debugging.I hope that helped!