Testing behavior of onTouchBegan and onTouchEnded

Testing behavior of onTouchBegan and onTouchEnded
0.0 0

#1
 var luckyGameTypeListener = cc.EventListener.create({
        event: cc.EventListener.TOUCH_ONE_BY_ONE,
        onTouchBegan: function (touch, event) {
          console.log("Touch Begin");
          return true;
        },
        onTouchEnded: function (touch, event) {
         console.log("Touch End");
          return true;
        }
    });

I create the simple EventListener to test the behavior of onTouchBegan and onTouchEnded , i found out that this is event is not simultaneously , The first time i click it only show “Touch Begin”, than I click again it show “Touch End” , the sequence will continue like begin than end than begin and end ,is this the correct behavior of this event or i did something wrong ?

What i am expecting is when the mouse on click it should fire onTouchBegan and when the click is release it show fire onTouchEnded .


#2

I am not using javascript with cocos2dx but the TOUCH_ONE_NY_ONE sound fishy to me :slight_smile:

It sounds like it will provide one-touch per touch click so maybe that’s the case ?

it is just a guess.


#3

Hi guys the problem is fix , i left out the return true in my actual code .


#4

var luckyGameTypeListener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
onTouchBegan: function (touch, event) {
console.log(“Touch Begin”);
return true;
},
onTouchEnded: function (touch, event) {
console.log(“Touch End”);
return true;
}
});

Base on this testing ,I found out the behavior of the event is when you first click it will go to onTouchBegan , in order to proceed with onTouchEnded after the onTouchBegan, return true is needed . In order to able to fire back the event onTouchBegin after the onTouchEnded must return a true , so that the next click for onTouchBegin is able to fire.

So on my case early mention , I have left out the return value in onTouchEnd , that why it cause , the Odd number firing.

would appreciate to correct my explanation if there is any mislead or not accurate.

Thanks