From 4051823f5f8d6a4f5bbddb2111d9331a14f43994 Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 30 Jul 2014 17:27:42 +0100 Subject: [PATCH] added Demo.compositeManipulation --- demo/dev.html | 1 + demo/js/Demo.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/demo/dev.html b/demo/dev.html index 63bcb674..a5654a0e 100644 --- a/demo/dev.html +++ b/demo/dev.html @@ -38,6 +38,7 @@

Matter.js Demo (Dev. Build)

+ diff --git a/demo/js/Demo.js b/demo/js/Demo.js index fc0304d0..e837b0ac 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -293,6 +293,48 @@ renderOptions.showCollisions = true; }; + Demo.compositeManipulation = function() { + var _world = _engine.world; + + Demo.reset(); + + var stack = Composites.stack(200, 200, 4, 4, 0, 0, function(x, y, column, row) { + return Bodies.rectangle(x, y, 40, 40); + }); + + World.add(_world, stack); + + _world.gravity.y = 0; + + _sceneEvents.push( + Events.on(_engine, 'tick', function(event) { + var time = _engine.timing.timestamp; + + Composite.translate(stack, { + x: Math.sin(time * 0.001) * 2, + y: 0 + }); + + Composite.rotate(stack, Math.sin(time * 0.001) * 0.01, { + x: 300, + y: 300 + }); + + var scale = 1 + (Math.sin(time * 0.001) * 0.01); + + Composite.scale(stack, scale, scale, { + x: 300, + y: 300 + }); + }) + ); + + var renderOptions = _engine.render.options; + renderOptions.wireframes = false; + renderOptions.showAxes = true; + renderOptions.showCollisions = true; + }; + Demo.views = function() { var _world = _engine.world;