Changing Sprite in Blocks

Hi,
I’m changing a sprite when there is a collision with a bullet.
The idea is to show another sprite with the same image on fire and, afterwards, return the original sprite to the initial position. If I just change the sprite (visible false and true) and do nothing else, it works perfect. It the logic flows to the initial sprite reposition, the sprite that with the image on fire never gets to be shown. It looks like the speed of the execution flow is so fast that I never get to see the change before the initialization again.
Is there any way to solve this type of things? if I put a delay with a timer it still doesn’t work.

thank you!

Hi

Surprised the timer does not work. Try setting it to something outrageous, like a minute, to prove it has no effect.

You could of course set a new sprite at the start position and hide the “on fire” sprite.

Difficult to help more without seeing your blocks.

You will need to use

  • lists of Sprite components,
  • the Any Sprite blocks,
  • a list of burning sprites and their associated expiration Instants (list of pairs)
  • a Clock Timer to frequently scan the burning sprite list for expired burns and clean up the ashes
  • bullet collision logic to add targets to the burning sprite list.

If you are uncomfortable with lists of pairs, you could just keep a list of burning sprites, and add new ones at the end (highest index), and set the Clock Timer servicing that list to cycle slowly, enough seconds to see the burn, and to clean up and remove just item 1 (if not empty check first) each cycle.

  1. Create a clock. Set enabled to false. And the interval to 1000.

  2. When the sprite collides with the bullet, change the sprite image to the “on fire” image and set the clock enabled to true.

  3. Inside the Clock Timer event first turn the clock enabled to false. Then set the sprite image to the normal image. Next set the sprite new x and y.

This should show your “on fire” image for one second (1000 ms).

Hi ABG,
thank you for your email. This looks like the correct way to do it. Can you point to an example ? I’m an experienced programmer but just new to App Inventor.
Thank you!

Here’s a sample using Balls, video at https://www.loom.com/share/fb6e4fa50e924f03ade55b75982e94f4

bullet_cloud.aia (4.4 KB) Capture global balls global colorScheme global liveBalls
I used generic blocks.

thank you!!