我要定义一个函数来设定速度,以人物在我比赛的节奏,我知道有这个公式:设置字符
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