Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7176579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:32:16+00:00 2026-05-28T16:32:16+00:00

I am working on a CoffeeScript game engine for Html5 canvas. I came up

  • 0

I am working on a CoffeeScript game engine for Html5 canvas. I came up with the “cool” idea to utilize mixins after I checked a very neat CoffeeScript implementation. I thought, it may be a very cool idea to reduce the various hierarchy of objects that game objects usually provide, by developing a set of mixin-based components, each of which has a very specific functionality. Then, when developing an actual game, one could build unique game objects on the fly by basically starting from one component and mixing it with a bunch of other components. This reduces the hierarchies and allows for frequent changes.

Then I thought about the possible collisions that might come up, for example having a few components define a method with the same signature. Now, I am not as excited as before.

What should I do? Is this a good way? I still like it, especially because of JS’ underlying prototype mechanism, which allows for such an easy way to combine stuff on the fly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:32:17+00:00Added an answer on May 28, 2026 at 4:32 pm

    You’re talking about an entity component system. There are a couple written in JS; the most popular is Crafty, which is big but worth looking at. I recently wrote one in CoffeeScript (just for funsies; will probably never release it).

    A few notes about collisions:

    So first, the problem may be worse than you think: collisions will happen if two methods have the same name; JS doesn’t differentiate function signatures. It also might not be so bad: why don’t you just create a namespacing convention, where each behavior (meaning method) is named after the component it belongs to, like burnable_burn?

    To take a step back though, mixins aren’t the only way to build this – behaviors (i.e. things a component can do) don’t have to be methods at all. The motivating question I ask is, how do you trigger a behavior? For example, you might do:

    if entity.hasComponent "burnable" #hasComponent provided by your framework
      entity.burn()
    

    But that doesn’t sound right to me; it creates a weird coupling between what’s happening in your game and what components you have, and it’s awkward to check if your entities implement the relevant component. Instead, I’d like behaviors to be listeners on events:

    entity.send("applySeriousHeat") #triggers whatever behaviors are there
    

    And then have your component do whatever it needs to do. So when you add a component to an entity, it registers listeners to events. Maybe it looks like (just sketching):

    register: (entity) -> #called when you add a component to an entity
      entity.listen "applySeriousHeat", -> #thing I do when this event is sent to me
        #do burnination here
    

    To bring that point home, if you do that, you don’t care about collisions, because your behaviors don’t have names. In fact, you want “collisions”; you want the ability to have more than one component respond to the same event. Maybe it burns and melts at the same time?

    In practice, I used both setups together. I made entity.addComponent mix in the component’s functions, since it’s occasionally convenient to just call a behavior as a method. But mostly, the components declare listeners that call those methods, which helped with decoupling and reduced the awkwardness of having to use scoped names, since I don’t call them directly in most cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with printf in a bash script, adding no spaces after \n does not
I'm trying to get the nodeunit module working within a coffeescript project but can't
I'm working through Trevor Burnham's CoffeeScript book and I've run into a weird puzzle
I feel quite excited about HAML and CoffeeScript and am working on tutorial showing
I have a working coffeescript/backbone idiom that looks like this: SidebarWidgets = ((() ->
Working with Rails 3.1 (rc5), and I'm noticing that any coffeescript file I include
I'm working on a project built entirely in node.js and coffeescript. I want to
It's not working for some reason (in coffeescript) afunction = () -> window.clearTimeout(timeoutID) $(.x).text(#{message}).addClass(y)
I was able to get jQuery autocomplete working in CoffeeScript just fine, but when
Working on rewriting the front-end of my site in Coffeescript. I understand how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.