Commit f4239e35 authored by Raphaël Bastide's avatar Raphaël Bastide

Auto pause avoid memory leaks

parent cdaa1b17
......@@ -28,10 +28,13 @@ body {
main{
display: flex;
}
.paused canvas{
filter:grayscale(1);
}
canvas{
border-radius: 20px;
margin-top: 30px;
transition: all .4s linear;
}
aside, main{
position: relative;
......@@ -84,6 +87,7 @@ a{color: inherit;}
right:10px;
bottom:10px;
width:44px;
z-index: 300;
text-align: center;
padding: 5px 10px;
border-radius: 20px;
......
......@@ -25,9 +25,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="152.42759"
inkscape:cy="100.27977"
inkscape:zoom="0.35"
inkscape:cx="1497.3301"
inkscape:cy="392.05853"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
......
......@@ -15,7 +15,10 @@
version="1.1"
id="svg8"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="pointer.svg">
sodipodi:docname="pointer.svg"
inkscape:export-filename="/home/raphael/Documents/WORK/PERSO/burl/img/pointer.png"
inkscape:export-xdpi="24.239979"
inkscape:export-ydpi="24.239979">
<defs
id="defs2" />
<sodipodi:namedview
......@@ -25,9 +28,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-190.77746"
inkscape:cy="-63.436134"
inkscape:zoom="1.979899"
inkscape:cx="56.63128"
inkscape:cy="78.538217"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
......@@ -70,87 +73,10 @@
id="layer1"
transform="translate(163.43963,267.89194)">
<path
style="opacity:1;vector-effect:none;fill:#ffff00;fill-opacity:1;stroke:none;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
style="opacity:1;vector-effect:none;fill:#ff5555;fill-opacity:1;stroke:none;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -159.23514,-266.25819 c -0.32931,0.009 -0.61018,0.0589 -0.80873,0.15813 -2.94506,1.47254 -2.19597,5.95851 -1.36013,10.31152 0.46168,2.4044 -0.28773,5.84047 3.01791,7.01663 l -1.31724,-0.0103 c -1.10109,1.90692 0.0839,5.08615 1.53479,8.4739 l -0.31626,0.47749 c -2.20725,2.57377 -3.24817,5.2582 -2.759,7.7587 0.43126,2.20442 8.53611,13.23605 13.68495,14.87609 2.00063,2.93605 10.0779,0.36876 13.55473,-0.11937 2.30925,-0.32421 3.90092,-1.8569 4.31808,-3.66334 0.18101,-0.78381 0.17024,-2.18558 0.0289,-3.00963 1.86918,-5.10486 1.89451,-9.6521 0.56018,-14.89729 l -0.005,-0.003 c 0.34017,-1.26388 0.40545,-2.56194 0.0811,-3.62148 -1.03412,-3.37836 -3.07031,-6.64841 -5.88751,-7.52565 -4.18025,-1.04507 -9.13159,-1.2754 -13.66221,-0.62063 -0.38539,-1.22226 -2.924,-5.77447 -4.3093,-8.78913 l -0.03,0.24081 c -0.0162,-2.61046 -1.84633,-5.29466 -2.0314,-5.57227 -0.52695,-0.79042 -2.86678,-1.51951 -4.2938,-1.48105 z"
id="path859"
inkscape:connector-curvature="0" />
<g
id="g839"
transform="matrix(0.99238553,0,0,0.9923411,-0.15116588,-1.9830296)"
style="stroke-width:1.00769544"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998">
<circle
inkscape:export-ydpi="57.439999"
inkscape:export-xdpi="57.439999"
r="25.796873"
cy="-258.91852"
cx="-19.85257"
style="opacity:1;vector-effect:none;fill:#ec82be;fill-opacity:1;stroke:#000000;stroke-width:1.3330971;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:fill markers stroke"
id="path817" />
</g>
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -23.821319,-276.49441 c -8.691206,-0.16604 -14.174107,8.91828 -14.174107,16.81994"
id="path73"
inkscape:connector-curvature="0"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -28.546021,-244.74441 c 4.528188,5.95666 15.867539,5.85171 19.5077337,0.37387"
id="path75"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -5.8674498,-250.22506 c 4.3845195,-7.10364 7.2251894,-17.62717 -2.834822,-22.48958"
id="path77"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -22.876379,-262.13131 c -3.185146,0.10429 -6.908,6.83592 -4.91369,9.82738 0.929543,1.39432 3.321585,0.90101 4.346726,2.26786"
id="path79"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccc"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -11.537094,-264.21018 c -2.581545,-3.38225 -6.902014,-8.24164 -11.339284,-4.91369"
id="path81"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -37.7539,-255.72027 c 0.610557,2.81962 2.812531,4.7459 3.987307,7.02025"
id="path83"
inkscape:connector-curvature="0"
inkscape:transform-center-x="-3.6463205"
inkscape:transform-center-y="3.4362163"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -17.017747,-249.46911 c 5.5631,-1.53936 6.236607,-5.31816 6.236607,-10.39435"
id="path85"
inkscape:connector-curvature="0"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#333333;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -20.041558,-278.38429 c 2.490497,0.13379 5.470427,1.37227 6.99256,3.40178"
id="path87"
inkscape:connector-curvature="0"
inkscape:export-xdpi="7.7399998"
inkscape:export-ydpi="7.7399998" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:2.5;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -158.42376,-249.14998 c -3.30564,-1.17616 -2.55643,-4.61226 -3.01811,-7.01666 -0.83584,-4.35301 -1.58492,-8.83887 1.36014,-10.3114 1.05894,-0.52947 4.45412,0.35009 5.10267,1.32292 0.21631,0.32446 2.68195,3.93666 1.8693,6.87596 m 0.19176,-1.54458 c 1.50145,3.26743 4.36454,8.35095 4.36454,9.03171"
......@@ -208,5 +134,10 @@
id="g886"
style="fill:#ffff00"
transform="translate(-38.931548,44.60119)" />
<path
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#000000;stroke-width:1.79999995;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:0.98431373;paint-order:fill markers stroke"
d="m -147.13619,-239.15251 c 3.82257,-0.92525 7.50851,-1.19647 11.22532,-0.26727"
id="path925"
inkscape:connector-curvature="0" />
</g>
</svg>
......@@ -32,7 +32,7 @@ function launch(units, isRefresh){
timeScaleTarget = 1,
zoom = 500,
zoomTarget = 500,
counterBonus = counterTime = counterZoom = 0,
counterBonus = counterTime = counterZoom = collisionBuffer = 0,
bulletTime, bonusTime, isTeleported, checkPoint, lastCollided = false
if (debug) {
......@@ -186,6 +186,12 @@ function launch(units, isRefresh){
// Render after each Tick
Events.on( engine, 'afterTick', (e)=> {
if (collisionBuffer >= 1000) {
togglePause()
collisionBuffer = 0
}else {
collisionBuffer +=1
}
if (bulletTime) {
engine.timing.timeScale = .5
zoom += (zoomTarget - zoom) * 0.05;
......@@ -220,9 +226,10 @@ function launch(units, isRefresh){
// Handling collisions
Events.on(engine, 'collisionStart', function(event) {
collisionBuffer = 0
var pairs = event.pairs;
for (var i = 0, j = pairs.length; i != j; ++i) {
var pair = pairs[i];
var pair = pairs[i]
var b1 = pair.bodyB
var b2 = pair.bodyA // can differ accordins to World.add order
var col = b2.render.fillStyle
......@@ -269,8 +276,10 @@ function launch(units, isRefresh){
});
World.add(world, [ball]);
pauseBtn.addEventListener('click',function(){
togglePause()
})
function togglePause(){
if (body.classList.contains('paused')) {
body.classList.remove('paused')
Render.run(render);
......@@ -280,6 +289,5 @@ function launch(units, isRefresh){
Render.stop(render);
Runner.stop(runner, engine);
}
})
}
} // end launch()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment