Answer the question
In order to leave comments, you need to log in
How to use real numbers less than 1 in pygame?
I will not give the whole code, only the essence. Small code is easier to understand.
If anything, all imports work. The object moves when I pass it an integer or float greater than 1 (and of course it moves at a speed of 1 at 1.9).
And of course it doesn't move when it's a real value less than 1, like 0.9
I know that rect can't store a real number in itself, but I don't understand how it works to pass real numbers to it
class Settings:
# класс со всеми настройками, который я передаю в другой класс
def __init__(self):
# Если здесь будет целочисленное значение, то объект двигается.
# self.speed = 1 # Всё ОК!
# self.speed = 1.9 # Всё ОК!
# Объект не двигается с вещественными числами меньше 1
self.speed = 0.3
class NOMATTER:
# класс, описывающий поведение объектов...
# вызываемый метод
def move(self):
if self.rect.y > 0:
self.rect.y += float(self.settings.speed)
self.nevazhno_kakoe_nazvanie = float(self.rect.centerx) # Чтобы работать с перемещением по оси "икс"
# и затем:
self.nevazhno_kakoe_nazvanie += self.settings.speed
# и затем использовать:
self.rect.centerx = self.nevazhno_kakoe_nazvanie
Answer the question
In order to leave comments, you need to log in
The rect coordinates are stored as an integer value. In order to implement movement less than a pixel, it is necessary to store the value of the coordinates in separate real variables and substitute them (discarding the fractional part) into the current coordinates of the object. It also costs its real numbers to increase, and not the current coordinates directly.
p.s. My first reply. Do not judge strictly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question