cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

Extendable components / sprites without points don't break update #178

Open benwiley4000 opened 8 years ago

benwiley4000 commented 8 years ago

I apologize for including two separate features in one pull request - they ended up that way. I can separate the commits if needed, but they're each fairly small.

  1. Not all sprites necessarily have points or need them, but the engine breaks if Sprites don't have provided points, when it tries to create collision points. I just updated the code so that no collision points are generated if no points exist (this problem will never come up anyway if you're using the 2d module). The change makes simple sprite animations without need for collision detection easy and lightweight.
  2. I made it possible to extend components. They are, after all, classes just like any other, except that they don't have a neat interface for being extended themselves (since they've clearly been intended to just be attached to other objects). The use case that inspired me to code in this feature is wanting to override some elements of platformerControls, without having to duplicate the entire class.

I adapted the existing component creation method to accommodate extension. Pass in the parent as the third argument. You can use the following to create a component called 'endlessRunnerControls' that inherits from 'platformerControls' but overrides the step function:

Q.component('endlessRunnerControls', {
  step: function (dt) {
    ...
  }
}, 'platformerControls');