<?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: touches - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/touches</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 04:10:03 +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/touches/topics" rel="self" type="application/rss+xml" />

		<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>jackrabbit on "Swallowing touches disables touches on layer?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22712#post-125838</link>
			<pubDate>Sun, 13 Nov 2011 19:36:14 +0000</pubDate>
			<dc:creator>jackrabbit</dc:creator>
			<guid isPermaLink="false">125838@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I basically have a layer with a scrolling picture (CCScrollView) and a CCMenuItem. When I add:</p>
<pre><code>- (void)onEnter {
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:YES];
    [super onEnter];
}

- (void)onExit {
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
    [super onExit];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

    return TRUE;

}</code></pre>
<p>to swallow touches, the CCMenuItem doesn't work anymore, and the picture becomes unscrollable. I tried to make another layer to swallow touches and put it behind this layer. However, I still have the same problem (I also tried playing around with the priorities of the two layers). What am I missing?
</p></description>
		</item>
		<item>
			<title>ktowncoder on "Why is my basic case touch detection not working?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28461#post-140088</link>
			<pubDate>Wed, 18 Jan 2012 19:43:07 +0000</pubDate>
			<dc:creator>ktowncoder</dc:creator>
			<guid isPermaLink="false">140088@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I can't understand why this isn't working- I am not swallowing touches, or anything, unless I am missing something..</p>
<pre><code>-(id) init{
    self = [super init];

    if (self!=nil){
        CCSprite *titleSprite = [CCSprite spriteWithFile:@&#34;introScreen.png&#34;];
        [self addChild:titleSprite z:0];
        [titleSprite setPosition:CGPointMake(160, 240)];
        self.isTouchEnabled=YES;
        [self schedule:@selector(splashTimerCallback) interval:2.0];
    }

    return self;
}

-(void) splashTimerCallback{
    [self unschedule:@selector(splashTimerCallback)];
    AppDelegate *delegate= [[UIApplication sharedApplication] delegate];
    [delegate toLoginScene];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self splashTimerCallback];
    printf(&#34;Touched\n&#34;);
}</code></pre>
<p>Cheers!
</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>pabloruiz55 on "Polling Layer for current touches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/27962#post-137322</link>
			<pubDate>Fri, 30 Dec 2011 11:18:05 +0000</pubDate>
			<dc:creator>pabloruiz55</dc:creator>
			<guid isPermaLink="false">137322@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi guys, i am having the following problem and i would like to know if you could help me, thanks in advance!</p>
<p>Suppose i am in scene 1, i touch my CCLayer to move the main character around the screen. When the character reaches a certain point we move to scene 2 (by doing a CCDirector replace scene).<br />
Now, being on scene 2, i want to have the character keep moving if the user is still touching the screen.<br />
The problem is that i can't figure out how to do this. Since the player was already touching the screen when we got to scene 2, i won't get a CCTouchedBegan event called.<br />
The solution i am thinking would be to somehow poll the new layer of scene 2 (or who knows what) asking it: "Hey are you being touched? Where exactly?"<br />
Problem is that i don't know if this is even possible. Any clues or other solutions?<br />
Thanks
</p></description>
		</item>
		<item>
			<title>Jannes Klaas on "2nd Touch is swallowed"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28038#post-137789</link>
			<pubDate>Tue, 03 Jan 2012 17:32:11 +0000</pubDate>
			<dc:creator>Jannes Klaas</dc:creator>
			<guid isPermaLink="false">137789@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello together,<br />
I´m a bit new to Cocos 2d so don´t eat me if this is a stupid question.<br />
I have a simple game where you shoot monsters while jumping over obstacles. I register for touches with this code in the init method of the layer:</p>
<p>self.isTouchEnabled = YES;<br />
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];</p>
<p>and this is my method to handle touches:</p>
<p>-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {<br />
    CGPoint location = [touch locationInView:[touch view]];<br />
    location = [[CCDirector sharedDirector] convertToGL:location];</p>
<p>   // Is the touch on the jump button<br />
    BOOL isInX = location.x &#62;0 &#38;&#38; location.x &#60;_jumpButton.contentSize.width;<br />
    BOOL isInY = location.y &#62;0 &#38;&#38; location.y &#60;_jumpButton.contentSize.height;</p>
<p>    if (isInX &#38;&#38; isInY) {<br />
        [self jump];<br />
        return YES;<br />
    }</p>
<p>    [self shoot:[NSArray arrayWithObjects:[NSNumber numberWithInt:location.x],[NSNumber numberWithInt:location.y], nil]];</p>
<p>    return YES;<br />
}</p>
<p>Everything works fine, as long as you don´t have two fingers on the device at the same time, for example: You press the jump button and shoot but your finger is still at the jump button. There is no shoot. The method is not called. I don´t understand that, because it´s a new touch that began, to the touch began method should be called.<br />
I tried various things like using ccTouchesBegan or ccTouchesEnded, but it did not help. I also tried using a standartDelegate, but then the method was not called at all.</p>
<p>Can you help me? The gamplay is really bad if you only have one finger at a time.<br />
Thanks in advance, Jannes
</p></description>
		</item>
		<item>
			<title>fuzz on "accurate touch value"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/24781#post-130671</link>
			<pubDate>Fri, 02 Dec 2011 06:16:52 +0000</pubDate>
			<dc:creator>fuzz</dc:creator>
			<guid isPermaLink="false">130671@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to calculate the distance I drag my finger in ccTouchesEnded,<br />
I do this by making the distance float the difference between the old touch and new touch location.<br />
This however always gives me whole values like 1.000, 2.000, is there a way I could get more accurate decimal values?</p>
<p>[code]- (void)ccTouchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {<br />
	UITouch *touch = [touches anyObject];<br />
	CGPoint location = [touch locationInView:[touch view]];<br />
	location = [[CCDirector sharedDirector] convertToGL:location];<br />
	float distance = oldLocation.y - location.y;<br />
	oldLocation = location;<br />
}[/code]
</p></description>
		</item>
		<item>
			<title>jed758 on "Detecting Touches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/23892#post-128974</link>
			<pubDate>Sun, 27 Nov 2011 09:57:52 +0000</pubDate>
			<dc:creator>jed758</dc:creator>
			<guid isPermaLink="false">128974@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>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>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>callispo on "porting cocos2d + box2d game to iPad"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22796#post-126183</link>
			<pubDate>Tue, 15 Nov 2011 14:44:55 +0000</pubDate>
			<dc:creator>callispo</dc:creator>
			<guid isPermaLink="false">126183@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to port my game to iPad, I have tried various things. </p>
<p>- Hacking ccFileUtils.m<br />
- Overriding CC_CONTENT_SCALE_FACTOR() to return 2 in case of iPad (using Apple's Macro)<br />
- Manually calling setContentScaleFactor for CCDirector. </p>
<p>However, I keep running into problems like: </p>
<p>- The sprites are not positioned properly<br />
- Physical bodies are not aligning properly with the sprites.<br />
- Touches location are all messed up.</p>
<p>I tried modifying ccp macro, but I cant get it running right. My objective is to simply use hd images which I've made for iphone4  in the iPad version and fill out the extra spaces with a border or something. If anyone out there has successfully achieved this, please help me out :)
</p></description>
		</item>
		<item>
			<title>jackrabbit on "Making CCScrollView swallow touches, but still scroll?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22505#post-124924</link>
			<pubDate>Mon, 07 Nov 2011 22:58:38 +0000</pubDate>
			<dc:creator>jackrabbit</dc:creator>
			<guid isPermaLink="false">124924@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am creating a popup CCScrollLayer (instructions to a game)- however, I want it to swallow touches. I added</p>
<pre><code>- (void)onEnter {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:YES];
[super onEnter];
}

- (void)onExit {
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {

return TRUE;

}
[/code]

This swallows the touches, but then the layer will not scroll. Here is the code for CCScrollView:

[code]//
// CCScrollView.m
// CCTable
//
// Created by Sangwoo Im on 6/3/10.
// Copyright 2010 Sangwoo Im. All rights reserved.
//

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCScrollView.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCActionInstant.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCActionInterval.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CGPointExtension.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CCTouchDispatcher.h&#34;

#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> SCROLL_DEACCEL_RATE 0.95f
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> SCROLL_DEACCEL_DIST 1.0f
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> BOUNCE_DURATION 0.35f
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> BOUNCE_STEP 0.1
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> INSET_RATIO 0.3f

@interface CCScrollView()
/**
* container is a protected property
*/
@property (nonatomic, retain) CCLayer *container_;
/**
* initial touch point
*/
@property (nonatomic, assign) CGPoint touchPoint_;
/**
* determines whether touch is moved after begin phase
*/
@property (nonatomic, assign) BOOL touchMoved_;
@end

@interface CCScrollView (Private)

/**
* Init this object with a given size to clip its content.
*
* @param size view size
* @return initialized scroll view object
*/
-(id)initWithViewSize:(CGSize)size;
/**
* Relocates the container at the proper offset, in bounds of max/min offsets.
*
* @param animated If YES, relocation is animated
*/
-(void)relocateContainer:(BOOL)animated;
/**
* implements auto-scrolling behavior. change SCROLL_DEACCEL_RATE as needed to choose
* deacceleration speed. it must be less than 1.0f.
*
* @param dt delta
*/
-(void)deaccelerateScrolling:(ccTime)dt;
/**
* This method makes sure auto scrolling causes delegate to invoke its method
*/
-(void)performedAnimatedScroll:(ccTime)dt;
/**
* Expire animated scroll delegate calls
*/
-(void)stoppedAnimatedScroll:(CCNode *)node;

@end

@implementation CCScrollView
@synthesize direction = direction_;
@synthesize clipToBounds = clipToBounds_;
@synthesize viewSize = viewSize_;
@synthesize bounces = bounces_;
@synthesize isDragging = isDragging_;
@synthesize delegate = delegate_;
@synthesize touchPoint_;
@synthesize touchMoved_;
@synthesize container_;

@dynamic contentOffset;

#pragma mark -
#pragma mark init
+(id)scrollViewWithViewSize:(CGSize)size {
return [[[CCScrollView alloc] initWithViewSize:size] autorelease];
}
-(id)initWithViewSize:(CGSize)size {
if ((self = [super init])) {
self.container_ = [CCLayer node];
self.viewSize = size;

delegate_ = nil;
bounces_ = YES;
clipToBounds_ = YES;
container_.contentSize = CGSizeZero;
direction_ = CCScrollViewDirectionBoth;
container_.position = ccp(0.0f, 0.0f);

[self addChild:container_];
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0];
}
return self;
}
-(id)init {
// CCAssert(NO, @&#34;CCScrollView: DO NOT initialize CCScrollview directly.&#34;);
return nil;
}
#pragma mark -
#pragma mark Properties
-(void)setContentOffset:(CGPoint)offset {
[self setContentOffset:offset animated:NO];
}
-(void)setContentOffset:(CGPoint)offset animated:(BOOL)animated {
if (animated) { //animate scrolling
NSAutoreleasePool *pool;
CCFiniteTimeAction *scroll, *expire;

pool = [NSAutoreleasePool new];
scroll = [CCMoveTo actionWithDuration:BOUNCE_DURATION position:offset];
expire = [CCCallFunc actionWithTarget:self selector:@selector(stoppedAnimatedScroll:)];
[container_ runAction:[CCSequence actions:scroll, expire, nil]];
[self schedule:@selector(performedAnimatedScroll:)];
[pool drain];
} else { //set the container position directly
container_.position = offset;
[delegate_ scrollViewDidScroll:self];
}
}
-(CGPoint)contentOffset {
return container_.position;
}
-(void)setViewSize:(CGSize)size {
if (!CGSizeEqualToSize(viewSize_, size)) {
viewSize_ = size;
maxInset_ = [self maxContainerOffset];
maxInset_ = ccp(maxInset_.x + viewSize_.width * INSET_RATIO,
maxInset_.y + viewSize_.height * INSET_RATIO);
minInset_ = [self minContainerOffset];
minInset_ = ccp(minInset_.x - viewSize_.width * INSET_RATIO,
minInset_.y - viewSize_.height * INSET_RATIO);
}
}
#pragma mark -
#pragma mark Private
-(void)relocateContainer:(BOOL)animated {
CGPoint oldPoint, min, max;
CGFloat newX, newY;

min = [self minContainerOffset];
max = [self maxContainerOffset];

oldPoint = container_.position;
newX = MIN(oldPoint.x, max.x);
newX = MAX(newX, min.x);
newY = MIN(oldPoint.y, max.y);
newY = MAX(newY, min.y);
if (newY != oldPoint.y &#124;&#124; newX != oldPoint.x) {
[self setContentOffset:ccp(newX, newY) animated:animated];
}
}
-(CGPoint)maxContainerOffset {
return ccp(0.0f, 0.0f);
}
-(CGPoint)minContainerOffset {
return ccp(viewSize_.width - self.contentSize.width, viewSize_.height - self.contentSize.height);
}
-(CGSize)viewSize{
return viewSize_;
}
-(void)deaccelerateScrolling:(ccTime)dt {
if (isDragging_) {
[self unschedule:@selector(deaccelerateScrolling:)];
return;
}

CGFloat newX, newY;
CGPoint maxInset, minInset;

container_.position = ccpAdd(container_.position, scrollDistance_);

if (bounces_) {
maxInset = maxInset_;
minInset = minInset_;
} else {
maxInset = [self maxContainerOffset];
minInset = [self minContainerOffset];
}

//check to see if offset lies within the inset bounds
newX = MIN(container_.position.x, maxInset.x);
newX = MAX(newX, minInset.x);
newY = MIN(container_.position.y, maxInset.y);
newY = MAX(newY, minInset.y);

scrollDistance_ = ccpSub(scrollDistance_, ccp(newX - container_.position.x, newY - container_.position.y));
scrollDistance_ = ccpMult(scrollDistance_, SCROLL_DEACCEL_RATE);
[self setContentOffset:ccp(newX,newY)];

if ((fabsf(scrollDistance_.x) &#60;= SCROLL_DEACCEL_DIST &#38;&#38;
fabsf(scrollDistance_.y) &#60;= SCROLL_DEACCEL_DIST) &#124;&#124;
newX == maxInset.x &#124;&#124; newX == minInset.x &#124;&#124;
newY == maxInset.y &#124;&#124; newY == minInset.y) {
[self unschedule:@selector(deaccelerateScrolling:)];
[self relocateContainer:YES];
}
}
-(void)stoppedAnimatedScroll:(CCNode *)node {
[self unschedule:@selector(performedAnimatedScroll:)];
}
-(void)performedAnimatedScroll:(ccTime)dt {
if (isDragging_) {
[self unschedule:@selector(performedAnimatedScroll:)];
return;
}
[delegate_ scrollViewDidScroll:self];
}
#pragma mark -
#pragma mark overriden
-(CGSize)contentSize {
return CGSizeMake(self.scaleX * container_.contentSize.width, self.scaleY * container_.contentSize.height);
}
-(void)setContentSize:(CGSize)size {
container_.contentSize = size;
maxInset_ = [self maxContainerOffset];
maxInset_ = ccp(maxInset_.x + viewSize_.width * INSET_RATIO,
maxInset_.y + viewSize_.height * INSET_RATIO);
minInset_ = [self minContainerOffset];
minInset_ = ccp(minInset_.x - viewSize_.width * INSET_RATIO,
minInset_.y - viewSize_.height * INSET_RATIO);
}
/**
* make sure all children go to the container
*/
-(void)addChild:(CCNode *)node z:(int)z tag:(int)aTag {
node.isRelativeAnchorPoint = YES;
node.anchorPoint = ccp(0.0f, 0.0f);
if (container_ != node) {
[container_ addChild:node z:z tag:aTag];
} else {
[super addChild:node z:z tag:aTag];
}
}
/**
* clip this view so that outside of the visible bounds can be hidden.
*/
-(void)beforeDraw {
if (clipToBounds_) {
GLfloat planeTop[] = {0.0f, -1.0f, 0.0f, viewSize_.height};
GLfloat planeBottom[] = {0.0f, 1.0f, 0.0f, 0.0f};
GLfloat planeLeft[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat planeRight[] = {-1.0f, 0.0f, 0.0f, viewSize_.width};

glClipPlanef(GL_CLIP_PLANE0, planeTop);
glClipPlanef(GL_CLIP_PLANE1, planeBottom);
glClipPlanef(GL_CLIP_PLANE2, planeLeft);
glClipPlanef(GL_CLIP_PLANE3, planeRight);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
}
}
/**
* retract what&#039;s done in beforeDraw so that there&#039;s no side effect to
* other nodes.
*/
-(void)afterDraw {
if (clipToBounds_) {
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}
}
#pragma mark -
#pragma mark touch events
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
CGRect frame;

frame = CGRectMake(self.position.x, self.position.y, viewSize_.width, viewSize_.height);
//dispatch does not know about clipping. reject touches outside visible bounds.
for (UITouch *touch in [touches allObjects]) {
if (!CGRectContainsPoint(frame, [self convertToWorldSpace:[self convertTouchToNodeSpace:touch]])) {
touchPoint_ = ccp(-1.0f, -1.0f);
isDragging_ = NO;
return;
}
}

if ([touches count] == 1) { // scrolling
touchPoint_ = [self convertTouchToNodeSpace:[touches anyObject]];
} else { // 2 or more touches would mean something else?
//invalidate initial values
touchPoint_ = ccp(-1.0f, -1.0f);
}
touchMoved_ = NO;
isDragging_ = YES; //dragging started
scrollDistance_ = ccp(0.0f, 0.0f);
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
touchMoved_ = YES;
if ([touches count] == 1 &#38;&#38; !CGPointEqualToPoint(ccp(-1.0f,-1.0f), touchPoint_) &#38;&#38; isDragging_) { // scrolling
CGPoint moveDistance, newPoint, maxInset, minInset;
CGRect frame;
CGFloat newX, newY;

frame = CGRectMake(self.position.x, self.position.y, viewSize_.width, viewSize_.height);
newPoint = [self convertTouchToNodeSpace:[touches anyObject]];
moveDistance = ccpSub(newPoint, touchPoint_);
touchPoint_ = newPoint;

if (CGRectContainsPoint(frame, [self convertToWorldSpace:newPoint])) {
switch (direction_) {
case CCScrollViewDirectionVertical:
moveDistance = ccp(0.0f, moveDistance.y);
break;
case CCScrollViewDirectionHorizontal:
moveDistance = ccp(moveDistance.x, 0.0f);
break;
default:
break;
}
container_.position = ccpAdd(container_.position, moveDistance);

if (bounces_) {
maxInset = maxInset_;
minInset = minInset_;
} else {
maxInset = [self maxContainerOffset];
minInset = [self minContainerOffset];
}

//check to see if offset lies within the inset bounds
newX = MIN(container_.position.x, maxInset.x);
newX = MAX(newX, minInset.x);
newY = MIN(container_.position.y, maxInset.y);
newY = MAX(newY, minInset.y);

scrollDistance_ = ccpSub(moveDistance, ccp(newX - container_.position.x, newY - container_.position.y));
[self setContentOffset:ccp(newX, newY)];
}
}
}
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
isDragging_ = NO;
if ([touches count] == 1 &#38;&#38; !CGPointEqualToPoint(ccp(-1.0f,-1.0f), touchPoint_) &#38;&#38; touchMoved_) {
[self schedule:@selector(deaccelerateScrolling:)];
}
}
-(void)ccTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
[self ccTouchesEnded:touches withEvent:event];
}

