playif / play_phaser

A Dart port for Phaser 2D game engine.
MIT License
71 stars 13 forks source link

Can't use State subclass in different file #18

Closed derrick56007 closed 9 years ago

derrick56007 commented 9 years ago

I understand that in the example of the readme you made a subclass of State, but when I attempt to separate the subclass into a different file, the error of "Exception: type 'TestState' is not a subtype of type 'State' of 'state'" comes up. I do not know if that's intentional or if it's because of my limited knowledge of dart.

went from this (one class only), it works

main() {
  Game game = new Game(800, 480, WEBGL, '', new TestState());
}

class TestState extends State {
  //the methods go here
}

to (2 files) not working for me

(Test.dart)

import 'TestState.dart';
main() {
  Game game = new Game(800, 480, WEBGL, '', new basic_01_load_an_image());
}

(TestState.dart)

class TestState extends State {
  //the methods go here
}
playif commented 9 years ago

Hi @TheSneakyNarwhal In the second scenario, the 'basic_01_load_an_image' should be replaced by 'TestState'.

derrick56007 commented 9 years ago

My mistake. It is named 'TestState' in my code but forgot to change it when I copied the example (mine had too many variables in the way).

playif commented 9 years ago

Hi @TheSneakyNarwhal You should use "library" and "part (of)" structure in your project. (check out this link: https://www.dartlang.org/docs/dart-up-and-running/ch02.html#libraries-and-visibility)

Or you will need to import play_phaser library in your second file.

derrick56007 commented 9 years ago

Ah, that did it! Another reason to reread dart documentation... Thanks @playif