Okay I am making a 2D scroller game with pygame but want to be able to control when to take collisions into consideration. For example, after my player collides and dies he respawns straight away in the middle of the screen, the problem is that there is often another collision object close by which kills the player instantly. What I want is some small time period in which the player is immured to collisions allowing it to move away to safety first then carry on playing ad normal. I was thinking maybe placing the respawns in a dummy sprite group then over time remove and add it to another group that has collisions. I don't really know.
When the player dies, I would set a variable with the number of frames you want it to be invulnerable for. When you do your collision detection, you can check if the player has any frames of invulnerability left, and only handle collisions when there are no frames left.
def kill_player(player):
# handle moving the player after death, anything else you need to do
# set player invulnerability to 30 frames
player_invulnerable_frames = 30
if environment_rect.collides(player_rect) and player_invulnerable_frames = 0:
# perform collision response stuff here
In your game loop, or maybe an update function, you can decrease the number of invulnerability frames if it is currently greater than zero
while(running):
# your game loop stuff
if player_invulnerable_frames > 0:
player_invulnerable_frames -= 1