【发布时间】:2020-02-29 00:47:47
【问题描述】:
如何让 pygame rect 顺利移动?就像我将 x 位置更新 2 一样,它看起来很平滑,但如果我用更大的数字(例如 25)更新它,它就会传送到该位置。另外,如果可能的话,这也适用于小数吗?
import pygame
import math
GREEN = (20, 255, 140)
GREY = (210, 210 ,210)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
PURPLE = (255, 0, 255)
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
class Dot(pygame.sprite.Sprite):
# This class represents a car. It derives from the "Sprite" class in Pygame.
def __init__(self, color, width, height):
# Call the parent class (Sprite) constructor
super().__init__()
# Pass in the color of the car, and its x and y position, width and height.
# Set the background color and set it to be transparent
self.image = pygame.Surface([width, height])
self.image.fill(WHITE)
self.image.set_colorkey(WHITE)
self.color = color
self.width = width
self.height = height
pygame.draw.rect(self.image, self.color, [0, 0, self.width, self.height])
self.rect = self.image.get_rect()
【问题讨论】:
-
尝试将距离减半,将
clock.tick时间戳加倍 -
为什么要在构造函数中绘制一个矩形(
pygame.draw.rect)?这似乎没有任何意义。