1
\$\begingroup\$

Okay, so I've started making a game using Khan Academy's Processing JavaScript, and I'm trying to delag it a bit since the framerate is very shaky. So, I've taken the advice of someone, and they told me instead of new object_name(), I could instead use something like object_name.create() by having this code:

Object.constructor.prototype.create = function() {
    var obj = Object.create(this.prototype);
    this.apply(obj, arguments);
    return obj;
};

So, I'm assuming it's helping since the framerate improved a bit, but not at all that much. I've been using a lot of OOP, and people have told me that Khan Academy's memory is acting weird, so it's not as good to use OOP, but I'm used to using it, so I'd like to see what kind of things there could be to help improve my program in framerate. I'm planning to check if the NPCs and enemies are in range, then draw them, but I'm not sure if this would help, because I'm not very familiar with the computers and how fast they would run certain things. Thank you.

For reference, this is my game Quests of a Warrior

This is the comment that someone posted that I happened to see, and that's why I used the object_name.create() for now. Discussion post (expand_key will lead you there)

If you are unfamiliar with Processing JavaScript, you can go to the documentation, although it doesn't include much (Khan Academy version). You'll find it here, but you can also glance at the real Processing JavaScript (notice that some can't be used for Khan Academy purposes) here

EDIT: I've figured out that you can do object pooling! The method shown here uses gEntityObjectPool. Is this in pure JavaScript?

\$\endgroup\$
9
  • 2
    \$\begingroup\$ If you think you have issues with "creating objects", I would probably look at how many objects you create (or your creation pattern), rather than how you create the object. \$\endgroup\$
    – Vaillancourt
    Apr 19, 2021 at 1:46
  • 3
    \$\begingroup\$ There are about a hundred tips one can give regarding how to improve the performance of a JavaScript application. This makes this question far too broad for the format of this website. But if Khan Academy didn't tell you about the JavaScript Profiler included in most web browsers, then I would recommend you to familiarize yourself with it. Because it can tell you which parts of your game's code are the real performance killers. \$\endgroup\$
    – Philipp
    Apr 19, 2021 at 8:23
  • \$\begingroup\$ @Vaillancourt, I've been using LOTS of objects. \$\endgroup\$
    – Potato
    Apr 19, 2021 at 14:15
  • \$\begingroup\$ @Philipp , where can I start to learn that, though? \$\endgroup\$
    – Potato
    Apr 19, 2021 at 14:16
  • 1
    \$\begingroup\$ If you create and destroy a lot of objects often, you might want to check the concept of object pooling. If you have lots of objects, all the time, maybe you have too many, period, and you need to review your game design (you'll need to profile). \$\endgroup\$
    – Vaillancourt
    Apr 19, 2021 at 15:15

0

Browse other questions tagged .