mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-12 16:08:50 -05:00
updated mobile demo
This commit is contained in:
parent
b421c38f74
commit
74c7ad07ee
2 changed files with 35 additions and 38 deletions
|
@ -9,7 +9,8 @@
|
||||||
Composite = Matter.Composite,
|
Composite = Matter.Composite,
|
||||||
Composites = Matter.Composites,
|
Composites = Matter.Composites,
|
||||||
Common = Matter.Common,
|
Common = Matter.Common,
|
||||||
Constraint = Matter.Constraint;
|
Constraint = Matter.Constraint,
|
||||||
|
MouseConstraint = Matter.MouseConstraint;
|
||||||
|
|
||||||
var Demo = {};
|
var Demo = {};
|
||||||
|
|
||||||
|
@ -26,18 +27,15 @@
|
||||||
demoStart.style.display = 'none';
|
demoStart.style.display = 'none';
|
||||||
|
|
||||||
_engine = Engine.create(canvasContainer, {
|
_engine = Engine.create(canvasContainer, {
|
||||||
positionIterations: 3,
|
|
||||||
velocityIterations: 2,
|
|
||||||
render: {
|
render: {
|
||||||
options: {
|
options: {
|
||||||
wireframes: true,
|
wireframes: true,
|
||||||
showAngleIndicator: true
|
showAngleIndicator: true,
|
||||||
|
showDebug: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_engine.broadphase.current = 'bruteForce';
|
|
||||||
|
|
||||||
Demo.fullscreen();
|
Demo.fullscreen();
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
@ -49,16 +47,39 @@
|
||||||
window.addEventListener('deviceorientation', Demo.updateGravity, true);
|
window.addEventListener('deviceorientation', Demo.updateGravity, true);
|
||||||
window.addEventListener('touchstart', Demo.fullscreen);
|
window.addEventListener('touchstart', Demo.fullscreen);
|
||||||
window.addEventListener('orientationchange', function() {
|
window.addEventListener('orientationchange', function() {
|
||||||
|
Demo.updateGravity();
|
||||||
Demo.updateScene();
|
Demo.updateScene();
|
||||||
Demo.fullscreen();
|
Demo.fullscreen();
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (window.addEventListener) {
|
window.addEventListener('load', Demo.init);
|
||||||
window.addEventListener('load', Demo.init);
|
|
||||||
} else if (window.attachEvent) {
|
Demo.mixed = function() {
|
||||||
window.attachEvent('load', Demo.init);
|
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() {
|
Demo.updateScene = function() {
|
||||||
if (!_engine)
|
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(_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 }));
|
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -3,11 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1, minimal-ui">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<meta name="robots" content="noindex">
|
<meta name="robots" content="noindex">
|
||||||
<script type="text/javascript" src="./js/lib/matter.js"></script>
|
<script type="text/javascript" src="./js/lib/matter-dev.js"></script>
|
||||||
<script type="text/javascript" src="./js/DemoMobile.js"></script>
|
<script type="text/javascript" src="./js/DemoMobile.js"></script>
|
||||||
<link rel="stylesheet" href="./css/style.css" type="text/css">
|
<link rel="stylesheet" href="./css/style.css" type="text/css">
|
||||||
<title>Matter.js Physics Engine Mobile Demo</title>
|
<title>Matter.js Physics Engine Mobile Demo</title>
|
||||||
|
|
Loading…
Reference in a new issue