From 74c7ad07ee3a4b0d3889fd46ac6ce1e49ffe918b Mon Sep 17 00:00:00 2001 From: liabru Date: Mon, 31 Mar 2014 15:35:00 +0100 Subject: [PATCH] updated mobile demo --- demo/js/DemoMobile.js | 69 +++++++++++++++++++++---------------------- demo/mobile.html | 4 +-- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/demo/js/DemoMobile.js b/demo/js/DemoMobile.js index 66f9634..8432878 100644 --- a/demo/js/DemoMobile.js +++ b/demo/js/DemoMobile.js @@ -9,7 +9,8 @@ Composite = Matter.Composite, Composites = Matter.Composites, Common = Matter.Common, - Constraint = Matter.Constraint; + Constraint = Matter.Constraint, + MouseConstraint = Matter.MouseConstraint; var Demo = {}; @@ -26,18 +27,15 @@ demoStart.style.display = 'none'; _engine = Engine.create(canvasContainer, { - positionIterations: 3, - velocityIterations: 2, render: { options: { wireframes: true, - showAngleIndicator: true + showAngleIndicator: true, + showDebug: true } } }); - - _engine.broadphase.current = 'bruteForce'; - + Demo.fullscreen(); setTimeout(function() { @@ -49,16 +47,39 @@ window.addEventListener('deviceorientation', Demo.updateGravity, true); window.addEventListener('touchstart', Demo.fullscreen); window.addEventListener('orientationchange', function() { + Demo.updateGravity(); Demo.updateScene(); Demo.fullscreen(); }, false); }; - if (window.addEventListener) { - window.addEventListener('load', Demo.init); - } else if (window.attachEvent) { - window.attachEvent('load', Demo.init); - } + window.addEventListener('load', Demo.init); + + Demo.mixed = function() { + var _world = _engine.world; + + Demo.reset(); + + World.add(_world, MouseConstraint.create(_engine)); + + var stack = Composites.stack(20, 20, 10, 5, 0, 0, function(x, y, column, row) { + switch (Math.round(Common.random(0, 1))) { + + case 0: + if (Math.random() < 0.8) { + return Bodies.rectangle(x, y, Common.random(20, 40), Common.random(20, 40), { friction: 0.01, restitution: 0.4 }); + } else { + return Bodies.rectangle(x, y, Common.random(80, 120), Common.random(20, 30), { friction: 0.01, restitution: 0.4 }); + } + break; + case 1: + return Bodies.polygon(x, y, Math.round(Common.random(4, 6)), Common.random(20, 40), { friction: 0.01, restitution: 0.4 }); + + } + }); + + World.add(_world, stack); + }; Demo.updateScene = function() { if (!_engine) @@ -128,29 +149,5 @@ World.addBody(_world, Bodies.rectangle(_sceneWidth + offset, _sceneHeight * 0.5, 50.5, _sceneHeight + 0.5, { isStatic: true })); World.addBody(_world, Bodies.rectangle(-offset, _sceneHeight * 0.5, 50.5, _sceneHeight + 0.5, { isStatic: true })); }; - - Demo.mixed = function() { - var _world = _engine.world; - - Demo.reset(); - - var stack = Composites.stack(20, 20, 10, 5, 0, 0, function(x, y, column, row) { - switch (Math.round(Common.random(0, 1))) { - - case 0: - if (Math.random() < 0.8) { - return Bodies.rectangle(x, y, Common.random(20, 40), Common.random(20, 40), { friction: 0.01, restitution: 0.4 }); - } else { - return Bodies.rectangle(x, y, Common.random(80, 120), Common.random(20, 30), { friction: 0.01, restitution: 0.4 }); - } - break; - case 1: - return Bodies.polygon(x, y, Math.round(Common.random(4, 6)), Common.random(20, 40), { friction: 0.01, restitution: 0.4 }); - - } - }); - - World.addComposite(_world, stack); - }; })(); \ No newline at end of file diff --git a/demo/mobile.html b/demo/mobile.html index 2517bc3..7ae4426 100644 --- a/demo/mobile.html +++ b/demo/mobile.html @@ -3,11 +3,11 @@ - + - + Matter.js Physics Engine Mobile Demo