SnakeTouchInput.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. var o0 = require('o0');
  2. var o0CC = require('o0CC');
  3. var o0Game = require('o0Game');
  4. cc.Class({
  5. extends: require('SnakeDirectionInput'),
  6. properties: {
  7. touchLocation: null,
  8. speedingButton:null,
  9. },
  10. // use this for initialization
  11. onLoad: function () {
  12. this._super();
  13. var self = this;
  14. this.speedingButton = o0CC.addScriptNode(this.control.snake.node,'o0CCButton',10);
  15. o0CC.setGroup(this.speedingButton,o0Game.GroupIndex.UI);
  16. this.speedingButton.node.x = this.control.snake.gameScene.canvas.node.width/2-150;
  17. this.speedingButton.node.y = 0;
  18. this.speedingButton.node.width = 80;
  19. this.speedingButton.node.height = 80;/** */
  20. this.speedingButton.name = 'Boost';
  21. this.speedingButton.node.on(cc.Node.EventType.TOUCH_START, function (event) {
  22. self.setTargetSpeeding(true);
  23. }, this);
  24. this.speedingButton.node.on(cc.Node.EventType.TOUCH_END, function (event) {
  25. self.setTargetSpeeding(false);
  26. }, this);/** */
  27. this.touchLocation = new o0.Vector2(1,0);
  28. //TOUCH_ONE_BY_ONE
  29. //TOUCH_ALL_AT_ONCE
  30. var listener = {
  31. event: cc.EventListener.TOUCH_ONE_BY_ONE,
  32. onTouchBegan: function (touch, event) {
  33. self.touchLocation = touch.getLocation();
  34. return true;
  35. },
  36. onTouchMoved: function (touch, event) {
  37. self.touchLocation = touch.getLocation();
  38. return true;
  39. },
  40. onTouchEnded: function (touch, event) {
  41. self.touchLocation = touch.getLocation();
  42. return true;
  43. },
  44. }
  45. cc.eventManager.addListener(listener, this.node);
  46. },
  47. start: function (dt) {
  48. },
  49. update: function (dt) {
  50. this._super();
  51. var localLocation = this.node.parent.convertToNodeSpaceAR(this.touchLocation);
  52. this.setTargetVector(new o0.Vector2(localLocation).mod);
  53. },/*
  54. test:function(){
  55. cc.log('mouse snake');
  56. },/** */
  57. });