Roboman.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import AvatarController = require("./AvatarController");
  2. // designate component
  3. "atomic component";
  4. //A RoboMan component
  5. class Roboman extends Atomic.JSComponent {
  6. start() {
  7. this.animCtrl = <Atomic.AnimationController>this.node.getComponent("AnimationController");
  8. this.controller = <AvatarController>this.node.getJSComponent("AvatarController");
  9. //get main camera of the current scene
  10. const camera = this.node.scene.getMainCamera();
  11. //if it exist
  12. if (camera) {
  13. camera.node.position = [0, 0, -10];
  14. camera.node.pitch(20);
  15. }
  16. this.animCtrl.playExclusive("Idle", 0, true, 0.0);
  17. //rotate current node around Y axis
  18. this.node.yaw(180);
  19. }
  20. update(timeStep: number) {
  21. //rotate current node around Y axis
  22. this.node.yaw(180);
  23. if (this.idle != this.controller.idle) {
  24. this.idle = this.controller.idle;
  25. if (this.idle) {
  26. this.animCtrl.playExclusive("Idle", 0, true, 0.1);
  27. } else {
  28. this.animCtrl.playExclusive("Run", 0, true, 0.1);
  29. }
  30. }
  31. }
  32. controller: AvatarController;
  33. animCtrl: Atomic.AnimationController;
  34. idle = true;
  35. }
  36. export = Roboman;