我要定義一個函數來設定速度,以人物在我比賽的節奏,我知道有這個公式:設置字符
rate * time = distance
1. Establish a rate of movement in whatever units of measure you want (such as pixels per millisecond).
2. Get the time since the last update that has passed (elapsed time).
3. Establish the direction of movement .
我已經tryied定義它實現方法這個:
def speed(self, speed):
clock = pygame.time.Clock()
milliseconds = clock.tick(60) # milliseconds passed since last frame
seconds = milliseconds/1000.0
speed = seconds * (self.dx+self.dy)
但是當我調用這個方法來改變我角色的速度時,沒有任何反應。
有什麼建議嗎?
你對速度做了什麼?你在哪裏調用這個函數? –
你似乎忘了添加'return speed'。 –
這是爲了*設定*速度還是要*取得它?爲什麼它有一個「速度」參數? – jonrsharpe