Destroying all sprite instances except 1

Get help using Construct 2

Post » Thu Apr 04, 2013 11:59 pm

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.
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Fri Apr 05, 2013 12:10 am

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".
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Apr 05, 2013 1:03 am

[QUOTE=Kyatric] 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".[/QUOTE]

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 responseretrodude2013-04-05 01:05:39
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Fri Apr 05, 2013 2:04 am

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

On collision with player
-(Invert) Pick Nearest to Player
-- Destroy

Cheers ...Whiteclaws2013-04-05 02:13:01
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Fri Apr 05, 2013 2:22 am

[QUOTE=Whiteclaws] I didn't try it ... but it might work ...

On collision with player
-(Invert) Pick Nearest to Player
-- Destroy

Cheers ...[/QUOTE]

I don't see the point of inverting it, there's an option that says "furtherest", or am I missing something here?
B
18
S
4
G
3
Posts: 436
Reputation: 4,801

Post » Fri Apr 05, 2013 2:34 am

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 ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Fri Apr 05, 2013 2:49 am

Oh and ... you also should pick all

Bullet | On collision with player
- Bullet | Pick All
-- Bullet | (Invert) Pick Nearest to the player
--- Destroy

Cheers ...
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Fri Apr 05, 2013 3:58 am

[QUOTE=Whiteclaws] 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 ...[/QUOTE]

That does sound useful, but you can't invert the "nearest" event
B
18
S
4
G
3
Posts: 436
Reputation: 4,801


Return to How do I....?

Who is online

Users browsing this forum: spcsmrf and 26 guests