You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. local touchEcFile = "res/effect/CommonEffect/ef_shubiaodianji/ef_shubiaodianji_02.effect"
  2. local bIgnore = false;
  3. local touchBeforeListener = nil;
  4. local touchAfterListener = nil;
  5. local touchEffectNode = nil;
  6. function showClickEffect(pos)
  7. --创建前把之前的移除
  8. ignoreCurTouchEffect();
  9. -- 创建一个光效
  10. local touchEffect = createEffect(touchEcFile);
  11. -- 默认要播放
  12. touchEffect:play();
  13. -- 播放完毕自动删除
  14. touchEffect:setOnStoped(ignoreCurTouchEffect);
  15. touchEffectNode = cc.GroupNodeIn2D:create();
  16. touchEffectNode:setTranslation({x=pos.x,y=pos.y,z=0});
  17. touchEffectNode:addChild(touchEffect);
  18. app.mainScene:addChild(touchEffectNode , UIZOrder.TipsOrder);
  19. --showTooltip("show");
  20. end
  21. function addGlobalTouchEffectListener()
  22. touchBeforeListener = cc.EventListenerTouchOneByOne:create()
  23. touchBeforeListener:setSwallowTouches(false);
  24. local function onBeforeBegan(touch , event)
  25. bIgnore = false;
  26. local pos = touch:getLocation();
  27. showClickEffect(pos)
  28. return false;
  29. end
  30. touchBeforeListener:registerScriptHandler(onBeforeBegan, cc.Handler.EVENT_TOUCH_BEGAN)
  31. cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(touchBeforeListener , -1)
  32. end
  33. --忽略此次点击光效
  34. function ignoreCurTouchEffect()
  35. if(touchEffectNode)then
  36. touchEffectNode:removeFromParent()
  37. touchEffectNode = nil;
  38. --showTooltip("remove");
  39. end
  40. end