<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>cocos2d for iPhone &#187; Tag: Touch - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/touch</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 03:55:49 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.cocos2d-iphone.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.cocos2d-iphone.org/forum/rss/tags/touch/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>breskit on "Am I doing this the right way?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28957#post-142728</link>
			<pubDate>Sun, 05 Feb 2012 09:26:25 +0000</pubDate>
			<dc:creator>breskit</dc:creator>
			<guid isPermaLink="false">142728@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi folks,</p>
<p>Apologies for the long post, but I'm a little stuck!</p>
<p>I just wanted to ask if some of you more experienced folks can tell me if I am coding my project the right way?  I think I have a couple of areas on my project that I may not be handling in the best way, so here's a question on the first.</p>
<p>In my project I'm using Chipmunk for physics and have created a number of "objects" that rotate.  One such example is a cross.  As the cross is a convex shape I have created each arm as a separate shape, so have a total of 4 shapes in my cross object (well, 5 actually as I also have a centre wheel).  These arms are joined by pivot joints around the centre of the cross and are rotated by a simple motor joints.</p>
<p>The touch event on the cross stops/starts it rotating (sets the motor angle to 0/45 accordingly).</p>
<p>My cross object is defined as so:-</p>
<pre><code>@interface _cross : CPSprite &#60;CCTargetedTouchDelegate&#62; {
    CPSprite *arm1;
    CPSprite *arm2;
    CPSprite *arm3;
    CPSprite *arm4;
    CPSprite *wheel;
    float objectMass;
    BOOL isMoving;
    cpConstraint *c1;
    cpConstraint *c2;
    cpConstraint *c3;
    cpConstraint *c4;
    cpConstraint *c5;
    cpConstraint *c6;
    cpConstraint *c7;
    cpConstraint *c8;
    cpConstraint *c9;
    cpConstraint *c10;
    float rotationAngle;
    cpSpace *mSpace;
    cpBody *mGround;

    CGRect rect1;
    CGRect rect2;
    CGRect rect3;
    CGRect rect4;
    CGRect rect5;

}</code></pre>
<p>Touch event for the cross:</p>
<pre><code>-(BOOL) containsTouch:(UITouch*) touch {

    CGPoint locationTouched = [arm1 convertTouchToNodeSpace:touch];
    BOOL isTouched1 = CGRectContainsPoint(rect1, locationTouched);

    locationTouched = [arm2 convertTouchToNodeSpace:touch];
    BOOL isTouched2 = CGRectContainsPoint(rect2, locationTouched);

    locationTouched = [arm3 convertTouchToNodeSpace:touch];
    BOOL isTouched3 = CGRectContainsPoint(rect3, locationTouched);

    locationTouched = [arm4 convertTouchToNodeSpace:touch];
    BOOL isTouched4 = CGRectContainsPoint(rect4, locationTouched);

    locationTouched = [wheel convertTouchToNodeSpace:touch];
    BOOL isTouched5 = CGRectContainsPoint(rect5, locationTouched);

    return isTouched1 &#124;&#124; isTouched2 &#124;&#124; isTouched3 &#124;&#124; isTouched4 &#124;&#124; isTouched5;
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    if (![self containsTouch:touch]) return NO;
    [self toggleMoving:mSpace withGround:mGround];
    return YES;
}</code></pre>
<p>Inside CPSprite I have an update method:</p>
<pre><code>- (void)update {
    self.position = body-&#62;p;
    self.rotation = CC_RADIANS_TO_DEGREES(-1 * body-&#62;a);
}</code></pre>
<p>And my game loop, I call the update for every CPSprite:</p>
<pre><code>-(void) step: (ccTime) delta {
    int steps = 1;
    cpFloat dt = 1.0f/60.0f/(cpFloat)steps;

    for(int i=0; i&#60;steps; i++){
        cpSpaceStep(space, dt);
    }

    for (CPSprite *sprite in batchNode.children) {

        if (sprite) {
            [sprite update];
        }
        if ([sprite isKindOfClass:[rock class]]) {
        }
    } 

    // need to check if level complete
    CGRect image_rect1 = CGRectMake(theEndGate.target.position.x,theEndGate.target.position.y,35,35);

    for (rock *arock in _rocks) {
        float rockw = arock.boundingBox.size.width;
        CGRect image_rect2 = CGRectMake(arock.position.x, arock.position.y, rockw, rockw);

        if(CGRectIntersectsRect(image_rect1, image_rect2)) {
            if (!endGateHit) {
                endGateHit = YES;
                [self addEndgatePD];
                [self endScene:TRUE];
            }
        }

    }
    cpSpaceReindexStatic(space);
}</code></pre>
<p>The CPSprite class allows me to create my CCSprite and Chipmunk body/shape. The touch delegate gives me the targeted touches agains this cross object.<br />
As part of the cross 'init' I calculate the CGRect properties for each piece of the cross so I don't have to calculate this each time I look for a touch.  The position and rotation of these are updated within CPSprite.</p>
<p>The questions I have now are:</p>
<p>1.  In pre-calculating the CGRect for the cross arms, do I need to recalculate these each time for the touch event? I don't think I do as the position/rotation appears to be updated OK.</p>
<p>2. Have I created the arms for the cross in the best way - using separate Chipmunk bodies/sprites/etc, or should I be trying to use a single Chipmunk body in someway for the whole object?</p>
<p>3. Is my main update call within the step: the most efficient way of handling this?  On some levels of my project there are as few as 12 sprites to update, but on others there can me as many as 80+.  Performance/FPS still seem quite good though (around 52fps in most cases).</p>
<p>My problem may just be down to my fat fingers not hitting the right place on the screen to toggle the moving (seems accurate when I use the mouse in simulator). Either that or I'm not calculating/using something correctly.
</p></description>
		</item>
		<item>
			<title>popsalicious on "Touch Counter"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28945#post-142692</link>
			<pubDate>Sat, 04 Feb 2012 21:10:19 +0000</pubDate>
			<dc:creator>popsalicious</dc:creator>
			<guid isPermaLink="false">142692@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm pretty new to cocos2d, so sorry if this is a super obvious question or I'm just not thinking about it the right way, but I'm trying to make a touch counter in a game.  The idea is that after one touch on a sprite, something happens.  After another touch, a different thing happens.  And after the third touch, yet another thing happens, and the counter returns to 0.  I tried assigning a value to an int pokeCount and having that change each time a touch happened on the sprite (pokeCount++), but it wasn't working for me (if I had the thing happen at pokeCount == 1 it'd work, but pokeCount == 2 didn't).  Any ideas?  Should I make the pokeCount a property of the layer and change it that way?</p>
<p>Here's the code I was trying out:<br />
<pre><code>- (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint poke=[touch locationInView:[touch view]];
    poke = [[CCDirector sharedDirector] convertToGL:poke];
    poke = [_fatcat convertToNodeSpace:poke];
    int pokeCount = 0;

    if (poke.x&#60;_fatcat.contentSize.width &#38;&#38; poke.x&#62;0 &#38;&#38; poke.y&#60;_fatcat.contentSize.height &#38;&#38; poke.y&#62;4)
        {
            pokeCount++;
            if(pokeCount == 2){
            [self doSomethingElse];
        }
    }
}</code></pre></description>
		</item>
		<item>
			<title>praveencastelino on "CCLayerPanZoom touch restrictions"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28906#post-142457</link>
			<pubDate>Fri, 03 Feb 2012 06:49:42 +0000</pubDate>
			<dc:creator>praveencastelino</dc:creator>
			<guid isPermaLink="false">142457@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>is there any way for CCLayerPanZoom to stop receiving the touches. I dont want the CCLayerPanZoom to pan or zoom when custom modal alert is shown.
</p></description>
		</item>
		<item>
			<title>kosa_nostra on "Touches and CCLayer"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28861#post-142223</link>
			<pubDate>Wed, 01 Feb 2012 23:23:34 +0000</pubDate>
			<dc:creator>kosa_nostra</dc:creator>
			<guid isPermaLink="false">142223@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everyone,</p>
<p>I'm working on a game and get confused by something: I have 2 CCLayers, one on the right and one on the left of the screen. Each one are their own touch delegate. My problem is when I touch the left screen, the event is caught by both of my layers.</p>
<p>Basically, I don't understand why a touch in a layer is not caught only in this layer. It's like both of my layers take the entire screen.</p>
<p>Any help, recommandation ?</p>
<p>Cheers,<br />
Kosa
</p></description>
		</item>
		<item>
			<title>JackBixby on "Trouble drawing after touch"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28889#post-142389</link>
			<pubDate>Thu, 02 Feb 2012 21:09:18 +0000</pubDate>
			<dc:creator>JackBixby</dc:creator>
			<guid isPermaLink="false">142389@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey all. I'm trying to draw a line after the user touches on the screen, but that's not working. All of the drawing in my draw method works. But none of the drawing in my drawLine method (called after a touch has ended) works. I know that the touching/method calling as the console displays "test." Here's my code:</p>
<p><a href="http://pastebin.com/tGT7qB7P" rel="nofollow">http://pastebin.com/tGT7qB7P</a></p>
<p>Thanks in advance
</p></description>
		</item>
		<item>
			<title>phantomsri on "how to remove a overlapped sprite."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28537#post-140520</link>
			<pubDate>Sat, 21 Jan 2012 10:37:36 +0000</pubDate>
			<dc:creator>phantomsri</dc:creator>
			<guid isPermaLink="false">140520@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi need help,<br />
I have 3 sprites overlapped, with tag 1 to 3.  How i can remove multiple overlapped sprite in a single touch?<br />
I have a loop code below to remove sprite based on tag, its not working. All im getting is that i need to click the same spot 3 times to remove the 3 sprites.</p>
<pre><code>-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch* myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView: [myTouch view]];
    location = [[CCDirector sharedDirector]convertToGL:location];
    location = [self convertToNodeSpace:location];

    int totalNumberOfItems=4;
    for (int y=0; y &#60; totalNumberOfItems; y++){
        CCSprite *temp = (CCSprite*)[self getChildByTag:y];

        CGRect test1 = [temp boundingBox];

        if (CGRectContainsPoint(test1, location)) {
            NSLog(@&#34;touched&#34;);
            [self removeChild:temp cleanup:YES ];
            return;
        }
    }  

}</code></pre></description>
		</item>
		<item>
			<title>dgtheman on "Pinch, Zoom, and Boundries? cocoswd 0.99.5??"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28737#post-141621</link>
			<pubDate>Sat, 28 Jan 2012 11:18:07 +0000</pubDate>
			<dc:creator>dgtheman</dc:creator>
			<guid isPermaLink="false">141621@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have searched forever for a good solution to pinching/zooming and a standard algrithm for detecting the boundries on a map but have not come up with any good results. I found some but the -(void)ccTouchesMoved:withEvent: method doesnt seem to work anymore...and I have multiple touches enabled. Also, I have seen the UIPinchGestureRecognizer but it does not seem to be working for landscape mode? And one more thing...this is probably the most important...can someone provide me an alogrithm for detecting the edges of a map? So, if the user scrolls the layer moves and it does not go pass a certain boundry. The thing is I need it to work with scale as well and it is NOT a tiled map.</p>
<p>Thanks In Advance! I would appreciate any help!!
</p></description>
		</item>
		<item>
			<title>WizKidSP on "Touch Location Not Passing to Second Class"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28574#post-140700</link>
			<pubDate>Sun, 22 Jan 2012 20:11:25 +0000</pubDate>
			<dc:creator>WizKidSP</dc:creator>
			<guid isPermaLink="false">140700@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello all!  I am new to cocos2d, but not new to programming in Xcode to create apps.  I am having trouble getting the touch location's value i.e. (338, 429) to pass to a second class.  I am getting the touch location correctly, as I have checked this via CCLOG.  Can anyone help me figure out why, when I use CCLOG to check if the second class has the correct location, I get (0,0) instead of the correct location values that I received in the first class?  Here is the code I am using to try to do this, if you know or have any suggestions, please let me know!<br />
In ClassA.h:<br />
@class ClassB, then ClassB *classB, followed by @property (nonatomic, strong) ClassB *classB;</p>
<p>In ClassA.m:<br />
@synthesize classB;<br />
//<br />
// Code<br />
//<br />
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{<br />
    UITouch *touch=[touches anyObject];<br />
    CGPoint loc=[touch locationInView:[touch view]];<br />
    loc=[[CCDirector sharedDirector] convertToGL:loc];<br />
    NSLog(@"touch (%g,%g)",loc.x,loc.y);</p>
<p>    classB.theLocation = [touch locationInView:[touch view]];<br />
    classB.theLocation = [[CCDirector sharedDirector] convertToGL:classB.theLocation];<br />
    NSLog(@"Class B should also get (%g,%g)",classB.theLocation.x,classB.theLocation.y);<br />
}</p>
<p>And, when I touch the screen, this NSLog for "Class B should also get..." does give the correct touch location.<br />
But, over in ClassB.m, I created a NSLog to see if I have received the correct location, but the NSLog in ClassB.m gives me (0,0) instead of the expected values that I get in ClassA.m  </p>
<p>Any help would be greatly appreciated!  Thanks guys!
</p></description>
		</item>
		<item>
			<title>Duckwit on "[?] Seriously Mislead as to &#039;Multi-Touch&#039; - Will not receive touches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28497#post-140271</link>
			<pubDate>Thu, 19 Jan 2012 21:28:42 +0000</pubDate>
			<dc:creator>Duckwit</dc:creator>
			<guid isPermaLink="false">140271@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Right,<br />
I am learning to program the touch input for my control system.<br />
I have posted various topics and read many tutorials, all to (almost) no avail. </p>
<p>At first I needed a method to manage multiple touches. Thanks to @<a href='http://www.cocos2d-iphone.org/forum/profile/1750'>hactar</a> I have my buttons store a UITouch and check to see if it corresponds with current touches on the screen. </p>
<p>Now I just plainly and simply want to receive the touches. Full. Stop. </p>
<p>"What?"</p>
<p>Why is this happening:<br />
-------------------------<br />
TL;DR<br />
-------------------------<br />
This code:<br />
<pre><code>-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *allTouches = [event allTouches];
for (UITouch* touch in allTouches)
printf(&#34;A TOUCH\n&#34;);
...</code></pre>
<p>...should receive touches that begin - correct?<br />
This is what happens:<br />
1.Put one finger on the screen (Output prints 'A TOUCH')<br />
2.Touch with another finger while holding down the first finger - Nothing.<br />
3. Tap, swipe, bang the iPod on your flesh until it (and your hand) are bleeding - Nothing. :3 </p>
<p>Why does this happen, and what should I do to make it work properly? </p>
<p>NOTE:<br />
I also tried:<br />
<pre><code>NSArray* allTouches = [[event allTouches] allObjects]; //&#60;-- EDIT
for (UITouch* touch in allTouches)</code></pre>
<p>and<br />
<pre><code>NSArray* allTouches = [[touches allTouches] allObjects];
for (UITouch* touch in allTouches)
...</code></pre>
<p>Thanks for any tips/pointers :)
</p></description>
		</item>
		<item>
			<title>Duckwit on "[?] Touch Manipulation Logic Fail - Help with Control System"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28426#post-139910</link>
			<pubDate>Tue, 17 Jan 2012 21:11:31 +0000</pubDate>
			<dc:creator>Duckwit</dc:creator>
			<guid isPermaLink="false">139910@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've been playing around with this for some hours now, and I'm still confused as to how I should solve this apparently complex puzzle. </p>
<p>-There are 3 buttons - move right, move left, and jump.<br />
-I am using the ccTouchesBegan/Moved/Ended methods and taking into account the sprite.boundingBox thing to check for touches. </p>
<p>Check if there is a touch in the box? Done.<br />
Check, if there are more than two touches, if one of them touches the box. &#60;- Aghem.  </p>
<p>Okay wait, I know how to check if two touches are there and one of them is within bounds.<br />
The problem is the order/way touches are received. </p>
<p>As far as I am aware there is no way to just get an array or NSSet* of touches present on the screen. Only touches that have just begun, that have just moved, or have just ended. </p>
<p>So what I ask, basically, is this:<br />
How do I check if a touch is THERE?<br />
1. touchBegan<br />
2.User is till holding his finger on the screen, but no method is called because they only trigger when it begins, moves, or ends. </p>
<p>Right. </p>
<p>So I have a BOOLEAN variable to control whether or not the button is held down. </p>
<p>1. TouchBegins - BOOL = YES;<br />
2. Touch Moves - How do I check if the touch has moved OFF the button? Think about this for a moment.<br />
Consider this scenario:<br />
1.TouchBegins - BOOL = YES;<br />
2.Touch2Begins - SomethingElse = YES;<br />
3.Touch2 Moves, but Touch1 does not, so it is not included in the array: I check to see if any of the touches hit the button, they don't, so now the application thinks also somethingElse is activated. </p>
<p>The first touch has been lost in translation. The user is still pressing the button on the screen, but I have no way of tracking the touch, especially when other touches are moving/beginning/ending that cause even more confusion. </p>
<p>I've read various tutorials, but none of them seem to cover interpreting these situations.<br />
I would really like some help with this, or just a friendly pointer in the right direction. </p>
<p>Thanks. :)
</p></description>
		</item>
		<item>
			<title>ASuskin on "UITouch location"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28371#post-139651</link>
			<pubDate>Mon, 16 Jan 2012 05:22:59 +0000</pubDate>
			<dc:creator>ASuskin</dc:creator>
			<guid isPermaLink="false">139651@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>I'll just get straight to it.<br />
