diff --git a/demo/js/Demo.js b/demo/js/Demo.js index 8b260e7..56f0fd3 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -64,6 +64,9 @@ demo.mouseConstraint = MouseConstraint.create(demo.engine); World.add(demo.engine.world, demo.mouseConstraint); + // pass mouse to renderer to enable showMousePosition + demo.engine.render.mouse = demo.mouseConstraint.mouse; + // get the scene function name from hash if (window.location.hash.length !== 0) demo.sceneName = window.location.hash.replace('#', '').replace('-inspect', ''); diff --git a/src/render/Render.js b/src/render/Render.js index f2ee31a..ce23bfd 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -35,6 +35,7 @@ var Grid = require('../collision/Grid'); controller: Render, element: null, canvas: null, + mouse: null, options: { width: 800, height: 600, @@ -58,7 +59,8 @@ var Grid = require('../collision/Grid'); showShadows: false, showVertexNumbers: false, showConvexHulls: false, - showInternalEdges: false + showInternalEdges: false, + showMousePosition: false } }; @@ -226,6 +228,9 @@ var Grid = require('../collision/Grid'); if (options.showVertexNumbers) Render.vertexNumbers(engine, bodies, context); + if (options.showMousePosition) + Render.mousePosition(engine, render.mouse, context); + Render.constraints(constraints, context); if (options.showBroadphase && engine.broadphase.controller === Grid) @@ -592,6 +597,20 @@ var Grid = require('../collision/Grid'); } }; + /** + * Renders mouse position. + * @private + * @method mousePosition + * @param {engine} engine + * @param {mouse} mouse + * @param {RenderingContext} context + */ + Render.mousePosition = function(engine, mouse, context) { + var c = context; + c.fillStyle = 'rgba(255,255,255,0.8)'; + c.fillText(mouse.position.x + ' ' + mouse.position.y, mouse.position.x + 5, mouse.position.y - 5); + }; + /** * Draws body bounds * @private