javascript - How do I create an HTML message for a mouseConstraint on this cradle? -
this i'm trying work on right now, matter.js library. want use 2 events trigger 2 html messages grabbing ball on left side of cradle "hey grabbed cradle" , when let go, "wow, @ that!".
// matter.js - http://brm.io/matter-js/ // matter module aliases var engine = matter.engine, world = matter.world, body = matter.body, composites = matter.composites, mouseconstraint = matter.mouseconstraint; // create matter.js engine var engine = engine.create(document.body, { render: { options: { showangleindicator: true, showvelocity: true, wireframes: false } } }); // add mouse controlled constraint var mouseconstraint = mouseconstraint.create(engine); world.add(engine.world, mouseconstraint); // add newton's cradle (using composites factory method!) var cradle = composites.newtonscradle(280, 150, 5, 30, 200); world.add(engine.world, cradle); // offset first body in cradle swing body.translate(cradle.bodies[0], { x: 0, y: 0 }); // run engine engine.run(engine);
where @ trying make happen at:
cradle.mouseconstraint=function(){alert("hi")};
for more information, here codepen: http://codepen.io/liabru/pen/abfml
Comments
Post a Comment