Home > other >  The self. The rect. Centerx and self center transformation problems
The self. The rect. Centerx and self center transformation problems

Time:09-26

The import pygame
The class Ship () :
Def __init__ (self, ai_settings, screen) :
The self. The screen=screen
Self. Ai_settings=ai_settings
The self. The image=pygame. Image. The load (' images/ship. BMP)
The self. The rect=self. Image. Get_rect ()
Self. Screen_rect=screen. Get_rect ()
The self. The rect. Centerx=self. Screen_rect. Centerx
The self. The rect. Bottom=self. Screen_rect. Bottom
Self. Moving_right=False
Self. Moving_left=False
Self center=float (self. The rect. Centerx)
Def blitme (self) :
The self. The screen. The blit (self image, self. The rect)
Def update (self) :
If self. Moving_right and self. The rect. RightThe self. The center +=self. Ai_settings. Ship_speed_factor
If self. Moving_left:
The self. The center +=- self. Ai_settings. Ship_speed_factor
The self. The rect. Centerx=self. Center# centerx only integer values, why to return can?



Sorry to bother you, the first question
Is learning python, but there is a place is not very understand in
Of the center and centerx, part of the book said centerx cannot store the decimal point, so the assignment to the center, which to store
But in the end, assign values to come back again, and said in the book cannot store centerx or decimal point at this moment, only impact???????
I want to ask you, is this why? Code as above, to run no problem.

CodePudding user response:

Isn't right click, while has been in circulation, and accumulation of decimal? Decimal is greater than 1, leading to the ship faster and faster, I also understand not clear,,,, code very difficult in the world
  • Related