使用pygame tranform.flip时两个弧线

发布于 2025-01-24 06:52:31 字数 755 浏览 0 评论 0原文

这是我的第一个真实代码项目。我正在尝试为学校的数学项目创建一个崩溃项目。

我目前的问题是,当我翻转弧线时,它绘制了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2025-01-31 06:52:31

当您画 ,它不会删除其他现有元素。以此代码为例:

import pygame
from pygame.locals import *

screen = pygame.display.set_mode((320, 240))
pygame.draw.rect(screen, (0, 255, 0), Rect(50, 20, 100, 100))
pygame.draw.rect(screen, (255, 0, 0), Rect(120, 100, 100, 100))
pygame.display.flip() # same as pygame.display.update() (with no arguments)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            exit()

执行此代码,您会看到2个正方形,即使您的更新 d在屏幕上,也不会阻止第一个仍然出现第一个。

“”

作为显示表面也是透明的表面,blit将显示面条to to to Plose Surese删除其内容。
为此,您可以调用 功能。


对您的代码进行一些可选的(但我建议)的一些改进:

  • 实现游戏循环到您的游戏/仿真,即获取用户事件并防止您的游戏不断
  • 使用pygame.display.flip()而不是 不断崩溃pygame.display.update()(当您只想更新
  • ,但不可能。 WNWN2是指同一表面。使用 pygame.surface.surface 用于创建其他表面。
  • 尝试将主显示表面保持原样,并与其他表面一起使用,而不是通过变换将其更改整个屏幕,因为调试时可能会令人困惑。

我希望有帮助!

When you draw onto a display Surface, it won't remove the other existing elements. Take this code as an example:

import pygame
from pygame.locals import *

screen = pygame.display.set_mode((320, 240))
pygame.draw.rect(screen, (0, 255, 0), Rect(50, 20, 100, 100))
pygame.draw.rect(screen, (255, 0, 0), Rect(120, 100, 100, 100))
pygame.display.flip() # same as pygame.display.update() (with no arguments)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            exit()

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 updated the screen.

As a display surface is also a transparent surface, blitting 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:

  • Implement a game loop to your game/simulation to namely get the user events and preventing your game from constantly crashing after a while
  • Use pygame.display.flip() instead of pygame.display.update() (the latter is useful when you want to only update part of the screen)
  • You are creating 2 screen surfaces, but that's not possible. wn and wn2 are referring to the same surface. Use pygame.Surface for creating other surfaces.
  • Try to leave the main display surface as it is, and work with other surfaces rather than changing the entire screen by transforming it, as this can be confusing when debugging.

I hope that helped!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文