Answer the question
In order to leave comments, you need to log in
How to make two simultaneous actions on an object?
I have an object, I can move it, and when I press the spacebar, another object appears and flies up, but as soon as I press the spacebar, the main object stops and I need to press the movement keys again to move it.
Is it possible to somehow make the object not stop after pressing the spacebar, and the second object also starts moving. Here is the event definition code:
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
main_while = False
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_RIGHT:
if hero.x < 420:
hero.x += 0.5
if ev.key == pygame.K_LEFT:
if hero.x > 3:
hero.x -= 0.5
if ev.key == pygame.K_SPACE:
if not bul_push:
bullet.x = hero.x + 30
bullet.y = hero.y + 10
bul_push = True
Answer the question
In order to leave comments, you need to log in
General approach: by pressing the key, do not change the position, but the speed of the object ( += vel). And when they release the key, change it back (-= vel).
Are you by any chance not taking An Introduction to Interactive Programming in Python right now?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question