@end</code></pre>
<p>Does anyone have an idea on how to make this swallow touches, but still scroll? Cheers!
</p></description>
		</item>
		<item>
			<title>nixarn on "Sending touches to UIView behind EAGLView?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22518#post-125003</link>
			<pubDate>Tue, 08 Nov 2011 09:52:59 +0000</pubDate>
			<dc:creator>nixarn</dc:creator>
			<guid isPermaLink="false">125003@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, so I'm trying to add ads to my game but allow the Cocos2d GL view to show on top of the ads (no, not trying to trick anyone, just trying to maximize screen usage). I got the ad to show as I wanted it to, but no touches go through to the adview. Anyone know what I'm doing wrong or not doing? Is this handled automagically by cocos2d or not?</p>
<p>Thanks!
</p></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>Duckwit on "[?] CCMenuItemSprite - &#039;setIsEnabled&#039; glitching touches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21743#post-120795</link>
			<pubDate>Wed, 12 Oct 2011 06:46:09 +0000</pubDate>
			<dc:creator>Duckwit</dc:creator>
			<guid isPermaLink="false">120795@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Only when I start changing 'isEnabled' variably does the 'touching' not work.<br />
e.g. Normally when you touch it the sprite switches to the specified 'selected' image, but once you setIsEnabled (Even if it is to YES) it will no longer switch images when touched.<br />
<pre><code>if (...) ... {
[button setIsEnabled:YES]; }
else [button setIsEnabled:NO];</code></pre></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>Duckwit on "[?] Why won&#039;t CCMenuItemSprite respond?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21679#post-120484</link>
			<pubDate>Mon, 10 Oct 2011 18:33:12 +0000</pubDate>
			<dc:creator>Duckwit</dc:creator>
			<guid isPermaLink="false">120484@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is how I am defining the button:<br />
