Dec-09-2020, 04:13 AM
Hi, I am using Metulburr's state machine for a project. I have an event that is lagging when NOT coded directly into the Control class event handler..
My code is as follows:
Any ideas? Please let me know if I can clear anything else up. Thanks!
My code is as follows:
def get_event(self, event): keys = pg.key.get_pressed() mouse = pg.mouse.get_pos() if keys[pg.K_a]: main_char.moveLeft(5), point.moveLeft(5) elif keys[pg.K_d]: main_char.moveRight(5), point.moveRight(5) if keys[pg.K_w]: main_char.moveUp(5), point.moveUp(5) elif keys[pg.K_s]: main_char.moveDown(5), point.moveDown(5) if keys[pg.K_SPACE]: self.ammo -= 1 chooser = choice(gunshots) pg.mixer.Sound.play(chooser) collider = pg.sprite.groupcollide(dot_sprites_list, villain_sprites_list, dokilla=False,dokillb=False) if collider: self.health -= 1 if self.health == 0: collider = pg.sprite.groupcollide(dot_sprites_list, villain_sprites_list, dokilla=False,dokillb=True) elif event.type == spawn: testing_jack.move_pos()When the event is in the Control class's event method, it runs smoothly. If it is as shown above, in the class which inherits from the States class, it lags and is not smooth. And just to be clear, what I mean by lag is that the sprite, controlled by the w,a,s,d keys, moves very slow and takes a second to move, as opposed to being instant when in the Control class's event handler. I'd just leave it there, but it will cause problems like that.
Any ideas? Please let me know if I can clear anything else up. Thanks!