Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, this is possible. One way to test for touches is by using the CCTouchDispatcher.</p> <h2>Overview</h2> <ol> <li>Determine which class will monitor for touches of your letter sprites.</li> <li>Make the class a delegate of CCTargetedTouchDelegate.</li> <li>Add code to the class to register with the CCTouchDispatcher.</li> <li>Add code to the class to unregister with the CCTouchDispatcher.</li> <li>Add the touch callback methods to your class. In the touch callback methods, you must add code for determining which sprite was touched.</li> </ol> <h2>Register and unregister from Dispatcher</h2> <pre><code>[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES]; [[CCTouchDispatcher sharedDispatcher] removeDelegate:self]; </code></pre> <h2>CallBack Methods To Implement</h2> <pre><code>- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event </code></pre> <h2>Example Code For Testing If Touch In Sprite</h2> <pre><code>- (BOOL) isTouch:(UITouch *)touch InSprite:(CCSprite *)sprite { CGPoint touchLocation = [touch locationInView: [touch view]]; touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation]; CGPoint localLocation = [sprite convertToNodeSpace:touchLocation]; CGRect spriteRect = [sprite textureRect]; spriteRect.origin = CGPointZero; if(CGRectContainsPoint(spriteRect, localLocation)) { return YES; } return NO; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload