How do I destroy a object once it enters then leaves layout?

Just started using Construct 2? Post your questions here

Post » Fri Apr 03, 2015 9:26 pm

An object may have a bullet behavior or physics behavior that uses impulse to move into the layout. My problem is that I don't know how to destroy something that enters a layout and once it leaves, to destroy it.

I realize I could use the fade behavior but for many of the objects within my game, they need to have full opacity, although I have found the fade have found the fade behavior to be useful for certain objects. Elongating the fade out time isn't useful because I will usually have objects being destroyed once outside layout to prevent performance issues.

Of course I've thought about using the Destroy Outside Layout behavior but an object will be destroyed if it's coming from outside the layout.

Here's a capx of what I mean: https://www.dropbox.com/s/9ij2kzf7zwz02 ... .capx?dl=0

The Balls coming from the left are bullet, the balls coming from above are impulsed. Once they exit the layout, how do I destroy them?
Risk Rocket now available on Google Play
Image
B
35
S
15
G
6
Posts: 337
Reputation: 6,275

Post » Fri Apr 03, 2015 9:51 pm

Try setting the initial state of Destroy Outside Layout to disabled, and enable it later on.
B
5
Posts: 16
Reputation: 259

Post » Fri Apr 03, 2015 10:45 pm

The Destroy Outside Layout behavior does not have any properties.
Risk Rocket now available on Google Play
Image
B
35
S
15
G
6
Posts: 337
Reputation: 6,275

Post » Sat Apr 04, 2015 10:21 am

how about using a booelan,
then if that object Is on screen, set it's value to true.
then when it is not on screen, and that boolean is true, destroy it.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
61
S
14
G
2
Posts: 286
Reputation: 6,521

Post » Sun Apr 05, 2015 10:11 pm

I think I've got. I used a Number Instance Variable in place of Boolean, and enlarged the window size to show that the objects are indeed destroying once they leave the layout.

I Used the Outside layout condition instead of On-Screen simply because my game may not have everything on screen at a time.

Here's the update: https://www.dropbox.com/s/cmw045j0x5pef ... .capx?dl=0
Risk Rocket now available on Google Play
Image
B
35
S
15
G
6
Posts: 337
Reputation: 6,275

Post » Sat Jul 04, 2015 6:55 pm

Hello. Its an old post but i where looking through them anyways :D

You dont need any variables.
You dont need "destroy outside layout"

On start - disable gravity and destroy the ball and bullet C2 needs (Not need i would say, since you could place them outside the margin)
Add a margin and set up your balls and bullet, that if they exceed the margin, destroy them.
Spawn bullets and balls at a interval - in the margin.

Yay!

The Coding You should move the "Physics force" to a seperay event, that only apply´s when a ball is created - otherwise its gonna do it every 0.5 two times :D just realised now when i where looking at the image. Woops.

Image

The Capx
http://www.designfremtid.dk/BallsAndBullets.capx
B
16
S
8
G
1
Posts: 153
Reputation: 2,548


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest