I have 2 scenes in the game.
- MainMenuScene
- GameScene
Once level gets seleted on MainMenuScene , GameScene gets loaded for that particular level. However after I return to MainMenuScene from GameScene, random buttons sometimes stop working (do not respond to touch events). This bug happens ONLY on iPad (IOS 9)
I should note that when a particular button is not responding, EventListenerTouchOneByOne events get triggered instead.
While switching from GameScene to MainMenuScene I use replaceScene
Thanks
Code:
Main menu scene:
//Inputs
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(MainMenuScene::onTouchBegan, this);
touchListener->onTouchEnded = CC_CALLBACK_2(MainMenuScene::onTouchEnded, this);
touchListener->onTouchMoved = CC_CALLBACK_2(MainMenuScene::onTouchMoved, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
Button touch listener:
m_pButton->addTouchEventListener(CC_CALLBACK_2(MainMenuScene::onButtonClicked, this));
Update:
After debugging what exactly is going wrong, I found out that when touch does not get detected, the getWorldToNodeTransform() that is called in hitTest method of that button returns a different matrix. This further causes the hitTest to return false even if the button is being pressed.
When touch gets detected on the button, getWorldToNodeTransform() returns the following matrix
(float [16]) m = { [0] = 0.0000000397364346 [1] = 0.666666686 [2] = 0 [3] = 0 [4] = -0.666666686 [5] = 0.0000000397364346 [6] = 0 [7] = 0 [8] = 0 [9] = -0 [10] = 0.666666686 [11] = 0 [12] = 377.333313 [13] = -410.666718 [14] = 0 [15] = 0.99999994 }
When touch does not get detected on the button, getWorldToNodeTransform() returns the following matrix
(float [16]) m = { [0] = 0.0000000458497347 [1] = 0.769230902 [2] = 0 [3] = 0 [4] = -0.769230902 [5] = 0.0000000458497347 [6] = 0 [7] = 0 [8] = 0 [9] = 0 [10] = 0.769230842 [11] = 0 [12] = -684.92334 [13] = -1810.30786 [14] = 0 [15] = 1 }
What would have caused the getWorldToNodeTransform() to return such a matrix ?