0

there is an example in stackoverflow, it is runing under the titel: Make a line as a sprite with its own collision. There is an example from Rabbid 76.I want to modify the example.

I want to get a message in the moment when the line hits the image. For example "hit" appears, which disappears again after 1 seconds. Then a second message comes up for 1 seconds when the line leaves the picture.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Joachim
  • 375
  • 1
  • 12
  • 1
    I saw the example. But i work with spritegroups. When the line finish the collide with the picture, how get the information about that and how do i rect.x and rect.y from the line in that moment? – Joachim Feb 20 '22 at 08:23
  • See [Pygame "pop up" text](https://stackoverflow.com/questions/70996802/pygame-pop-up-text/70996856#70996856) – Rabbid76 Feb 20 '22 at 08:25
  • I saw and understand pop up text. That don't solve my problem. I give up. – Joachim Feb 20 '22 at 08:48
  • 2
    Your question is _"[...] For example "hit" appears, which disappears again after 1 seconds [...]"_. This is exactly what is shown in [Pygame "pop up" text](https://stackoverflow.com/questions/70996802/pygame-pop-up-text/70996856#70996856). If this answer doesn't help you, you need to provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) and exactly explain where you struggle. – Rabbid76 Feb 20 '22 at 09:29

1 Answers1

0

You must create a text object when the 2 objects collide. Store the time when the text must disappear again in an attribute of the object. Add the object to a list and draw all the text objects in the list in each frame. If the current time is greater than the object's end time, remove the object from the list.

Examples of this principle can be found in the answer to the following questions:

Pygame "pop up" text

break down a permanent collisions into individual events in pygame

Adding a particle effect to my clicker game

Rabbid76
  • 202,892
  • 27
  • 131
  • 174