传递给Actor.addBehavior的行为类为null。超级大国

时间:2017-04-27 17:49:42

标签: typescript

Superpowers游戏引擎。

打字稿。

游戏脚本

let MainChar = new Sup.Actor("Main Character");
new Sup.SpriteRenderer(MainChar, "Leonard");

let CameraMan = new Sup.Actor("Camera Man");
new Sup.Camera(CameraMan);

MainChar.setPosition(0, 0, 0);
CameraMan.setPosition(0, 0, 5);

MainChar.addBehavior(CharacterBehavior);

字符脚本

class CharacterBehavior extends Sup.Behavior {
 update() {
  if(Sup.Input.isKeyDown("LEFT")){
   this.actor.move(-0.1, 0, 0);
 }

  if(Sup.Input.isKeyDown("RIGHT")){
   this.actor.move(0.1, 0, 0);
  }
 }
 }
Sup.registerBehavior(CharacterBehavior);

问题

Game.ts:12 Uncaught Error: The behavior class passed to Actor.addBehavior was null. Make sure the class is declared before     Actor.addBehavior is called.Actor.addBehavior @ VM148:527(anonymous function) @ Game.ts:12start @ runtime.js:61310(anonymous function) @ SupRuntime.js:1826(anonymous function) @ SupRuntime.js:206async.forEachOf.async.eachOf @ SupRuntime.js:258async.forEach.async.each @ SupRuntime.js:234Player._startPlugins @ SupRuntime.js:1823(anonymous function) @ SupRuntime.js:1698(anonymous function) @ SupRuntime.js:743iterate @ SupRuntime.js:287Item.run @ SupRuntime.js:1446drainQueue @ SupRuntime.js:1416

screenshot

如何修复?我是TypeScript的新手,并且使用了“export”和“import”,但它不起作用。

2 个答案:

答案 0 :(得分:0)

为什么您的import { CharacterBehavior } ...已注明?

答案 1 :(得分:0)

决定将游戏脚本放在角色脚本

下面