I'm trying to implement the touchMoved method in my CC3Layer but I do not know how to get the location of the UITouch.</p>
<p>This is cocos3d.</p>
<p>Does anyone have any ideas?
</p></description>
		</item>
		<item>
			<title>xanatas on "CCsprite not touchable in certain area through layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25387#post-132168</link>
			<pubDate>Wed, 07 Dec 2011 22:09:30 +0000</pubDate>
			<dc:creator>xanatas</dc:creator>
			<guid isPermaLink="false">132168@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>First my structure<br />
-------------------------</p>
<p>top layer: scoreboard..... a sprite square on bottom of screen, always on top.</p>
<p>bottom layer: I have a layer with 5 touchable sprites. they disappear on touch --- Working</p>
<p>----------------------</p>
<p>problem: want to disable touching the sprites when they are behind the scoreboard. cause the player is not seeing them and whats happening with them.<br />
any suggestions?</p>
<p>some code:</p>
<p>top layer scoreboard sprite</p>
<pre><code>- (void)onEnter {
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:NO];
    [super onEnter];
}
- (void)onExit {
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
    return YES;
}</code></pre>
<p>enables touching through to the layer below cause we want them sprites to be touched.</p>
<p>touch code on layer below:</p>
<pre><code>- (void)onEnter
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self
                                                     priority:0 swallowsTouches:YES];
    [super onEnter];
}
- (void)onExit
{
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
    if (CGRectContainsPoint(sprite.boundingBox , [self convertTouchToNodeSpace:touch])){
       [sprite disappear]
    }

  return NO;
}</code></pre>
<p>is there any easy way or do i have to get the touch position and if its on the scoreboard do nothing.<br />
i just dont know what to look for here<br />
thanks</p>
<p>SIMILAR problem maybe similar solution: i have the 5 sprites and they kind of overlap at some points when i press the overlapping points of two sprites they both disappear.
</p></description>
		</item>
		<item>
			<title>mapleegreen on "How to determine sliding the correct graphics"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25338#post-131817</link>
			<pubDate>Tue, 06 Dec 2011 02:37:42 +0000</pubDate>
			<dc:creator>mapleegreen</dc:creator>
			<guid isPermaLink="false">131817@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>For example,I have a graphic "Z",how to determin the user sliding the correct graphic?thanks for any tips about this algorithm
</p></description>
		</item>
		<item>
			<title>jed758 on "Moving Objects/ Touch Detection"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/24829#post-130920</link>
			<pubDate>Sat, 03 Dec 2011 16:13:33 +0000</pubDate>
			<dc:creator>jed758</dc:creator>
			<guid isPermaLink="false">130920@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>In my iphone app i need to be able to detect tiuches to drag around different sprites/b2bodys (im not sure which one to use for collision detection), at the moment when i drag them around they all stack on top of each other and im not sure how to detect individual sprites/b2bodys , any help is appreciated, thanks :D
</p></description>
		</item>
		<item>
			<title>cokoco on "Different touches show the same location."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/24049#post-129192</link>
			<pubDate>Sun, 27 Nov 2011 20:14:13 +0000</pubDate>
			<dc:creator>cokoco</dc:creator>
			<guid isPermaLink="false">129192@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to get a keyboard type of thing going with multitouch.</p>
<p>Even though I touch with two finger at separate positions, the same sprite is played.</p>
<p>Im sure it's something i've missed concerning the basics of touches.</p>
<pre><code>- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	NSSet *allTouches = [event allTouches];

    switch ([[allTouches allObjects] count]) {

        case 1:

            NSLog(@&#34;One Touch&#34;);
             UITouch *touch1 = [[allTouches allObjects] objectAtIndex:0];
             CGPoint location1 = [touch1 locationInView: [touch1 view]];
             location1 = [[CCDirector sharedDirector] convertToGL: location1];

            for(int i=0;i&#60;8;i++){
                  if(CGRectContainsPoint(xSprite[i].boundingBox, location1)){
                      [synthObject startNote:i];
                  }
            }
            break;

        case 2:

            NSLog(@&#34;Two Touches&#34;);
            UITouch *touch2 = [[allTouches allObjects] objectAtIndex:1];
            CGPoint location2 = [touch2 locationInView: [touch2 view]];
            location2 = [[CCDirector sharedDirector] convertToGL: location2];

                for(int i=0;i&#60;8;i++){
                    if(CGRectContainsPoint(xSprite[i].boundingBox, location2)){
                        [synthObject startNote:i+1];
                    }
                }
            break;

    }
}</code></pre></description>
		</item>
		<item>
			<title>roko on "How to get touch position on the CCMenuItemImage?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14150#post-79875</link>
			<pubDate>Thu, 03 Mar 2011 10:54:44 +0000</pubDate>
			<dc:creator>roko</dc:creator>
			<guid isPermaLink="false">79875@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all! Can anybody explain me how i can get touch position in a button(CCMenuItemImage) in the selector method?</p>
<p>for example i have this snippet of code:<br />
<pre><code>CCMenuItemImage *myMenuItem = [CCMenuItemImage itemFromNormalImage:imageNormal
							selectedImage:imageSelected
							disabledImage:imageDisable
								target:self
								selector:@selector(myMenuItemWasOn)];

	CCMenu *myMenu = [CCMenu menuWithItems:myMenuItem,nil];
	[self addChild:myMenu z:100];
	[myMenu setPosition:CGPointMake(200, 200)];</code></pre>
<p>then after i have pressed the button method "myMenuItemWasOn" will be called:</p>
<pre><code>- (void) myMenuItemWasOn
{
	CGPoint touchPos =  ?//how to get touch pos here?
}</code></pre></description>
		</item>
		<item>
			<title>jed758 on "Moving Multiple Objects"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/23133#post-127439</link>
			<pubDate>Mon, 21 Nov 2011 17:51:40 +0000</pubDate>
			<dc:creator>jed758</dc:creator>
			<guid isPermaLink="false">127439@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>How do i move multiple objects in cocos2d, i have imported all my sprites from level helper as CCSprites and b2Bodies. When i use this code only one character is dragged and all the others disappear, why? I am creating an iPhone app.<br />
Thanks </p>
<p>-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{<br />
    [self ccTouchesMoved:touches withEvent:event];<br />
}<br />
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{<br />
    UITouch *touch =[touches anyObject];<br />
    CGPoint point = [touch locationInView:[touch view]];<br />
    point = [[CCDirector sharedDirector]convertToGL:point];<br />
    greenman.position = ccp(point.x, point.y);<br />
    greenman1.position = ccp(point.x, point.y);<br />
    greenman2.position = ccp(point.x, point.y);<br />
    greenman3.position = ccp(point.x, point.y);<br />
    greenman4.position = ccp(point.x, point.y);</p>
<p>    blueman.position = ccp(point.x, point.y);<br />
    blueman1.position = ccp(point.x, point.y);<br />
    blueman2.position = ccp(point.x, point.y);<br />
    blueman3.position = ccp(point.x, point.y);<br />
    blueman4.position = ccp(point.x, point.y);<br />
}
</p></description>
		</item>
		<item>
			<title>riley13196 on "My sprite touch detection does not work"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22988#post-127057</link>
			<pubDate>Sun, 20 Nov 2011 15:42:09 +0000</pubDate>
			<dc:creator>riley13196</dc:creator>
			<guid isPermaLink="false">127057@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey everyone, I'm VERY new to iPhone programming...as in.. I started a few days ago.  I'm attempting to make a game called "Gift Grabber" in which gifts will fall down the screen and you have to touch them before they hit the bottom. I coded the part where they fall down the screen and it worked fine. Then, I tried to add the touch in and I thought I did it right but it's not working. It doesn't crash the gifts still fall down the screen but nothing happens when they are touched.  Please bear with me if my formatting isn't correct or if I don't understand a term I'm still learning. Here is my code:</p>
<p>____________________________________________________________</p>
<p>Gift Grabber.h</p>
<p>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> "cocos2d.h"</p>
<p>// HelloWorldLayer<br />
@interface GiftGrabber : CCLayerColor<br />
{</p>
<p>   NSMutableArray *_items;</p>
<p>}</p>
<p>+(CCScene *) scene;<br />
@property (nonatomic, retain) CCSprite *item;<br />
@end</p>
<p>____________________________________________________________________</p>
<p>GiftGrabber.m</p>
<p>//<br />
//  HelloWorldLayer.m<br />
//  GiftGrabber<br />
//<br />
//  Created by  ..... on 11/17/11.<br />
//<br />
//</p>
<p>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> "GiftGrabber.h"</p>
<p>@implementation GiftGrabber<br />
@synthesize item;<br />
+(CCScene *) scene<br />
{</p>
<p>	CCScene *scene = [CCScene node];</p>
<p>	GiftGrabber *layer = [GiftGrabber node];</p>
<p>	// add layer as a child to scene<br />
	[scene addChild: layer];</p>
<p>	// return the scene<br />
	return scene;</p>
<p>    UIView *myview=[[UIView alloc] initWithFrame: CGRectMake(0, 0,320,480)];<br />
    [[[CCDirector sharedDirector] openGLView] addSubview:myview];<br />
    [myview release];<br />
}</p>
<p>-(void)itemMoveFinished:(id)sender {<br />
    item = (CCSprite *)sender;<br />
    [self removeChild:item cleanup:YES];<br />
}</p>
<p>-(void)addItem {</p>
<p>    int giftNumber = (arc4random() % 5) + 1;<br />
    NSString *fileName = @"lightbluegift.png";</p>
<p>    switch(giftNumber)<br />
    {<br />
        case 1:<br />
            fileName = @"pinkgift.png";<br />
            break;<br />
        case 2:<br />
            fileName = @"purplegift.png";<br />
            break;<br />
        case 3:<br />
            fileName = @"bluegift.png";<br />
        case 4:<br />
            fileName = @"lightbluegift.png";<br />
        case 5:<br />
            fileName = @"candycane.png";<br />
            break;<br />
    }</p>
<p>    item = [CCSprite spriteWithFile:fileName rect:CGRectMake(0, 0, 40, 40)];</p>
<p>    CGSize winSize = [[CCDirector sharedDirector] winSize];<br />
    int minX = item.contentSize.width/2;<br />
    int maxX = winSize.width - item.contentSize.width/2;<br />
    int rangeX = maxX - minX;<br />
    int actualX = (arc4random() % rangeX) + minX;</p>
<p>    // Create the target slightly off-screen along the upper edge,<br />
    // and along a random position along the x axis as calculated above<br />
    item.position = ccp(actualX, winSize.height + (item.contentSize.height/2));<br />
    [self addChild:item];</p>
<p>    // Determine speed of the item<br />
    int minDuration = 2.0;<br />
    int maxDuration = 4.0;<br />
    int rangeDuration = maxDuration - minDuration;<br />
    int actualDuration = (arc4random() % rangeDuration) + minDuration;</p>
<p>    id actionMove = [CCMoveTo actionWithDuration:actualDuration<br />
                                        position:ccp(actualX, -item.contentSize.height/2)];<br />
    id actionMoveDone = [CCCallFuncN actionWithTarget:self<br />
                                             selector:@selector(itemMoveFinished:)];<br />
    [item runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];</p>
<p>    item.tag = 1;<br />
    [_items addObject:item];</p>
<p>}</p>
<p>-(void)gameLogic:(ccTime)dt {</p>
<p>    [self addItem];</p>
<p>}</p>
<p>- (void)selectSpriteForTouch:(CGPoint)touchLocation {<br />
    for (CCSprite *item in _items) {<br />
        if (CGRectContainsPoint(item.boundingBox, touchLocation)) {<br />
			NSLog(@"sprite was touched");<br />
            [item.parent removeChild:item cleanup:YES];;<br />
        }<br />
    }<br />
}</p>
<p>- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {<br />
    CGPoint touchLocation = [self convertTouchToNodeSpace:touch];<br />
    [self selectSpriteForTouch:touchLocation];<br />
    NSLog(@"touch was detected");<br />
    return TRUE;</p>
<p>}</p>
<p>-(id) init<br />
{<br />
		if( (self=[super initWithColor:ccc4(255,255,255,255)] )) {</p>
<p>            [self schedule:@selector(gameLogic:) interval:1.0];</p>
<p>			}<br />
	return self;</p>
<p>}</p>
<p>- (void) dealloc<br />
{</p>
<p>    [_items release];<br />
    _items = nil;</p>
<p>	[super dealloc];<br />
}<br />
@end </p>
<p>__________________________________</p>
<p>Please help! thanks
</p></description>
		</item>
		<item>
			<title>jed758 on "ccTouches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22954#post-126883</link>
			<pubDate>Sat, 19 Nov 2011 12:46:49 +0000</pubDate>
			<dc:creator>jed758</dc:creator>
			<guid isPermaLink="false">126883@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>When i use this code for only one object it runs fine but when i do it for all of these every time i click on the one object appear and all the others disappear from view. How would i fix this, This is for an iPhone App.<br />
Thanks </p>
<p>Code:<br />
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{<br />
    [self ccTouchesMoved:touches withEvent:event];<br />
}<br />
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{<br />
    UITouch *touch =[touches anyObject];<br />
    CGPoint point = [touch locationInView:[touch view]];<br />
    point = [[CCDirector sharedDirector]convertToGL:point];<br />
    greenman.position = ccp(point.x, point.y);<br />
    greenman1.position = ccp(point.x, point.y);<br />
    greenman2.position = ccp(point.x, point.y);<br />
    greenman3.position = ccp(point.x, point.y);<br />
    greenman4.position = ccp(point.x, point.y);</p>
<p>    blueman.position = ccp(point.x, point.y);<br />
    blueman1.position = ccp(point.x, point.y);<br />
    blueman2.position = ccp(point.x, point.y);<br />
    blueman3.position = ccp(point.x, point.y);<br />
    blueman4.position = ccp(point.x, point.y);<br />
}
</p></description>
		</item>
		<item>
			<title>infrid on "2.5d throwing - brain dump"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/13956#post-78674</link>
			<pubDate>Sat, 26 Feb 2011 06:16:38 +0000</pubDate>
			<dc:creator>infrid</dc:creator>
			<guid isPermaLink="false">78674@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I want to throw things into z space along the lines of gnome toss, but not with a catapult, with a flick gesture. The touch recognition, timing, angles and stuff is done, and known factors.. I'm just at the point where I have to decide how to approach the algorithm and I'm being terribly indecisive.</p>
<p>It seems I need to work out, x,y and z positions, based on, angle, length of movement of finger, and amount of time of the flick.</p>
<p>Has anyone done anything similar to this, who can briefly discuss their approach? I'm considering using x as final angle, then a mixture of time of the flick, distance between start points as y/z.</p>
<p>Any tutorials/example code on the matter would be great as I feel like I'm about to spend all day hacking something that feels nice, but then again.. that's not such a bad thing, as it is MY game, so a day's work on the core dynamic is fair play... just tryna keep DRY, that's all :)
</p></description>
		</item>
		<item>
			<title>MarshallHahn on "Add abilities of Touch &amp; Shake Features to a 3D Object .pod"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22656#post-125677</link>
			<pubDate>Sat, 12 Nov 2011 04:27:16 +0000</pubDate>
			<dc:creator>MarshallHahn</dc:creator>
			<guid isPermaLink="false">125677@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello! I started learning how to make iPhone apps about a month ago, and was wondering if you could help me out.<br />
