Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

benwiley4000
Copy link
Contributor

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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant