HTML and CSS Reference
In-Depth Information
When you need to seek help on Box2D, the original C++ Box2D website or
even the documentaion of the Flash ediion helps a lot. You can learn from
there and apply the JavaScript syntax in Box2DWeb from the following URLs:
F http://www.box2d.org/manual.html
F http://www.box2dflash.org/docs/2.1a/
Shooting the ball
In this task, we create a hoop and allow the player to throw the ball by clicking the
mouse buton. The ball may or may not pass through the hoop based on the throwing
angle and power.
Prepare for lift off
We remove the two bodies that were created in the first task. Those two bodies were just
an experiment and we don't need them anymore.
Engage thrusters
In the following steps, we will create the core part of this project—shooing the ball:
1. We will create a hoop and spawn a ball in the physics world. We create a funcion
for these two tasks:
physics.createLevel = function() {
this.createHoop();
// the first ball
this.spawnBall();
};
2. We are going to spawn many balls. We define the following method for this task.
In this task, we hardcode the posiion, ball size, and ixture properies. The ball is
spawned as a staic object unil the player throws the ball out:
physics.spawnBall = function() {
var positionX = 300;
var positionY = 200;
var radius = 13;
var bodyDef = new b2BodyDef;
var fixDef = new b2FixtureDef;
 
Search WWH ::




Custom Search