python - I can increment the x position of my sprite by -0.01, but not 0.01? -


Whenever I try to add 0.01 to my x position, nothing happens, but when I add -0.01 It works fine.

  square ball (phantom): def __init __ (self, color, x, y, radius, thickness): self.speed = 0.01 self.angle = math.pi / 2 self.colour = Color self .x = x self.y = y self.radius = radius self. Dizziness = Thickness self. Just = PuGam.Rate (self.x, self, or, radius * 2, auto radius * 2) DRF draw (self, screen): pygame.draw.circle (screen, self-crow, [Self, pure, x.fi], self. RDI, self-destruct) def move (self): self.rect.x + = 0.01 # this self.rect.x - = 0.01 # This does not work Obviously, there will be no two phantom move at the same time, but it still goes to the left.   

Pygame rectangles use integers for these properties, becaus e they represent pixel value , Which is the smallest unit on the screen.

So, first, increasing from 0.01 is unusable. Secondly, you are hunting for falling prey, this is the reason that the deficit is increasing at the present time while the increment is not there. The reason for this is (2 + 0.01) 2.01 2, where there is 1.99 1. I.e. successful reduction

This dragon shell is easily shown

  & gt; & Gt; & Gt; Rect = pygame.Rect (100, 100, 10, 10) & gt; & Gt; & Gt; Rect & lt; Rect (100, 100, 10, 10) & gt; & Gt; & Gt; & Gt; Rect.x100 & gt; & Gt; & Gt; Rect.x + = 0.01 & gt; & Gt; & Gt; Rect.x100 & gt; & Gt; & Gt; Rect.x - 0.01 & gt; & Gt; & Gt; Rect.x 99  

My recommendation for the future is to store the situation in a tuple (x, y) where x and y are float, with this you can increase from 0.01 and its The effect will be. But then convert them to convert when rect attributes

  pos = (x, y) x = pos [0] x + = 0.01 ## or anything you pos = (x, Y) Built-in and re-match due to the unchangeability of Tulips (other methods are) rect.x = int (x)  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -