Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to "reset" any existing touches?

Cocos2d-iphone 1.0.1.
  • My main game scene requires the player to have a finger pressing the screen for the character to move.
    • While the character moves (thus the finger pressing the screen), a battle might occur. Such battle triggers a new CCScene which is pushed into the CCDirector (so the main game scene still exists within memory).
    • During the battle, naturally, the player will probably release his finger at some point.
    • When the battle is over, this CCScene is popped. Thus, the main game scene returns.
  • Now here is a problem: the main game scene still thinks that the finger that was initially pressing the screen before the battle is still pressing it at the same point, thus the joystick is still "functioning" and the player is still moving despite the fact that the finger is no longer pressing the screen.

Is there a way to "reset" the screen touches? I'd like to do so in the onEnter method of the main game scene. I tried something like

self.isTouchEnabled = NO;
self.isTouchEnabled = YES;

Hoping that such would re-register the touch dispatcher and thus causing some kind of reset. It did not work.

Basically, I need a way to tell the main game scene "dude, no one's touching the screen despite whatever you think".

Edit

Note that, if you press the screen again, it is fixed.

like image 392
Voldemort Avatar asked Dec 06 '25 06:12

Voldemort


1 Answers

To make sure I understand the problem:

After you pop the battle scene, the character continues moving around as if the user never released his finger from the joystick?

My initial thought is that you have a deeper underlying design flaw somewhere in the code. It is my understanding that you want to use at least one layer to handle input. Try shifting everything in that 'game' CCScene to a 'game' CCLayer and add the layer as a child of the scene. Then register the layer to receive touch input.

If that doesn't work, you could always use a flag. Compare the scene you are in to the scene you want to be in, and if not, don't activate the joystick controller. Kind of hack-y but it works.

like image 166
Clev3r Avatar answered Dec 07 '25 20:12

Clev3r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!