I am working on cocos2d-x v3.2
Some strange problem, I’ve noticed.
I have attached my eventListener to spriteA and not layer to which it is added…
I’ve implemented the onTouchBegan and on TouchEnded in a normal way…
Consider the code…
HelloWorld::onTouchBegan(...)
{
if(spriteA->getBoundingBox().containsPoint(touch->getLocation()))
{
globalFlag = 1;
}
else
{
globalFlag = 2;
}
}
HelloWorld::onTouchEnded(...)
{
if(spriteA->getBoundingBox().containsPoint(touch->getLocation()) && globalFlag==1)
{
spriteA->removeFromParent();
}
}
Don’t worry about the declarations and other things. Assume that I can do them all without any problem.
So, here is my problem…
Case 1:
Use just 1 finger… Don’t touch the screen with 2nd finger (especially outside spriteA while this process otherwise BLAST , I mean then you would have to see Case 2 )
Touch spriteA and release/raise your finger. spriteA should get removed.
WORKING PERFECTLY
Because when I touched the spriteA, my globalFlag is set to 1 and when I released my finger while keeping this finger inside spriteA, it removed this spriteA because my globalFlag was 1 and my touch ended’s locations was within spriteA.
Good Enough.
Case 2:
Now use 2 fingers for this procedure as stated below:
Touch spriteA with one finger and keep pressing… DON’T release/raise your this finger…
globalFlag should get set to 1…Right!!
Now, (don’t raise your first finger until said), touch outside spriteA with the 2nd finger and raise this 2nd finger.
Interesting thing is globalFlag will now change to 2… and now when I will raise/release my 1st finger which was still touching on spriteA… Now, spriteA won’t get removed because the globalFlag is changed to 2 although my touch location (in touch ended) is within spriteA’s boundingBox.
My Problem:
I don’t know why this happened… Or may be I was so unaware…
But I was expecting that when I am using singleTouch then until the things(all the 3 functions- onTouchBegan/Moved/Ended) of first touch are over then touch of 2nd finger should be ignored automatically by engine.
I figured out the workable workaround using some flags to make above thing work even if the player touches outside spriteA by mistake… But I could have achieved it exactly what I wanted if the 2nd touch would have been ignored automatically by the engine…
Any suggestions?