From 10afaea8bc6623111048cc12fe3fe83229cf295c Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 8 Dec 2021 23:53:12 +0000 Subject: [PATCH] change raycasting example events to enable use in tests --- examples/raycasting.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/raycasting.js b/examples/raycasting.js index 4e512c9..347f4de 100644 --- a/examples/raycasting.js +++ b/examples/raycasting.js @@ -68,14 +68,21 @@ Example.raycasting = function() { Bodies.rectangle(0, 300, 50, 600, { isStatic: true }) ]); + var collisions, + startPoint = { x: 400, y: 100 }; + + Events.on(engine, 'afterUpdate', function() { + var mouse = mouseConstraint.mouse, + bodies = Composite.allBodies(engine.world), + endPoint = mouse.position || { x: 100, y: 600 }; + + collisions = Query.ray(bodies, startPoint, endPoint); + }); + Events.on(render, 'afterRender', function() { var mouse = mouseConstraint.mouse, context = render.context, - bodies = Composite.allBodies(engine.world), - startPoint = { x: 400, y: 100 }, - endPoint = mouse.position; - - var collisions = Query.ray(bodies, startPoint, endPoint); + endPoint = mouse.position || { x: 100, y: 600 }; Render.startViewTransform(render);