class Score(pygame.Surface):
pygame.font.Font.render(Text, antialias, color, Background)
我正在尝试创建一个代码来实现一个文本文件,该文件可以进入我的pygame表面。我希望它显示在屏幕的右上角。我的问题是我不知道antialias做了什么以及我对antialias代码点有什么看法。我是否放置了Int或某种String。这里有更多代码,只是为了让您了解我的目标。我希望这有助于得到我的答案。
import pygame
from pygame.locals import *
from sys import exit
class Ball(pygame.Surface):
""" A bouncy ball """
x = 320
y = 0
speedx = 0
speedy = 250
def get_top(self):
return self.y
def get_bottom(self):
return self.y + self.get_height()
def get_left(self):
return self.x
def get_right(self):
return self.x + self.get_width()
def is_hit(self, paddle):
if self.get_bottom() >= paddle.get_top():
if self.get_right() >= paddle.get_left():
if self.get_left() <= paddle.get_right():
if self.get_top() <= paddle.get_top():
self.speedy = self.speedy * -1
self.y = self.y - 3
if paddle.motion == "Left":
self.speedx -= 20
if paddle.motion == "Right":
self.speedx += 20
class Paddle(pygame.Surface):
""" A Paddle """
x = 200
y = 260
motion = "None"
def get_top(self):
return self.y
def get_bottom(self):
return self.y + self.get_height()
def get_left(self):
return self.x
def get_right(self):
return self.x + self.get_width()
class Score(pygame.Surface): pygame.font.Font.render("name.png",
if __name__ == "__main__":
pygame.init()
infoObject = pygame.display.Info()
screen_w = 640
screen_h = 480
screen = pygame.display.set_mode((screen_w, screen_h), 0, 32)
clock = pygame.time.Clock()
screencolor = (0,255,255)
color = (255, 0, 0)
color2 = (0,0,255)
radius = 7
pos = (radius,radius)
screen.fill(screencolor)
wipe = pygame.Surface((screen_w,screen_h))
pygame.draw.rect(wipe, screencolor, pygame.Rect(0,0,screen_w,screen_h))
paddle = Paddle((70,10))
pygame.draw.rect(paddle, color2, pygame.Rect(0,0,70,10))
sprite = Ball((radius*2,radius*2))
pygame.draw.circle(sprite, color, pos, radius)
sprite.set_colorkey((0,0,0))
paddle_old_position = paddle.x
Fullscreen = False
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
paddleX, test = pygame.mouse.get_pos()
paddle.x = paddleX - (paddle.get_width() / 2)
screen.blit(wipe, (0,0))
screen.blit(paddle, (paddle.x,260))
screen.blit(sprite, (sprite.x, sprite.y))
time_passed = clock.tick()
time_passed_seconds = time_passed / 1000.0
distancemovedy = time_passed_seconds * sprite.speedy
sprite.y += distancemovedy
distancemovedx = time_passed_seconds * sprite.speedx
sprite.x += distancemovedx
if paddle.x < paddle_old_position:
paddle.motion = "Left"
if paddle.x > paddle_old_position:
paddle.motion = "Right"
sprite.is_hit(paddle)
paddle_old_position = paddle.x
if sprite.get_bottom() > screen_h:
sprite.speedy = abs(sprite.speedy) * -1
if sprite.get_top() < 0:
sprite.speedy = abs(sprite.speedy)
if sprite.get_right() > screen_w:
sprite.speedx = abs(sprite.speedx) * -1
if sprite.get_left() < 0:
sprite.speedx = abs(sprite.speedx)
if event.type == KEYDOWN:
if event.key == K_f:
Fullscreen = not Fullscreen
if Fullscreen:
screen = pygame.display.set_mode((screen_w, screen_h), FULLSCREEN, 32)
else:
screen = pygame.display.set_mode((screen_w, screen_h), 0, 32)
pygame.display.update()
答案 0 :(得分:3)
antialias参数是一个布尔值。如果为true,则字符将具有平滑边缘。您可以在文档中阅读它。
https://www.pygame.org/docs/ref/font.html#pygame.font.Font.render
抗锯齿通过模糊像素使图像看起来具有平滑的边缘
答案 1 :(得分:2)
抗锯齿是计算机用于平滑渲染像素的技术。
假设你有一条线,如果它是直的,它看起来很好,但是如果你使它成为对角线,它会变成锯齿状,就像一个楼梯。
这就是Anti-Aliasing的用武之地。它的作用是寻找可以消除锯齿的斑点,并产生一个半透明的像素,最终使形状看起来光滑,而不是锯齿状。像素值得注意(因此&#34; Alias&#34;)。
如果你将参数设置为true,你的形状会变得平滑,没有,它会变得不平滑,如果你需要做一些逐像素操作,你有时会想要使用false。
TL; DR,只需将其设置为True即可正常使用,但有时您可能希望使用false进行高级操作。