1
\$\begingroup\$

So, I've got a game in the pipeline.

Game environment screenshot

There's a problem, tho. After a couple of weeks of lunch hours incrementally adding stuff, it's regularly using up 100% of my CPU and slowing down. I don't really know how to go about debugging what part of the application is using all those resources.

I've particularly noticed that if you restart the map, (by pressing r or falling in water) a few times, the resource issue gets much worse.

Possible issues:

It's loading quite a lot of assets in /js/loader.js

The collision method on the platforms group (interaction.landOnPlatform) is being called many times a second. Although that steps over most functionality when 3 flags are false.

  landOnPlatform: function (player, platform) {
    if (platform.breakable) {
      interaction.breakPlatform(player, platform);
    }
    if (player.slamming) {
      player.slamming = false;
      action.shakeCamera();
    }
    if (player.jumping) {
      if (player.body.onFloor()) {
        audio.play_land();
        player.jumping = false;
      } else if (player.body.onCeiling()) {
        audio.play_sfx('head_block')
      }
    }
  },

There's also quite a lot of objects being created by map.draw (reading a file from /maps/

Because of the repeated reloading exacerbating the issue, could it be that this block in map.draw is not removing all the objects and their interactions from memory?

  platforms.clear(true, true);
  doors.clear(true, true);
  water.clear(true, true);
  keys.clear(true, true);
  springs.clear(true, true);
  sliders.clear(true, true);
  slider_tracks.clear(true, true);

The full code base is here:

https://github.com/AJFaraday/night_and_day

I'm really looking for advice on how to find this issue, or more information on exactly what and where the issue is.

Please be kind, I'm a ruby developer playing in JavaScript, so this isn't my first language.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Have you tried profiling it? You can use Chrome dev tools for that. \$\endgroup\$ May 30, 2019 at 12:01
  • \$\begingroup\$ @Pritilender I wasn’t aware of it, but sounds like it could be really helpful here. Thanks! \$\endgroup\$
    – AJFaraday
    May 30, 2019 at 12:33
  • \$\begingroup\$ I haven't yet solved this problem, but I did find this discussion of Phaser 3 performance. Saving for future investigation: html5gamedevs.com/topic/… \$\endgroup\$
    – AJFaraday
    May 31, 2019 at 8:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.