问题
class Score(pygame.Surface):
pygame.font.Font.render(Text, antialias, color, Background)
I am trying to make a code that will implement a Text file that gets on to my pygame surface. I want It to show up on the top right hand corner of the screen. My issue is that i have no understanding what the antialias does and what do I put on the antialias code spot. Do I put an Int or some sort of String. Here is more of the code to show just to give you an idea of what i'm going for. I hope this helps to get my answer.
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()
回答1:
The antialias argument is a boolean. If true the characters will have smooth edges. You can read about it in the documentation.
https://www.pygame.org/docs/ref/font.html#pygame.font.Font.render
Antialiasing makes images appear to have smooth edges by blurring pixels
回答2:
Anti-Aliasing is a technology computers use to render pixels smoothly.
Say you have a line, if it is straight it looks just fine, but if you make it diagonal, it becomes jagged, like a stair-case.
This is where Anti-Aliasing comes in. What it does is that it looks for spots that can be anti-aliased, and spawns a semi-transparent pixel, in the end this makes the shape look smooth, and not jagged and the pixels noticable (Hence "Alias").
If you set the argument to true, your shape will become smooth, without, it will be non-smooth, sometimes you will want to use false if you ever need to do some per-pixel manipulation.
TL;DR, Just set it to True for normal use, but sometimes you might want to use false for advanced manipulation.
来源:https://stackoverflow.com/questions/50192897/what-does-the-antialias-mean-in-this-font-render-code-for-pygame-mean