superpowers / superpowers-game

:video_game: Make 2D and 3D games in live collaboration with Superpowers
http://superpowers-html5.com/
Other
402 stars 93 forks source link

Can't subclass Sup.Behavior? #149

Open GaetanRole opened 8 years ago

GaetanRole commented 8 years ago

Hi,

Whenever I try to subclass Sup.Behavior I get an error like this one:

capture du 2016-10-13 10-43-54

Is this not supported? I think it can be very useful to factor some common logic.

Here is my setup:

abstract class AObstacleBehavior extends Sup.Behavior {  
  public someMethod() {  
    Sup.log("Hey, I'm a parent method!");  
  }  
}  
class HighObstacleBehavior extends AObstacleBehavior {
  awake() {
  }

  update() {
  }
}
Sup.registerBehavior(HighObstacleBehavior);
bilou84 commented 8 years ago

The script hierarchy matters in Superpowers so your AObstacleBehavior must be defined before the HighObstacleBehavior. Looks like TypeScript doesn't throw an error in this case because it's a class. Not sure what we could/should do about it. Any idea @elisee?

elisee commented 8 years ago

If the classes are in the same file, then there will be an error:


// TypeScript complains here
class B extends A {

}

abstract class A {

}

Not sure why we don't get errors when they are in different files. Maybe we have to tell the TypeScript compiler in which order the files will be concatenated, if that's possible?