mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-26 13:49:01 -05:00
added render.options.showMousePosition
This commit is contained in:
parent
e0a6de0971
commit
e191d44857
2 changed files with 23 additions and 1 deletions
|
@ -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', '');
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue