11var Example = Example || { } ;
22
33Example . ballPool = function ( ) {
4+ Matter . use (
5+ 'matter-wrap'
6+ ) ;
7+
48 var Engine = Matter . Engine ,
59 Render = Matter . Render ,
610 Runner = Matter . Runner ,
@@ -21,8 +25,8 @@ Example.ballPool = function() {
2125 element : document . body ,
2226 engine : engine ,
2327 options : {
24- width : Math . min ( document . body . clientWidth , 1024 ) ,
25- height : Math . min ( document . body . clientHeight , 1024 ) ,
28+ width : Math . min ( document . documentElement . clientWidth , 800 ) ,
29+ height : Math . min ( document . documentElement . clientHeight , 600 ) ,
2630 showAngleIndicator : true
2731 }
2832 } ) ;
@@ -35,20 +39,18 @@ Example.ballPool = function() {
3539
3640 // add bodies
3741 World . add ( world , [
38- Bodies . rectangle ( 400 , 600 , 800 , 50.5 , { isStatic : true } ) ,
39- Bodies . rectangle ( 800 , 300 , 50 , 600 , { isStatic : true } ) ,
40- Bodies . rectangle ( 0 , 300 , 50 , 600 , { isStatic : true } )
42+ Bodies . rectangle ( 400 , 600 , 1200 , 50.5 , { isStatic : true } )
4143 ] ) ;
4244
43- var stack = Composites . stack ( 100 , 50 , 10 , 8 , 10 , 10 , function ( x , y ) {
45+ var stack = Composites . stack ( 100 , 0 , 10 , 8 , 10 , 10 , function ( x , y ) {
4446 return Bodies . circle ( x , y , Common . random ( 15 , 30 ) , { restitution : 0.6 , friction : 0.1 } ) ;
4547 } ) ;
4648
4749 World . add ( world , [
4850 stack ,
49- Bodies . polygon ( 200 , 560 , 3 , 60 ) ,
50- Bodies . polygon ( 400 , 560 , 5 , 60 ) ,
51- Bodies . rectangle ( 600 , 560 , 80 , 80 )
51+ Bodies . polygon ( 200 , 460 , 3 , 60 ) ,
52+ Bodies . polygon ( 400 , 460 , 5 , 60 ) ,
53+ Bodies . rectangle ( 600 , 460 , 80 , 80 )
5254 ] ) ;
5355
5456 // add mouse control
@@ -69,7 +71,20 @@ Example.ballPool = function() {
6971 render . mouse = mouse ;
7072
7173 // fit the render viewport to the scene
72- Render . lookAt ( render , Composite . allBodies ( world ) ) ;
74+ Render . lookAt ( render , {
75+ min : { x : 0 , y : 0 } ,
76+ max : { x : 800 , y : 600 }
77+ } ) ;
78+
79+ // wrapping using matter-wrap plugin
80+ var allBodies = Composite . allBodies ( world ) ;
81+
82+ for ( var i = 0 ; i < allBodies . length ; i += 1 ) {
83+ allBodies [ i ] . wrap = {
84+ min : { x : render . bounds . min . x - 100 , y : render . bounds . min . y } ,
85+ max : { x : render . bounds . max . x + 100 , y : render . bounds . max . y }
86+ } ;
87+ }
7388
7489 // context for MatterTools.Demo
7590 return {
0 commit comments