<pre><code>CCMenuItemSprite* cubicleOneButton = [CCMenuItemSprite itemFromNormalSprite:[CCSprite spriteWithSpriteFrameName:@&#34;PlayButtonUp.png&#34;]
                                                               selectedSprite:[CCSprite spriteWithSpriteFrameName:@&#34;PlayButtonDown.png&#34;]
                                                                target:cubicleOneSpace selector:@selector(touched)];</code></pre>
<p>I am then sending the button pointer to a class to manipulate the position and opacity based on some other factors. So all it is doing is reading and modifying the position/opacity value.<br />
I add the button to my _gameLayer:<br />
<pre><code>[_gameLayer addChild:cubicleOneButton z:10000];</code></pre>
<p>Touches are enabled on everything (normally I just use self.isTouchedEnabled...):<br />
'<br />
self.isTouchEnabled = YES;<br />
		_gameLayer.isTouchEnabled = YES;<br />
		_hud.isTouchEnabled = YES;<br />
`<br />
The _hudLayer responds perfectly to touches, but that uses CCMenuItemImage instead of CCMenuItemSprite. </p>
<p>Does anyone know what I am missing?<br />
Any tips or pointers would be greatly appreciated. :)
</p></description>
		</item>
		<item>
			<title>gyazbek on "[solved] Touches not detected over ccsprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21234#post-118071</link>
			<pubDate>Mon, 26 Sep 2011 02:21:18 +0000</pubDate>
			<dc:creator>gyazbek</dc:creator>
			<guid isPermaLink="false">118071@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The problem I am having is that touches over a specific ccsprite is not being detected.  Since things weren't working, I created a gameLayer and tried on that with no avail. When I output data to the console, it detects all points just outside 200,200. The ccsprite is 50px by 50px (positioned at x=200 y=200). So it doesnt detect between 200x or y, to 250x,y.  I have gotten as close as 199 x. </p>
<p>The code I have is as follows:</p>
<p>HelloWorld.mm</p>
<pre><code>-(id) init
{
	if( (self=[super init])) {

		// add gamelayer
		gameLayer = [CCLayer node];
		gameLayer.isTouchEnabled = YES;
		[self addChild:gameLayer];

                //add clicker
                clickLaunch = [CCSprite spriteWithFile:@&#34;click.png&#34;];
		clickerPoint = ccp(200,200);

                [gameLayer addChild:clickLaunch];
	        [clickLaunch setPosition:clickerPoint];

        }
	return self;

}

- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{

	UITouch *touch = [touches anyObject];
	CGPoint location = [gameLayer convertTouchToNodeSpace: touch];

	if ([touches count] == 1) {

                        CGPoint locationA = [gameLayer convertTouchToNodeSpace: touch];			

                        // Get the camera&#39;s current values.
			float centerX, centerY, centerZ;

			[gameLayer.camera centerX:&#38;centerX centerY:&#38;centerY centerZ:&#38;centerZ];

                        // I move around my gameLayer, this was the way I could get accurate positions.
			locationA.x = (centerX + locationA.x);
			locationA.y = (centerY + locationA.y); 

			/*

			CGRect rect=CGRectMake((clickLaunch.position.x), (clickLaunch.position.y), 50,50);

			if (CGRectContainsPoint(rect, locationA)) {

                        NSLOG(@&#34;Clicked&#34;);	

                        }

            }

}</code></pre>
<p>HelloWorld.h declaration<br />
<pre><code>@interface HelloWorld : CCLayer //&#60;CCTargetedTouchDelegate&#62;
{

	CGPoint clickerPoint;
	CCSprite *clickLaunch;

	/* layers */
	CCLayer *gameLayer;

}</code></pre>
<p>I have a feeling I did a very stupid mistake. Any help would be appreciated :)</p>
<p>Thanks</p>
<p>-Gui
</p></description>
		</item>
		<item>
			<title>RomanRobot on "Not responding to touches (yes I did [self setIsTouchEnabled:YES] on a layer)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21232#post-118060</link>
			<pubDate>Mon, 26 Sep 2011 00:15:53 +0000</pubDate>
			<dc:creator>RomanRobot</dc:creator>
			<guid isPermaLink="false">118060@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a navigation controller. It pushes a special View Controller for Cocos2d. I do all the Cocos2d stuff in the special view controller's implementation like this:<br />
<pre><code>- (void) removeStartupFlicker {
	//
	// THIS CODE REMOVES THE STARTUP FLICKER
	//
	// Uncomment the following code if you Application only supports landscape mode
	//
#<a href='http://www.cocos2d-iphone.org/forum/tags/if'>if</a> GAME_AUTOROTATION == kGameAutorotationUIViewController

    //	CC_ENABLE_DEFAULT_GL_STATES();
    //	CCDirector *director = [CCDirector sharedDirector];
    //	CGSize size = [director winSize];
    //	CCSprite *sprite = [CCSprite spriteWithFile:@&#34;Default.png&#34;];
    //	sprite.position = ccp(size.width/2, size.height/2);
    //	sprite.rotation = -90;
    //	[sprite visit];
    //	[[director openGLView] swapBuffers];
    //	CC_ENABLE_DEFAULT_GL_STATES();

#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
}

-(id)init {
    if ((self = [super init])) {
        // Init the window

        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        // Try to use CADisplayLink director
        // if it fails (SDK &#60; 3.1) use the default director
        if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
            [CCDirector setDirectorType:kCCDirectorTypeDefault];

        CCDirector *director = [CCDirector sharedDirector];

        // Init the View Controller
        self.wantsFullScreenLayout = YES;

        //
        // Create the EAGLView manually
        //  1. Create a RGB565 format. Alternative: RGBA8
        //	2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
        //
        //
        EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                       pixelFormat:kEAGLColorFormatRGB565	// kEAGLColorFormatRGBA8
                                       depthFormat:0						// GL_DEPTH_COMPONENT16_OES
                            ];

        [glView setMultipleTouchEnabled:YES];

        // attach the openglView to the director
        [director setOpenGLView:glView];

        // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
        if( ! [director enableRetinaDisplay:YES] )
            CCLOG(@&#34;Retina Display Not supported&#34;);

        //
        // VERY IMPORTANT:
        // If the rotation is going to be controlled by a UIViewController
        // then the device orientation should be &#34;Portrait&#34;.
        //
        // IMPORTANT:
        // By default, this template only supports Landscape orientations.
        // Edit the RootViewController.m file to edit the supported orientations.
        //
#<a href='http://www.cocos2d-iphone.org/forum/tags/if'>if</a> GAME_AUTOROTATION == kGameAutorotationUIViewController
        [director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
        [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

        [director setAnimationInterval:1.0/60];
        [director setDisplayFPS:YES];

        // make the OpenGLView a child of the view controller
        [self setView:glView];

        [window setUserInteractionEnabled:YES];
        [self.view setUserInteractionEnabled:YES];

        // make the View Controller a child of the main window
        [window addSubview: self.view];

        [window makeKeyAndVisible];

        // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
        // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
        // You can change anytime.
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

        // Removes the startup flicker
        [self removeStartupFlicker];

        [director runWithScene:[GameScene node]];
    }
    return self;
}</code></pre>
<p>^ That sets up the director and runs the GameScene which has all the layers in it, including the HUD layer that has some buttons that makes the Player move and jump.</p>
<p>The scenes and everything are fine. I'm almost completely sure it's something I did wrong or didn't do at all here.</p>
<p>Thanks in advance for the help. ^.^
</p></description>
		</item>
		<item>
			<title>Aorata on "Two independent touches"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18452#post-103502</link>
			<pubDate>Fri, 08 Jul 2011 00:42:29 +0000</pubDate>
			<dc:creator>Aorata</dc:creator>
			<guid isPermaLink="false">103502@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I need to make TWO independent touches. I need these touches to give me different locations AT THE SAME TIME.</p>
<p>I know how to get one touch and its location, but when I try to get the second touch and location at the same time, all hell breaks loose, they get confused!</p>
<p>Help!
</p></description>
		</item>
		<item>
			<title>waelchli on "finding touch location in scene"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18703#post-104948</link>
			<pubDate>Thu, 14 Jul 2011 22:44:40 +0000</pubDate>
			<dc:creator>waelchli</dc:creator>
			<guid isPermaLink="false">104948@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is a pretty simple problem but I've been going at it for a while now and still can't figure it out. I was hoping someone more experienced than I could help me figure this out. I'm trying to find the location of my touch in relation to the scene instead of the relation to the screen. To further explain the touch position I get is always 250 near the center of the screen even if it's on a different point of the scene because it's on the x y plane of the screen and not the scene as a whole (hopefully that cleared things up) anyway I've been using this code that i got from many tutorials for converting the touch points to things i could use<br />
<pre><code>UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView:[touch view]];
	location = [[CCDirector sharedDirector] convertToGL:location];</code></pre>
<p>I figure I need to change something in the locationinview method so that instead of returning values based on the screen it will return values based on the scene. I looked it up in the documentation and was led to believe that self would be what you would use to accomplish that, but I can't seem to type it in a way that it accepts. If anyone could help me out that would be most appreciated :)
</p></description>
		</item>
		<item>
			<title>SnickersChamber on "Problem Handling Touches Over The 5th"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18788#post-105409</link>
			<pubDate>Sun, 17 Jul 2011 07:13:34 +0000</pubDate>
			<dc:creator>SnickersChamber</dc:creator>
			<guid isPermaLink="false">105409@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I came across this problem when I was just play testing my game prototype. In one section of the game, I basically have two buttons that need to be pressed simultaneously in order to open a door. </p>
<p>Worked perfectly until I decided to do something not so normal. I decided to place five touches onscreen (none touching the buttons mentioned) and see if the 6th and 7th touch would register. To my surprise they didn't.</p>
<p>What's worse is that, upon placing my 6th and 7th touch on the buttons, releasing all seven touches, then pressing either one of the two buttons, the door opens.</p>
<p>Curious about the problem, I did a quick test with published games, namely Flight Control and Cut the Rope. Surprise surprise, neither responded to anything over 5 touches.</p>
<p>I'd happily provide the code for this is necessarily, but I think it isn't. The simple question really is, can cocos2D (or iOS for that matter) handle touches over the 5th?</p>
<p>Am using Targeted Touch in case anybody was wondering.</p>
<p>Thanks in advanced for any insight into this issue. Will keep looking into this and post my findings if any.
</p></description>
		</item>
		<item>
			<title>madclouds on "To Touch or Multitouch... That is the question..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8822#post-51135</link>
			<pubDate>Thu, 19 Aug 2010 02:25:06 +0000</pubDate>
			<dc:creator>madclouds</dc:creator>
			<guid isPermaLink="false">51135@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p><strong>Hi Community!  You guys are awesome!</strong></p>
<p>So I have an interesting challenge that I'd like to discuss with the community and hopefully learn something in the process.  My game consists of 5 buttons.  Here's an image to identify the layout:</p>
<p><img src="http://madclouds.com/wordpress/wp-content/uploads/2010/08/buttons.png" alt="Buttons" /></p>
<p>Every time a button is touched - a bullet is shot from the button.position.  </p>
<p><strong>The Challenge:</strong><br />
When two buttons next to each other are touched at the same time, a bullet is fried from the center point between the two buttons.</p>
<p>For example - if button 3 is touched a bullet is fired from the center of the screen, but if button 3 and 4 is touched at the same time a bullet is fried from the location between the two buttons!</p>
<p>Crazy challenge hu?</p>
<p><strong>Some Thoughts:</strong><br />
I was considering creating a button manager layer that would track all touches and calculate their location in relation to the buttons.  This may be my best option and I'll proceed with this unless someone can convince me otherwise :)</p>
<p>Another thought was to have a boolean in each button class that when ccTouchesBegan set it to YES and when ccTouchesEnded set it to NO - then in some scheduler compare the booleans of each button to determine the starting location of the bullet.</p>
<p><strong>Potential Problem:</strong><br />
I'm worried about the timing associated with determining if one button was pressed, or if two (or more) are pressed.<br />
I know there's more... But I'm drawing a blank right now.</p>
<p>I'm very excited to hear from the community!  Thanks for any feedback or suggestions!</p>
<p>Erik
</p></description>
		</item>
		<item>
			<title>Ricardo1980 on "How can I create a sprite that swallows touches?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18307#post-102701</link>
			<pubDate>Mon, 04 Jul 2011 10:32:10 +0000</pubDate>
			<dc:creator>Ricardo1980</dc:creator>
			<guid isPermaLink="false">102701@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello!</p>
<p>Does CCSprite have anything to block touches?</p>
<p>Now I only have one idea, create a CCSprite subclass and use CCTargetedTouchDelegate to block all touches, but not sure if this is the correct way.</p>
<p>Any ideas or suggestions?<br />
Thanks a lot.
</p></description>
		</item>
		<item>
			<title>LaneStevens on "Buttons and touches question (n00b)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18250#post-102311</link>
			<pubDate>Sat, 02 Jul 2011 04:08:33 +0000</pubDate>
			<dc:creator>LaneStevens</dc:creator>
			<guid isPermaLink="false">102311@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello i am pretty noobish to cocos2d so maybe you can help...</p>
<p>I have a button and it does a simple actions (to learn with) but insted of doing it on touchUP (where the user lifts the finger to make the action occur, i want it to us touchdown (when the user touches on the screen without having to lift up their finger. Then i want it to do somthing else when the user lifts up.</p>
<p>But...there are 4 buttons so i have to be able to do it on all four buttons</p>
<p>example</p>
<p>buttonA touchDown {</p>
<p>NSLog("The user has touched down!");</p>
<p>}</p>
<p>buttonA touchUp {</p>
<p>NSLog ("the user has lifted their finger off of the screen!");</p>
<p>}</p>
<p>buttonB touchDown {</p>
<p>NSLog("The user has touched down on buttonB!");</p>
<p>}</p>
<p>buttonB touchUp {</p>
<p>NSLog ("the user has lifted their finger off of the screeno on buttonB!");</p>
<p>}</p>
<p>i know this isnt the correct programming of it but i think it gets the point across of what im trying to do. ive searched it on google and had no luck finding it, so i thought i would ask the pros!</p>
<p>Thanks,</p>
<p>Lane
</p></description>
		</item>
		<item>
			<title>Zee on "Touch Held"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17495#post-98318</link>
			<pubDate>Fri, 10 Jun 2011 05:21:37 +0000</pubDate>
			<dc:creator>Zee</dc:creator>
			<guid isPermaLink="false">98318@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey, I've been working on a project and seem to have hit a speedbump. I have been trying to find a way to calculate the time that a touch has been held(from time began to time release). I've been through timers and nothing seems to be working. I keep getting errors or no errors at all but the app crashes as soon as a touch occurs.<br />
Any help would be appreciated
</p></description>
		</item>
		<item>
			<title>bipolarpants on "Moving Two Sprites in Two Different Directions At the Same Time?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/16144#post-91040</link>
			<pubDate>Sun, 01 May 2011 21:48:21 +0000</pubDate>
			<dc:creator>bipolarpants</dc:creator>
			<guid isPermaLink="false">91040@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>So this is probably a pretty basic question, but how do I move two sprites at the same time? I was using touchesbegan to move them originally and it worked just fine, but the I realized they can't be moved at the same time, only one at a time. Any suggestions? thanks!
</p></description>
		</item>
		<item>
			<title>heikPhone on "New touch event when finger is close to border"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14524#post-82337</link>
			<pubDate>Tue, 15 Mar 2011 08:31:42 +0000</pubDate>
			<dc:creator>heikPhone</dc:creator>
			<guid isPermaLink="false">82337@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there,<br />
does anyone have the same problem:</p>
<p>I have a landscape app and when i touch and move finger close to the lower border then i get no touch events for the last 10 pixels:</p>
<p>You can easily try:</p>
<p>- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event<br />
{<br />
        UITouch* touch = [touches anyObject];</p>
<p>        CGPoint location = [touch locationInView: [touch view]];</p>
<p>        location = [[CCDirector sharedDirector] convertToGL: location];</p>
<p>        CCLOG(@"x: %.2f y: %.2f", location.x, location.y);<br />
}</p>
<p>Thx for any advice,<br />
heikPhone
</p></description>
		</item>
		<item>
			<title>nasty_jpp on "Moving multiple sprites with multiple touches at different times"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14250#post-80482</link>
			<pubDate>Mon, 07 Mar 2011 03:24:26 +0000</pubDate>
			<dc:creator>nasty_jpp</dc:creator>
			<guid isPermaLink="false">80482@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey!</p>
<p>I have a scene with two sprites. One on the left and one on the right. I wanna be able to move them independently at different times. But so far no good. </p>
<p>Here's the code I have for now (taken from the Paddle example) in the class that each sprite inherits from:</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 (state != kSpriteStateUngrabbed) return NO;
	if ( ![self containsTouchLocation:touch] ) return NO;

	state = kSpriteStateGrabbed;

	//some code...

	return YES;
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{

	NSAssert(state == kSpriteStateGrabbed, @&#34;Paddle - Unexpected state!&#34;);	

	//some code...
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
	NSAssert(state == kSpriteStateGrabbed, @&#34;Paddle - Unexpected state!&#34;);
	state = kSpriteStateUngrabbed;

	//some code...
}</code></pre>
<p>Tried a couple of things but it seems like I cannot get ccTouchBegan fired a second time i.e. ccTouchBegan gets fired when the player touches the screen on the left with one finger but it doesn't is the player touches the screen on the right (while his finger is still on the left side...). How the hell can I do that?</p>
<p>Any help would be well appreciated!</p>
<p>Thx!
</p></description>
		</item>
		<item>
			<title>cmsleal on "Touch(es) Moved precision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/14335#post-81148</link>
			<pubDate>Wed, 09 Mar 2011 21:32:18 +0000</pubDate>
			<dc:creator>cmsleal</dc:creator>
			<guid isPermaLink="false">81148@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>There is some way to decrease the precision from touch(es) move(d) ? I mean, I guess this method is called each time the finger moved over the screen... even though this movement was subtle. So, if we have a lot of code on this method, the performance could be compromised... I was thinking if there is some way to say "Don't be called if the move is lower than x points..." or something like that. Of course I could make this check by myself... but this method will be called any way...<br />
I don't know if I made myself clear 'cause english isn't my native language...  Hope someone get it.. &#62;.&#60;</p>
<p>Bye!
</p></description>
		</item>

	</channel>
</rss>