I am making an app where when the device is shaken or the obect is touched, the 3D model will move. It is basically a bobble-head app.<br />
I was wondering how I would come about doing this. I followed your tutorial on your website on how to take it from a blender to a POD, and have replaced the "Head" with the default "hello-world.pod" file in the code.<br />
I have it working so far, but it just sits there.... nothing happens. I cannot click it to make it move or anything. I would really appreciate it if you could help me with this! </p>
<p>Thanks in Advance!<br />
-Marshall
</p></description>
		</item>
		<item>
			<title>xemus on "Adding UIGestureRecognizer support in cocos2d"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8929#post-51655</link>
			<pubDate>Sun, 22 Aug 2010 20:19:31 +0000</pubDate>
			<dc:creator>xemus</dc:creator>
			<guid isPermaLink="false">51655@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I wanted to share some code I've written to allow using UIGestureRecognizer classes with cocos2d.  This code has saved me a tremendous amount of time handling touch events, so hopefully it will help some others out I can get some feedback on them in the process.  The main goal  was to be able to get the gesture recognizers to act as close to original design as possible without a lot of setup work to use them.</p>
<p>This major design change I did to accomplish this was to move touches from CCLayer based to CCNode based, this way can be seen as each node being a view.   Handling touches this way gives you a lot of flexibility and control to test for touches on individual objects of a scene or a layer like a sprite instead of just knowing the layer was touched somewhere.  This change was only for gesture recognizers, I left the way cocos handles individual touch events intact.  My other goal was the gesture recognizers should handle touches across nodes,  but a touch on a particular node can only be handled by itself and it's children, this mimics the way gesture recognizers normally work with subviews.</p>
<p>Note:<br />
Not all code changes are in this post, I made some changes to CCNode such as moving the isTouchEnabled from CCLayer and the code to retain its gesture recognizers and handle the actual attachment to the view.  If this post generates enough interest I will post a full patch.</p>
<p>Example initialization:<br />
<pre><code>CCGestureRecognizer* recognizer = [CCGestureRecognizer CCRecognizerWithRecognizerTargetAction:[[[UIRotationGestureRecognizer alloc]init] autorelease] target:self action:@selector(rotate:node:)];</code></pre>
<p>Example usage:<br />
Usage is very straightforward, the callback function that occurs once a gesture is recognized just needs to take a  UIGestureRecognizer and a CCNode as a parameter.  Normally you can tell what view was touched from the gesture recognizer, but since we only have one view the CCNode that was touched gets passed to the callback function as well.<br />
<pre><code>- (void) rotate:(UIGestureRecognizer*)recognizer node:(CCNode*)node
{
  UIRotationGestureRecognizer* rotate = (UIRotationGestureRecognizer*)recognizer;
  float r = node.rotation;
  node.rotation += CC_RADIANS_TO_DEGREES(rotate.rotation) -r;
}</code></pre>
<p>Here is the source:<br />
CCGestureRecognizer.h<br />
<pre><code>#ifndef __CCGestureRecognizer_H__
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> __CCGestureRecognizer_H__

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;ccTypes.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCNode.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;UIKit/UIKit.h&#62;

@class CCNode;

@interface CCGestureRecognizer : NSObject &#60;UIGestureRecognizerDelegate&#62;
{
  UIGestureRecognizer* m_gestureRecognizer;
  CCNode* m_node;

  id&#60;UIGestureRecognizerDelegate&#62; m_delegate;

  id m_target;
  SEL m_callback;
}

@property(nonatomic,readonly) UIGestureRecognizer* gestureRecognizer;
@property(nonatomic,assign) CCNode* node;
@property(nonatomic,assign) id&#60;UIGestureRecognizerDelegate&#62; delegate;
@property(nonatomic,assign) id target;
@property(nonatomic,assign) SEL callback;

- (id) initWithRecognizerTargetAction:(UIGestureRecognizer*)gestureRecognizer target:(id)target action:(SEL)action;
+ (id) CCRecognizerWithRecognizerTargetAction:(UIGestureRecognizer*)gestureRecognizer target:(id)target action:(SEL)action;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;

// this is the function the gesture recognizer will callback and we will add our CCNode onto it
- (void) callback:(UIGestureRecognizer*)recognizer;
@end

#endif  // end of __CCGestureRecognizer_H__</code></pre>
<p>CCGestureRecognizer.m<br />
It looks m_node isn't retained or released, but when you attach a gesture recognizer to a CCNode the node sets this value and also unsets this value when it is released.   Since CCNode keeps track of gesture recognizers attached to it doing a retain would mean both objects would never get released.<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCGestureRecognizer.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCDirector.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;ccMacros.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CGPointExtension.h&#34;

@implementation CCGestureRecognizer

-(void)dealloc
{
  [m_delegate release];
  [super dealloc];
}

- (UIGestureRecognizer*)gestureRecognizer
{
  return m_gestureRecognizer;
}

- (CCNode*)node
{
  return m_node;
}

- (void)setNode:(CCNode*)node
{
  // we can&#39;t retain the node, otherwise a node will never get destroyed since it contains a
  // ref to this.  if node gets unrefed it will destroy this so all should be good
  m_node = node;
}

- (id&#60;UIGestureRecognizerDelegate&#62;)delegate
{
  return m_delegate;
}

- (void) setDelegate:(id&#60;UIGestureRecognizerDelegate&#62;)delegate
{
  [m_delegate release];
  m_delegate = delegate;
  [m_delegate retain];
}

- (id)target
{
  return m_target;
}

- (void)setTarget:(id)target
{
  [m_target release];
  m_target = target;
  [m_target retain];
}

- (SEL)callback
{
  return m_callback;
}

- (void)setCallback:(SEL)callback
{
  m_callback = callback;
}

- (id)initWithRecognizerTargetAction:(UIGestureRecognizer*)gestureRecognizer target:(id)target action:(SEL)action
{
  if( (self=[super init]) )
  {
    m_gestureRecognizer = gestureRecognizer;
    [m_gestureRecognizer retain];
    [m_gestureRecognizer addTarget:self action:@selector(callback:)];

    // setup our new delegate
    m_delegate = m_gestureRecognizer.delegate;
    m_gestureRecognizer.delegate = self;

    m_target = target;
    [m_target retain];
    m_callback = action;
  }
  return self;
}

+ (id)CCRecognizerWithRecognizerTargetAction:(UIGestureRecognizer*)gestureRecognizer target:(id)target action:(SEL)action
{
  [[[self alloc] initWithRecognizerTargetAction:gestureRecognizer target:target action:action] autorelease];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
  CGPoint pt = [[CCDirector sharedDirector] convertToGL:[touch locationInView: [touch view]]];

  BOOL rslt = [m_node isPointInArea:pt];

  if( rslt )
  {
    // still ok, now check children of parents after this node
    CCNode* node = m_node;
    CCNode* parent = m_node.parent;
    while( node != nil &#38;&#38; rslt)
    {
      CCNode* child;
      BOOL nodeFound = NO;
      CCARRAY_FOREACH(parent.children, child)
      {
        if( !nodeFound )
        {
          if( !nodeFound &#38;&#38; node == child )
            nodeFound = YES;  // we need to keep track of until we hit our node, any past it have a higher z value
          continue;
        }

        if( [child isNodeInTreeTouched:pt] )
        {
          rslt = NO;
          break;
        }
      }

      node = parent;
      parent = node.parent;
    }
  }

  if( rslt &#38;&#38; m_delegate )
    rslt = [m_delegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];

  return rslt;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
  if( !m_delegate )
    return YES;
  return [m_delegate gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
  if( !m_delegate )
    return YES;
  return [m_delegate gestureRecognizerShouldBegin:gestureRecognizer];
}

- (void)callback:(UIGestureRecognizer*)recognizer
{
  if( m_target )
    [m_target performSelector:m_callback withObject:recognizer withObject:m_node];
}
@end</code></pre>
<p>Here are some of the changes to CCNode<br />
<pre><code>-(BOOL) isPointInArea:(CGPoint)pt
{
  if( !visible_ )
    return NO;

  /*  convert the point to the nodes local coordinate system to make it
   easier to compare against the area the node occupies*/
  pt = [self convertToNodeSpace:pt];

  // we have to take the anchor point into account for checking
  CGRect rect;
  /*  we should be able to use touchableArea here, even if a node doesn&#39;t set
   this, it will return the contentArea.  */
  rect.size = self.touchableArea;
  CGPoint anchor = anchorPoint_;

  // we pretty much need to undo the anchor to get our rect to start at the lower left
  anchor.x = 0.5f - anchor.x;
  anchor.y = 0.5f - anchor.y;

  rect.origin = CGPointMake( -(rect.size.width*anchor.x), -(rect.size.height*anchor.y) );

  if( CGRectContainsPoint(rect,pt) )
    return YES;
  return NO;
}

-(BOOL) isNodeInTreeTouched:(CGPoint)pt
{
  if( [self isPointInArea:pt] )
    return YES;

  BOOL rslt = NO;
  CCNode* child;
  CCARRAY_FOREACH(children_, child )
  {
    if( [child isNodeInTreeTouched:pt] )
    {
      rslt = YES;
      break;
    }
  }
  return rslt;
}

-(CGSize) touchableArea
{
  // we use content size if touchable area is 0
  if( touchableArea_.width != 0.0f &#38;&#38;
      touchableArea_.height != 0.0f )
    return touchableArea_;
  else
    return contentSize_;
}

-(void) setTouchableArea:(CGSize)area
{
	touchableArea_ = area;
}</code></pre></description>
		</item>
		<item>
			<title>Toucher1 on "How to remove/add tiles where you touch???"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15934#post-89949</link>
			<pubDate>Mon, 25 Apr 2011 19:04:29 +0000</pubDate>
			<dc:creator>Toucher1</dc:creator>
			<guid isPermaLink="false">89949@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>How do I remove or add a Tile from my TMXTiledMap when I touch on it?</p>
<p>I tried to remove Tiles, but this isn't working:</p>
<pre><code>-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch=[touches anyObject];
    CGPoint touchLocation = [touch locationInView: [touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
    touchLocation = [self convertToNodeSpace:touchLocation];

    [background removeTileAt:touchLocation];
}</code></pre>
<p>Please help me!
</p></description>
		</item>
		<item>
			<title>iclem on "Detecting touch in layers and sprites"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22514#post-124959</link>
			<pubDate>Tue, 08 Nov 2011 04:42:41 +0000</pubDate>
			<dc:creator>iclem</dc:creator>
			<guid isPermaLink="false">124959@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am having a problem detecting touch in a layer and then again in a sprite. Basically, I have a layer with upgrades. The upgrades a are scrollable, thus I need to detect touch in the layer itself. Then, the upgrades have plus and minus signs which need to detect touch as well. I am using a selector on the plus and minus signs in order to continue to add or subtract upgrade points quickly. When holding a touch on a sign, then points continuously add or subtract. Upon touchEnd, I unschedule the selector to stop subtracting or adding points. the problem is, I need to return a boolean value of YES or True in the touchBegan function in order to call touch end to unschedule the selector. When using a boolean value of YES or True, all the other objects that use touch do not work. How do I fix this problem? Here is my code:</p>
<p>my upgrades all look similar to this<br />
<pre><code>- (void)onEnter
{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
    [super onEnter];
}
- (void)onExit
{
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
	CGPoint touchLocation = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	touchLocation = [self convertToNodeSpace:touchLocation];

    points = [prefs integerForKey:@&#34;points&#34;];

    if(ccpDistance(touchLocation, plus.position) &#60; plus.contentSize.width/2 &#38;&#38; pointsRequired &#60;= points &#38;&#38; upgradePoints &#60; upgradePointsMax)
    {
        upgradePoints++;
        pointsString = [NSString stringWithFormat:@&#34;%i/%i&#34;, upgradePoints, upgradePointsMax];
        [pointsLabel setString:pointsString];
        points--;
        [prefs setInteger:points forKey:@&#34;points&#34;];

        level.pointsString = [NSString stringWithFormat:@&#34;Points: %i&#34;, points];
        [level.pointsLabel setString:level.pointsString];

        //[self schedule:@selector(increase) interval:0.1];
        //plusPoints = true;
    }
    else if(ccpDistance(touchLocation, minus.position) &#60; minus.contentSize.width/2 &#38;&#38; upgradePoints &#62; 0)
    {
        upgradePoints--;
        pointsString = [NSString stringWithFormat:@&#34;%i/%i&#34;, upgradePoints, upgradePointsMax];
        [pointsLabel setString:pointsString];
        points++;
        [prefs setInteger:points forKey:@&#34;points&#34;];

        level.pointsString = [NSString stringWithFormat:@&#34;Points: %i&#34;, points];
        [level.pointsLabel setString:level.pointsString];

        //[self schedule:@selector(decrease) interval:0.1];
        //minusPoints = true;
    }

    if(ccpDistance(touchLocation, background.position) &#60; background.contentSize.width/2)
    {
        [level.infoLabel setString:@&#34;Laser Speed: Upgrading will result in an increase in laser rate of fire.&#34;];
    }

    return YES;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    if(plusPoints)
    {
        [self unschedule:@selector(increase)];
        plusPoints = false;
    }
    else if(minusPoints)
    {
        [self unschedule:@selector(decrease)];
        minusPoints = false;
    }
}

-(void) decrease
{
    if(upgradePoints &#62; 0)
    {
        upgradePoints--;
        pointsString = [NSString stringWithFormat:@&#34;%i/%i&#34;, upgradePoints, upgradePointsMax];
        [pointsLabel setString:pointsString];
        points++;
        [prefs setInteger:points forKey:@&#34;points&#34;];

        level.pointsString = [NSString stringWithFormat:@&#34;Points: %i&#34;, points];
        [level.pointsLabel setString:level.pointsString];
    }
}

- (void) increase
{
    if(pointsRequired &#60; points &#38;&#38; upgradePoints &#60; upgradePointsMax)
    {
        upgradePoints++;
        pointsString = [NSString stringWithFormat:@&#34;%i/%i&#34;, upgradePoints, upgradePointsMax];
        [pointsLabel setString:pointsString];
        points--;
        [prefs setInteger:points forKey:@&#34;points&#34;];

        level.pointsString = [NSString stringWithFormat:@&#34;Points: %i&#34;, points];
        [level.pointsLabel setString:level.pointsString];
    }
}</code></pre>
<p>my layer looks like this<br />
<pre><code>- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
	CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	location = [self convertToNodeSpace:location];

    startLocation = location;
    prevLocation = location;

    return YES;
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
	CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	location = [self convertToNodeSpace:location];

    if (startLocation.y - location.y &#62; 5 &#124;&#124; startLocation.y - location.y &#60; -5)
    {
        for (int i = 0; i &#60; [upgrades count]; i++)
        {
            Upgrade *upgrade = [upgrades objectAtIndex:i];
            upgrade.position = ccp(upgrade.position.x, upgrade.position.y + ((prevLocation.y - location.y) * -1));
        }
    }
    prevLocation = location;
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
	CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	location = [self convertToNodeSpace:location];

	if(ccpDistance(location, backButton.position) &#60; backButton.contentSize.width/2)
	{
		[[CCDirector sharedDirector] popSceneWithTransition:[CCTransitionFade class] duration:0.5f];
	}

    if (startLocation.y - location.y &#62; 60 &#38;&#38; startLocation.y - location.y &#60; LPU.background.contentSize.width * 2 &#38;&#38; pageNumber &#62; 1)
    {
        [self moveBack];
    }
    else if (startLocation.y - location.y &#62; LPU.background.contentSize.width * 2 &#38;&#38; pageNumber &#62; 2)
    {
        [self moveBack2];
    }
    else if(startLocation.y - location.y &#62;= LPU.background.contentSize.width * 2 &#38;&#38; pageNumber == 2)
    {
        [self moveBack];
    }
    else if(startLocation.y - location.y &#60; -60 &#38;&#38; startLocation.y - location.y &#62; -LPU.background.contentSize.height * 2 &#38;&#38; pageNumber &#60; maxPages)
    {
        [self moveForward];
    }
    else if(startLocation.y - location.y &#60; -LPU.background.contentSize.height * 2 &#38;&#38; pageNumber &#60; maxPages - 1)
    {
        [self moveForward2];
    }
    else if(startLocation.y - location.y &#62;= LPU.background.contentSize.width * 2 &#38;&#38; pageNumber == 2)
    {
        [self moveForward];
    }
    else
    {
        for (int i = 0; i &#60; [upgrades count]; i++)
        {
            Upgrade *upgrade = [upgrades objectAtIndex:i];

            [upgrade runAction:[CCMoveTo actionWithDuration:0.4 position:ccp(upgrade.location.x, upgrade.location.y)]];
        }
    }
    [self updatePage];
}

-(void) registerWithTouchDispatcher
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}</code></pre></description>
		</item>
		<item>
			<title>gametreesnet on "All About Touch"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22424#post-124434</link>
			<pubDate>Fri, 04 Nov 2011 02:14:26 +0000</pubDate>
			<dc:creator>gametreesnet</dc:creator>
			<guid isPermaLink="false">124434@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello people!<br />
I'm here to ask questions about touch detection.<br />
Generally, there is this code in every touch code:<br />
UITouch* touch = [touches anyObject];</p>
<p>Without making it anyObject, how can I make a touch detection to a certain location or an object?<br />
Also, what is KEventHandled?<br />
Thanks!
</p></description>
		</item>
		<item>
			<title>artemisworks on "Cocos2D touch locations - compiling with armv6/armv7 and optimized armv7"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22368#post-124173</link>
			<pubDate>Wed, 02 Nov 2011 09:53:16 +0000</pubDate>
			<dc:creator>artemisworks</dc:creator>
			<guid isPermaLink="false">124173@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>While making my game for the iPhone/iPod Touch, I noticed something strange about the following. I would like to detect the screen X,Y coordinates where the player touches in order to perform certain actions.<span class="Apple-style-span">&#160;<br /></span><div><br /></div><div><br /></div><div><br />
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">-(<span>void</span>)ccTouchEnded:(<span>UITouch</span> *)touch withEvent:(<span>UIEvent</span> *)event {</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"><span class="Apple-tab-span">	</span><span>CGPoint</span> touchLocation = [touch <span>locationInView</span>:[touch <span>view</span>]];</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"><span class="Apple-tab-span">	</span><span>CGPoint</span> playerPosition;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"><span class="Apple-tab-span">	</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"><span class="Apple-tab-span">	</span>playerPosition = <span>self</span>.<span>playerSprite</span>.<span>position</span>;</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">if (touchLocation.x &#60; 500.0f) {do something; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">if (touchLocation.y &#62;= 100.0f) { do something; }</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">//TEST</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">CCLOG(@"X location touched: %f",touchLocation.x);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo">CCLOG(@"Y location touched: %f",touchLocation.y);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"><h3><span class="Apple-style-span">I found that if I compile my code with armv7 (optimized) and test it on my iPhone device, the code works as it should. However if I compile it with armv6,armv7 architectures both enabled, then the actual touch location CHANGES... as I've discovered from the CCLOG statements. Why is this so and have I omitted something? The above code works with the simulator fine, but fails on the device when I compile with armv6/armv7 enabled, because the detected coordinates are different.</span><br /></h3><span class="Apple-style-span"><h3><span class="Apple-style-span">Can someone throw some light on this?</span></h3></span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px;font: 11.0px Menlo"></p>
</div>
</p></description>
		</item>
		<item>
			<title>gcc on "Box2D collision issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22161#post-123074</link>
			<pubDate>Wed, 26 Oct 2011 10:30:41 +0000</pubDate>
			<dc:creator>gcc</dc:creator>
			<guid isPermaLink="false">123074@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello!</p>
<p>First of all, this is my very very first Box2D project, so sorry if my questions are noob questions :) Thanks!</p>
<p>I need a little help to resolve my problem with Box2D and collision. I made a circle shape (dynamic body) and I added 12 little circle shape with weld joint on the edge of the big circle. This is the "wheel". I also added a box shape (a rectangle, dynamic body) as a "sticker" on the right side of the composition. This would be something like a trap door. The both of these are joined (RevoluteJoint) to the ground to fix the position of them. So, if I rotate the wheel with touch and SetTransform() then the collision doesn't work properly. If I rotate the wheel with SetAngularVelocity() then the collision is perfect. The gravity is zero. I made a sandbox from a basic cocos2d template. What's the problem?</p>
<p>The other problem is that when I not include after the SetTransform() call the SetAngularVelocity(0.0001f) call then only the joint lines are moving/rotating or I don't know they are doing...</p>
<p>I would like to create a fortune wheel: Something like this: <a href="http://www.wkbingo.com/photo_08/fortune_wheel.jpg">Fortune Wheel</a></p>
<p>Here's the problem:<br />
<img src="http://f.cl.ly/items/2x143M3U2I461G3F2s0v/collisionProblem.jpg" /></p>
<p>I think the best is that you can download the sample I made: <a href="http://cl.ly/1V1E0H410z022q2k441F" rel="nofollow">http://cl.ly/1V1E0H410z022q2k441F</a></p>
<p>Thanks for your time!
</p></description>
		</item>
		<item>
			<title>0u73rh34v3n on "Selecting/ Touching an isometric tile"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21721#post-120676</link>
			<pubDate>Tue, 11 Oct 2011 18:51:53 +0000</pubDate>
			<dc:creator>0u73rh34v3n</dc:creator>
			<guid isPermaLink="false">120676@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Greetings,</p>
<p>How do I make an isometric tile selectable?<br />
i.e I touch the tile and then do what ever I want with it.</p>
<p>The problem I'm having right now is I don't know how to make a tile touchable.<br />
I followed a youtube tutorial on collisions and adapted it for my program (see code below).<br />
I think I'm doing everything right, but 1 line keeps failing the build. I don't know why, because it doesn't fail for the guy in the tutorial...<br />
stLayer is the layer with the tile I want selectable.</p>
<p>Any help would be greatly appreciated.</p>
<pre><code>-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CCLOG(@&#34;Touch Begin&#34;);

    CGPoint touchObject = [touch locationInView: [touch view]];
    touchObject = [[CCDirector sharedDirector] convertToGL: touchObject];
    touchObject = [self convertToNodeSpace: touchObject];

    //----- THIS LINE FAILS THE BUILD. &#34;INVALID INITIALIZER&#34; -----------
    CGPoint tileCoord = [stLayer tileCoordForPosition:touchObject];

    int tileGid = [stLayer tileGIDAt: tileCoord];

    if(tileGid)
    {
        NSDictionary *properties = [theMap propertiesForGID:tileGid];

        if(properties)
        {
            NSString *building1Tile = [properties valueForKey:@&#34;building1&#34;];
            if(building1Tile &#38;&#38; [building1Tile compare:@&#34;TRUE&#34;] ==NSOrderedSame)
            {
                CCLOG(@&#34;Object Touched&#34;);
            }
        }
    }
    else
    {
        CGRect boundingRect = CGRectMake(0, 0, 32*50, 16*50);
        _controller = [[CCPanZoomController controllerWithNode:self] retain];
        _controller.boundingRect = boundingRect;
        _controller.zoomOutLimit = _controller.optimalZoomOutLimit;
        _controller.zoomInLimit = 2.0f;

        [_controller enableWithTouchPriority:0 swallowsTouches:YES];
    }
    return YES;
}</code></pre>
<p>Thank you!
</p></description>
		</item>
		<item>
			<title>pimms on "Multi-touch tutorial"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17540#post-98544</link>
			<pubDate>Sat, 11 Jun 2011 09:54:19 +0000</pubDate>
			<dc:creator>pimms</dc:creator>
			<guid isPermaLink="false">98544@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>OK. I accidentaly pressed backspace and everything got erased as I went back to the forum menu (arrrgggh...). Anways, this is gonna be a quick (!) brief on how to implement multi touch. I'm not going in depth on advanced touch-handling, primarily as I learned this like 15 minutes ago. </p>
<p>This tutorial is aimed for those struggling getting their multi-touch working, and most likely recently started with Cocos2D. I assume you are still somewhat experienced with ObjC in general.</p>
<p><strong>Getting started</strong></p>
<p>If you've read / watched any tutorials online, chances are you've been instructed to register your class with the touchDispatcher like this:</p>
<p><code>[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES];</code></p>
<p>First thing you're gonna have to do is to remove that line of code. Forget about it. Upon registering with the dispatcher, the dispatcher messages your class with the single-touch methods upon a touch, and the multi-touch methods are never even called. And with the single-touch methods probably not being implemented, this is bound to cause an error.</p>
<p>With that out of the way, let's move on.</p>
<p><strong>Moving on</strong></p>
<p>You've probably already guessed that<br />
<code>-(void) ccTouches Began/Moved/Ended/Cancelled</code><br />
are the methods we will be using for multi touch.</p>
<p>The way I look at it, there are two primary ways of checking the touches on the screen. You have the <em>iteration way</em>, and the <em>retrieve object by array-index way</em>. </p>
<p><strong>Iteration</strong></p>
<p>Iteration-checking is just that. You iterate through all the touches in a for-loop, and do stuff with them. By doing so, you are guaranteed to look through all the touches present on the screen. Even the misplaced thumb caused by holding the phone phunny. (That was funny, laugh.)</p>
<pre><code>-(void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    for ( UITouch* touch in touches ) {
         CGPoint location = [touch locationInView:[touch view]];
         location = [[CCDirector sharedDirector] convertToGL:location];

         //code
    }
}</code></pre>
<p><strong>Array-index retrieval</strong></p>
<p>By performing the touch-checker this way, you stand the risk of not checking the touches you actually want to check. Obviously, at times it's what is best for the game. </p>
<pre><code>-(void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    NSArray *touchArray = [touches allObjects];

    UITouch *touchOne = [touchArray objectAtIndex:0];
    CGPoint locationOne = [touchOne locationInView:[touchOne location]];

    //CODE

    if ( [touchArray count] &#62; 1 ) {
        UITouch *touchTwo = [touchArray objectAtIndex:1];
        //Location, CODE
    }

    //And so forth...
}</code></pre>
<p>As mentioned in the start, I'm not gonna go in depth on any advanced code. The reason I made this tutorial is the fact that after several hours of searching, all I've been able to find is scraps and pieces of how to do this. I hope this was of help to someone out there.</p>
<p>//pimms
</p></description>
		</item>
		<item>
			<title>phantomsri on "how to detect touch in a circle"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21629#post-120212</link>
			<pubDate>Sat, 08 Oct 2011 13:21:43 +0000</pubDate>
			<dc:creator>phantomsri</dc:creator>
			<guid isPermaLink="false">120212@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I really need help.<br />
i have a circle sprite, and this code</p>
<pre><code>-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGSize winSize =[[CCDirector sharedDirector] winSize];
    UITouch* myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView: [myTouch view]];
    location = [[CCDirector sharedDirector]convertToGL:location];

    CCSprite *circleSprite = (CCSprite*)[self getChildByTag:30];
    CGRect correctColorSprite1 = [circleSprite boundingBox];

        if (CGRectContainsPoint(correctColorSprite1, location)) {
       NSLog(@&#34;inside&#34;);
}</code></pre>
<p>as i know there is a bounding box, when i touch slightly outside of the top circle it will still detect the touch.<br />
Now i need help to eliminate this, i have read this post from this link <a href="http://www.cocos2d-iphone.org/forum/topic/8803" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/8803</a>.</p>
<p>But after reading it I'm confused how to incorporate it.  Currently my circle size is in 50 points.<br />
I hope someone can help me out give me some snippets of a improved code to detect the touch only in the circle.
</p></description>
		</item>

	</channel>
</rss>

