HTML and CSS Reference
In-Depth Information
context.beginPath();
context.moveTo(partA.x, partA.y);
context.lineTo(partB.x, partB.y);
context.stroke();
var ax = dx * springAmount,
ay = dy * springAmount;
partA.vx += ax / partA.mass;
partA.vy += ay / partA.mass;
partB.vx -= ax / partB.mass;
partB.vy -= ay / partB.mass;
}
}
Because this cuts down the overall effect of the spring, set springAmount to something small like 0.0005.
You can see the effect in Figure 12-6.
Figure 12-6. One more for the road
Aside from the nodes just looking impressive, imagine all of the game scenarios you could build with them.
You might want to add in the spaceship from earlier chapters, and make it avoid the nodes. That would be
a nice challenge!
 
Search WWH ::




Custom Search