How do I delete a sprite after exiting from the right?

  • In my game, I have sprites that pretend to scroll by spawning off the layout from the left and moving across, exiting at the right. The issue is that they accumulate in the 100s after a few minutes because I don't delete them. I can't use "delete outside layout" behavior as they spawn off of the layout.

    I could check if their x < 0, but I would need new events for every object. Is this the most optimal way to do it? Can I combine events in some way?

  • If these sprites have bullet behavior, you can add an event like this:

    Sprite->Compare X -> greater than 2000 -> Sprite Destroy

    2000 here is just an example. If your layout is not scrolling, this can be a fixed number greater than layout width plus sprite width. You don't have to be very precise, just put a number that's definitely outside of the layout.

    If your layout is scrolling, you should use something like "greater than (scrollx+WindowWidth+sprite.width)" or something like that.

    Another easy way to ensure that sprites get destroyed is to add Fade behavior.

    Set Fade in=0, Wait=20, Fade out=1, Destroy after fade out=yes, and your sprites will be automatically destroyed after 21 seconds.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Good to know what I can do with the fade behavior! I think I'll be using that method. Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)