main.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // camera: {
  14. // default: null,
  15. // type: cc.Node
  16. // },
  17. // bg: {
  18. // default: null,
  19. // type: cc.Node
  20. // },
  21. },
  22. // LIFE-CYCLE CALLBACKS:
  23. onLoad () {
  24. this.MainCamera = UtilsNode.getNode("Main Camera",this.node);
  25. app.camera = this.MainCamera;
  26. },
  27. start() {
  28. this.bg = UtilsNode.getNode("bg",this.node);
  29. cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
  30. cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onkeyUp, this);
  31. this.wTag = false;
  32. this.sTag = false;
  33. // let MoveUp = cc.moveBy(0.5,cc.v2(0,1000)).easing(cc.easeIn(10));
  34. },
  35. onkeyUp: function (event) {
  36. switch(event.keyCode) {
  37. case cc.macro.KEY.w:
  38. console.log('Press a key');
  39. this.wTag = false;
  40. break;
  41. case cc.macro.KEY.s:
  42. console.log('Press a key');
  43. this.sTag = false;
  44. break;
  45. }
  46. },
  47. onKeyDown: function (event) {
  48. switch(event.keyCode) {
  49. case cc.macro.KEY.w:
  50. console.log('Press a key');
  51. this.wTag = true;
  52. break;
  53. case cc.macro.KEY.s:
  54. console.log('Press a key');
  55. this.sTag = true;
  56. break;
  57. }
  58. },
  59. update (dt) {
  60. if (this.wTag) {
  61. this.MainCamera.y -=40;
  62. // this.camera.getComponent(cc.Camera).zoomRatio+=1;
  63. }else if (this.sTag) {
  64. this.MainCamera.y +=40;
  65. // this.camera.getComponent(cc.Camera).zoomRatio-=1;
  66. }
  67. },
  68. });