HTML and CSS Reference
In-Depth Information
function
function canvasApp () {
iif ( ! canvasSupport ()) {
return
return ;
}
function
function drawScreen () {
world . Step ( 1 / 60 , 10 , 10 );
world . DrawDebugData ();
world . ClearForces ();
}
theCanvas = document . getElementById ( 'canvasOne' );
context = theCanvas . getContext ( '2d' );
var
var
b2Vec2 = Box2D . Common . Math . b2Vec2
,
b2BodyDef = Box2D . Dynamics . b2BodyDef
,
b2Body = Box2D . Dynamics . b2Body
,
b2FixtureDef = Box2D . Dynamics . b2FixtureDef
,
b2World = Box2D . Dynamics . b2World
,
b2PolygonShape = Box2D . Collision . Shapes . b2PolygonShape
,
b2CircleShape = Box2D . Collision . Shapes . b2CircleShape
,
b2DebugDraw = Box2D . Dynamics . b2DebugDraw ;
var
var world = new
new b2World ( new
new b2Vec2 ( 0 , 10 ), true
true );
var
var numBalls = 50 ;
var
var balls = new
new Array ();
for
for ( var
var i = 0 ; i < numBalls ; i ++ ) {
var
var ballDef = new
new b2BodyDef ;
ballDef . type = b2Body . b2_dynamicBody ;
var
var ypos = ( Math . random () * 8 ) + 1 ;
var
var xpos = ( Math . random () * 14 ) + 1 ;
var
var size = ( Math . random () * . 4 ) + . 2 ;
ballDef . position . Set ( xpos , ypos );
var
var ballFixture = new
new b2FixtureDef ;
ballFixture . density = 10.0 ;
ballFixture . friction = 0.5 ;
ballFixture . restitution = 1 ;
ballFixture . shape = new
new b2CircleShape ( size );
var
var newBall = world . CreateBody ( ballDef )
newBall . CreateFixture ( ballFixture );
balls . push ( newBall );
}
var
var wallDefs = new
new Array ({ x : 8.3 , y : . 03 , w : 8.3 , h : . 03 }, //top
{ x : 8.3 , y : 13.33 , w : 8.3 , h : . 03 },
//bottom
{ x : 0 , y : 6.67 , w : . 03 , h : 6.67 },
//left
{ x : 16.7 , y : 6.67 , w : . 03 , h : 6.67 } );
//right
var
var walls = new
new Array ();
Search WWH ::




Custom Search