TestMask.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. rsultLabel:cc.Label,
  5. mask:cc.Mask,
  6. promptLabel:cc.Label,
  7. },
  8. // use this for initialization
  9. onLoad: function (){
  10. this.node.on(cc.Node.EventType.TOUCH_START, this._onTouchBegin, this);
  11. this.node.on(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this);
  12. this.node.on(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
  13. this.node.on(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
  14. },
  15. onDestroy:function () {
  16. this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegin, this);
  17. this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMoved, this);
  18. this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnd, this);
  19. this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
  20. },
  21. start:function () {
  22. //
  23. // var x =-100;
  24. // var y =-100;
  25. // var width =300;
  26. // var height = 200;
  27. // var rectangle = [cc.v2(x, y),
  28. // cc.v2(x + width, y),
  29. // cc.v2(x + width, y + height),
  30. // cc.v2(x, y + height)];
  31. //
  32. // stencil.drawPoly(rectangle, color, 0, color);
  33. // stencil.drawPoly(this.mask._calculateCircle(cc.p(0,0),cc.p(100,100), 64), color, 0, color);
  34. //
  35. // stencil.drawPoly(this.mask._calculateCircle(cc.p(200,200),cc.p(50,50), 64), color, 0, color);
  36. },
  37. _onTouchBegin:function (event) {
  38. cc.log('touchBegin');
  39. var point = event.touch.getLocation();
  40. point = this.node.convertToNodeSpaceAR(point);
  41. this._addCircle(point);
  42. },
  43. _onTouchMoved:function (event) {
  44. var point = event.touch.getLocation();
  45. point = this.node.convertToNodeSpaceAR(point);
  46. this._addCircle(point);
  47. },
  48. _onTouchEnd:function (event) {
  49. var point = event.touch.getLocation();
  50. point = this.node.convertToNodeSpaceAR(point);
  51. this._addCircle(point);
  52. },
  53. _onTouchCancel:function (event) {
  54. // var point = event.touch.getLocation();
  55. // point = this.node.convertToNodeSpaceAR(point);
  56. // this._addCircle(point);
  57. },
  58. _addCircle:function (point) {
  59. var stencil = this.mask._clippingStencil;
  60. var color = cc.color(255, 255, 255, 0);
  61. stencil.drawPoly(this.mask._calculateCircle(point,cc.p(50,50), 64), color, 0, color);
  62. if (!CC_JSB) {
  63. cc.renderer.childrenOrderDirty = true;
  64. }
  65. },
  66. // called every frame, uncomment this function to activate update callback
  67. // update: function (dt) {
  68. // },
  69. });