Howto: Self-fading / killing / modifying objects!

About advanced scenes, and the Thyme scripting language used in Algodoo.

Howto: Self-fading / killing / modifying objects!

Postby pixartist » Wed Feb 10, 2010 5:32 pm

I found that if you spawn objects that modify itself on the fly, they tend only to work one at a time...but now I found a workaround that should work for any dynamic, self-modifying objects:

Code: Select all
scene.my.summonBall := (b_pos, b_vel,b_collideSet, b_selfcollide, b_density, b_radius, b_cake, b_border, b_color, b_airFric, b_lifetime)=>{Scene.addCircle {
collideWater := false;
mark := sim.time;
color := {[b_color(0), b_color(1), b_color(2), 1-(((sim.time - mark) / b_lifetime))]};
drawCake := b_cake;
collideSet := b_collideSet;
pos := b_pos;
radius := b_radius;
density := {(sim.time - mark) < b_lifetime ? {b_density} : {NaN}};
heteroCollide := b_selfcollide;
velocity := b_vel;
drawBorder := b_border;
airFrictionMult := b_airFric;
opaqueBorders := false;
};
// redefine the onHit event of the triggering object here! e.g.:
onLaserHit := (e)=>{scene.my.summonBall(e.pos, [0, 0], 0, true, 0.05, 0.05, false, true, [0, 1, 0, 1], 100, 2)};
}

now put the same code as below the comment into your laser:

onLaserHit := (e)=>{scene.my.summonBall(e.pos, [0, 0], 0, true, 0.05, 0.05, false, true, [0, 1, 0, 1], 100, 2)};

now the laser will spawn onHit and every single object will work!
have fun


btw i think density = NaN causes a memory leak, so be aware...
Image
pixartist
 
Posts: 65
Joined: Wed Sep 02, 2009 5:30 pm

Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 7 guests