SnakePositionInput.js 691 B

1234567891011121314151617181920212223242526
  1. var o0 = require('o0');
  2. var o0CC = require('o0CC');
  3. cc.Class({
  4. extends: require('SnakeDirectionInput'),
  5. properties: {
  6. targetPosition: null,
  7. controllByPosition: true,
  8. },
  9. setTargetPosition:function(position){
  10. this.targetPosition = position;
  11. },
  12. setControllByPosition:function(bool){
  13. this.controllByPosition = bool;
  14. },
  15. // use this for initialization
  16. onLoad: function () {
  17. this.targetPosition = new o0.Vector2(1,0);
  18. this._super();
  19. },
  20. update: function (dt) {
  21. if(this.controllByPosition)
  22. this.setTargetVector(this.targetPosition.minus(this.node).mod);
  23. this._super();
  24. },
  25. });