Destroying all sprite instances except 1

0 favourites
  • 8 posts
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • Basically I have the same instance bullet objects moving in one direction and what I want is that when the bullet objects overlap another bullet object, all the bullet objects should be destroyed except for 1.

    So lets say theres three instances of the same sprite all overlapping eachother. I want two of them destroyed, with only one left. It doesn't matter which one is left as long as all of them except "1" are destroyed.

    At the same time these objects are respawning, so I cant seem to think of a proper solution.

    Heres the Pseudo code: Assume three sprites are moving across the screen. These three sprites are the same sprite object copied three times (so same 3 instances)

    if sprite collides with sprite

          -->Then Destroy one of the sprites

    Or if sprite is overlapping sprite

    ----> Then destroy one of the sprites, not both

    I have tried this:

    Event--> sprite on collision with sprite

         --> pick 1 instance

          Action---> destroy sprite

    This doesn't really work out to well.

  • Example capx

    I think you're missing something in your explanation, because the logic is simple.

    Perhaps your own capx has something you overlooked and you should post it rather than "pseudo code".

  • Example capx

    I think you're missing something in your explanation, because the logic is simple.

    Perhaps your own capx has something you overlooked and you should post it rather than "pseudo code".

    I'm really sorry for not being clear enough

    I didn't explain the problem that good. But I guess the main problem is that when my two sprite objects overlap with one another, both sprite objects are destroyed. And thats because both of these objects are the same sprite object. The reason why its having this issue is because its an endless runner that has kind of like a player recoil feature. So when the player is hit the player is sent flying in the opposite direction, setting all the bullet objects to inverse their speed and causing overlap between the platforms and spawning additional platforms.

    Also I was gonna post my capx, but its for tommorows student contest, and I don't really have the time now to recreate the issue. Right now I'm going over any glitches or bugs I have and am looking for solutions to fix them.

    I think I was able to solve the problem by having the Event: "platform nearest to Player" destroyed as well as when the "platform is on screen" and it seems like it solved my problem. I'll have it tested by others later tonight.

    But I do appreciate the response

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I didn't try it ... but it might work ...

    On collision with player

    -(Invert) Pick Nearest to Player

    -- Destroy

    Cheers ...

  • I didn't try it ... but it might work ...

    On collision with player

    -(Invert) Pick Nearest to Player

    -- Destroy

    Cheers ...

    I don't see the point of inverting it, there's an option that says "furtherest", or am I missing something here?

  • Here , what the event does is that it doesn't pick the nearest to the player and there's where the invert shine , it picks every instance that isn't the nearest to the player ... thus furthest would only pick the furthest instance ...

  • Oh and ... you also should pick all

    Bullet | On collision with player

    • Bullet | Pick All

    -- Bullet | (Invert) Pick Nearest to the player

    --- Destroy

    Cheers ...

  • Here , what the event does is that it doesn't pick the nearest to the player and there's where the invert shine , it picks every instance that isn't the nearest to the player ... thus furthest would only pick the furthest instance ...

    That does sound useful, but you can't invert the "nearest" event

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