How to delete objects using a script
6 posts • Page 1 of 1
How to delete objects using a script
At first, I was having trouble with figuring out how to delete objects with a script. After some experimentation, it seems that the perfect way to do it is to set an object's timeToLive property equal to 0.
I crossed this problem when I decided to program a star to absorb the mass of any planetary object that hit it, and the code for the star's onCollide event looks like this:
As you can see, I'm deleting the other circle's instance by eliminating all the time it has to live.
Anyway, I hope this is useful to anyone who's new to programming with Algodoo! (I'm new myself)
I crossed this problem when I decided to program a star to absorb the mass of any planetary object that hit it, and the code for the star's onCollide event looks like this:
- Code: Select all
(e)=>{
radius = math.sqrt(radius ^ 2 + (e.other.density / density) * e.other.radius ^ 2);
e.other.timeToLive = 0
}
As you can see, I'm deleting the other circle's instance by eliminating all the time it has to live.
Anyway, I hope this is useful to anyone who's new to programming with Algodoo! (I'm new myself)
- sOvr9000
- Posts: 1
- Joined: Tue Apr 21, 2015 1:07 am
Re: How to delete objects using a script
scene.removeEntity()
Dream of Algodoo as game development engine...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: How to delete objects using a script
e.other.density = 0 is my typical way
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
Re: How to delete objects using a script
FRA32 wrote:e.other.density = 0 is my typical way
Don't use that, it causes a memory leak as objects aren't removed from the scene properly, they're just effectlvly set to an invalid state and not cleared from the memory.
We got scene.removeEntity() for a reason
When asking for help, READ THE STICKIES!
- electronicboy
- Posts: 1694
- Joined: Mon Aug 31, 2009 6:18 pm
Re: How to delete objects using a script
Or just use killers. I mean, setting a killer on an object is just the nooby way of typing {scene.removeEntity(e.other)} into onCollide...
(/)(°,,,°)(/)
-
pnvv - Posts: 670
- Joined: Tue Aug 26, 2014 11:46 pm
- Location: Disunited States of America
6 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 9 guests