<?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: detection - Recent Topics</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/detection</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:15: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/detection/topics" rel="self" type="application/rss+xml" />

		<item>
			<title>arbitur on "collision detection doesnt work as expected"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28723#post-141571</link>
			<pubDate>Fri, 27 Jan 2012 20:04:20 +0000</pubDate>
			<dc:creator>arbitur</dc:creator>
			<guid isPermaLink="false">141571@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>im making a little more advanced snake game, and im making the worms body by adding CCSprites at the heads position eatch 0,02 sec.</p>
<p>that works fine but when i try to add collision detection between the first worms body and the second worms body it wont work.</p>
<p>it only works when the last "spawned" body parts are colliding.</p>
<p>im using CGRectIntersectsRect([body1 boundingBox], [body2 boundingBox])
</p></description>
		</item>
		<item>
			<title>Tenorm on "Implementing a high-resolution collision detection"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20808#post-115668</link>
			<pubDate>Tue, 13 Sep 2011 08:56:50 +0000</pubDate>
			<dc:creator>Tenorm</dc:creator>
			<guid isPermaLink="false">115668@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>I tried to implement a high-resolution collision detection and found this two very useful commands:<br />
<pre><code>CC3PlaneFromPoints(&#60;#<a href='http://www.cocos2d-iphone.org/forum/tags/cc3vector'>CC3Vector</a> p1#&#62;, &#60;#<a href='http://www.cocos2d-iphone.org/forum/tags/cc3vector'>CC3Vector</a> p2#&#62;, &#60;#<a href='http://www.cocos2d-iphone.org/forum/tags/cc3vector'>CC3Vector</a> p3#&#62;);
CC3RayIntersectionWithPlane(&#60;#<a href='http://www.cocos2d-iphone.org/forum/tags/cc3ray'>CC3Ray</a> ray#&#62;, &#60;#CC3Plane plane#&#62;);</code></pre>
<p>So I want to check for collision by computing the distance to all of the faces of an object. But I don't know how to access them... I found this:<br />
<code>CC3VertexLocations* vertices = ((CC3VertexArrayMeshModel*)node.meshModel).vertexLocations;</code><br />
but I don't know which three vertices of this pool make a face. So my basic question is how to make a loop that checks all the FACES of an object.</p>
<p>Thank you!</p>
<p>By the way: How to use CC3Ray?
</p></description>
		</item>
		<item>
			<title>pravin on "How to detect collision of two sprite object ?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/414#post-2364</link>
			<pubDate>Wed, 01 Jul 2009 12:59:53 +0000</pubDate>
			<dc:creator>pravin</dc:creator>
			<guid isPermaLink="false">2364@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>Could you help me with the following task?<br />
I have problem with collision detection of two sprite object.
</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>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>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>goodeats2009 on "A* Star path finder algorithm speed performance"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21245#post-118116</link>
			<pubDate>Mon, 26 Sep 2011 08:15:30 +0000</pubDate>
			<dc:creator>goodeats2009</dc:creator>
			<guid isPermaLink="false">118116@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi, i just want to get your feedback with regards to A* path finder algorithm as to speed in performing the calculations.  i used the A* algorithm by sqlboy in this link</p>
<p><a href="http://www.cocos2d-iphone.org/forum/topic/19463" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/19463</a></p>
<p>i have a 64x64 tile size in a 15x10 tilemap. After selecting my target node which is only 3 tiles in any direction, it takes about 1-1.5 seconds before the sprite starts moving to the node. i also added a method that highlights a 3 tile node radius around the sprite. the method gets called when i click on the sprite so it shows the options on where the sprite can go. it also takes about 1-1.5 seconds after clicking the sprite for the highlighted nodes to show up. the lag is evident when using it on the phone. </p>
<p>the fps as shown in the phone is still at 60fps, but I'm thinking its the calculating part that takes a bit of time and not the rendering of the sprite.<br />
anybody else noticed this performance? any tips? thanks
</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>EasyDev on "Disable a Scene/CCSprite"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9193#post-53100</link>
			<pubDate>Tue, 31 Aug 2010 20:37:44 +0000</pubDate>
			<dc:creator>EasyDev</dc:creator>
			<guid isPermaLink="false">53100@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey developers ! </p>
<p>I am searching for how to un disable a scene ? I mean I have a GamePlay class in which the game is running. Then when you hit a button it goes to the menu with this code : </p>
<pre><code>[[CCDirector sharedDirector] replaceScene:[CCSplitRowsTransition transitionWithDuration:1 scene:[HelloWorld node]]];</code></pre>
<p>But the problem is that while I am on the menu the GamePlay scene continue running itself. Is it normal ? How to prevent that ?</p>
<p>And I have another problem : I have a character in my GamePlay view who can interact with objects. For example when the character interacts with the bag, the bag fadeout and scaleby 1.5. But there is also ennemies who can collide with objects and when an ennemy collide with an object, it does exactly the same thing for the object as when the character collides with this object. Sometimes, the character touches the object and before that the object finished its animation, the ennemy collides with this same object who is a CCSprite. So what happens is that my CCSprite run 2 times the same action. I want to prevent that by disabling to the object the ability to collide with the character or with the ennemies when the ennemy or the character touches for the first time the object. I hope you understood ? Remember that objects which can interract with the ennemies or the character are CCSprites.</p>
<p>Thanks in advance for your help,<br />
Best regards
</p></description>
		</item>
		<item>
			<title>albrufsky on "SpaceManager Collision issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20689#post-115049</link>
			<pubDate>Fri, 09 Sep 2011 01:49:40 +0000</pubDate>
			<dc:creator>albrufsky</dc:creator>
			<guid isPermaLink="false">115049@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi i'm a n00b to spacemanager and somewhat knowledgeable to cocos2d and am looking at a EXC bad access on  collision type definition line. here is my code :</p>
<pre><code>player.shape-&#62;collision_type = kPlayerCollisionType;
        jumping_barier.shape-&#62;collision_type = kJumping_BarrierCollisionType;

        [smgr addCollisionCallbackBetweenType:kPlayerCollisionType otherType:kJumping_BarrierCollisionType target:self selector:@selector(maincollision:arbiter:space:) moments:COLLISION_BEGIN, nil];</code></pre>
<p>and my two objects are declared like this:</p>
<p>player:</p>
<pre><code>spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@&#34;guy.png&#34;];

        [self addChild:spriteSheet z:3];

         pshape = [smgr addRectAt:cpv( 30, s.height-(s.height-57)+40.5) mass:0 width:84/2 height:174/2 rotation:0];

        player = [cpCCSprite spriteWithShape:pshape spriteFrameName:@&#34;jump0001.png&#34;];

        [player setPosition:ccp( 30, s.height-(s.height-57)+40.5 )];
        [spriteSheet addChild:player z:3];</code></pre>
<p>and for jumping barrier</p>
<pre><code>float s = [jumping_barier textureRect].size.height/2; 

        jshape = [smgr addRectAt:cpv( 92+480, s+67+2 )  mass:0 width:75 height:9 rotation:0];

    jumping_barier = [cpCCSprite spriteWithShape:jshape file:@&#34;barrier.png&#34;];

    [jumping_barier setPosition:ccp( 92+480, s+67+2 )];

    [self addChild:jumping_barier z:3];</code></pre>
<p>and they're * declarations are in the top of the file</p>
<p>also, the k definitions are in the gameconfig.h file
</p></description>
		</item>
		<item>
			<title>mrtechgu2y3 on "Collision Detection problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20569#post-114290</link>
			<pubDate>Sun, 04 Sep 2011 18:02:36 +0000</pubDate>
			<dc:creator>mrtechgu2y3</dc:creator>
			<guid isPermaLink="false">114290@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have the following code to detect my collision</p>
<pre><code>-(void)col:(ccTime)dt{

    CGRect _bearRect = CGRectMake(_bear.position.x - (_bear.contentSize.width/2),
                                       _bear.position.y - (_bear.contentSize.height/2),
                                       _bear.contentSize.width,
                                       _bear.contentSize.height);

    NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
    for (CCSprite *target in _targets) {
        CGRect targetRect = CGRectMake(target.position.x - (target.contentSize.width/2),
                                       target.position.y - (target.contentSize.height/2),
                                       target.contentSize.width,
                                       target.contentSize.height);

        if (CGRectIntersectsRect(_bearRect, targetRect)) {

            progressstimer.percentage = currentHealth -= 25;

            [self removeChild:target cleanup:YES];

            NSLog(@&#34;Detected collision&#34;);
}
        break;

    }

}</code></pre>
<p>and here is my update method</p>
<p><code>[self schedule:@selector(col:)];</code></p>
<p>But when I run the gameplay and the monsters hit the player, the players health bar loses 100 percent of his life instead of losing on 25 percent. What am I doing wrong? I already tried changing my update method as so</p>
<p><code>[self schedule:@selector(col:) interval:0.4];</code></p>
<p>But it messed up the game but detecting some collisions and not detecting some.
</p></description>
		</item>
		<item>
			<title>albrufsky on "CGRectIntersectsRect not working"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/20561#post-114266</link>
			<pubDate>Sun, 04 Sep 2011 13:32:44 +0000</pubDate>
			<dc:creator>albrufsky</dc:creator>
			<guid isPermaLink="false">114266@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hi i'm sort of a noob and am trying this code out in a game</p>
<pre><code>-(BOOL) coldetect: (CCSprite *)a: (CCSprite *)b {

    float a_bottom = [a textureRect].size.height;
    float a_side = [a textureRect].size.width;

    float b_top = [b textureRect].size.height;
    float b_side = [b textureRect].size.width;

    CGRect ar = CGRectMake([a position].x, [a position].y, a_bottom, a_side);
    CGRect br = CGRectMake([b position].x, [b position].y, b_top, b_side);

    if (CGRectIntersectsRect(ar, br)) {

        is = YES; 

    }  

    return is;

}</code></pre>
<p>and I'm calling it in a callback method with two sprites.</p>
<p>My issue is that it won't detect the collision.</p>
<p>Forgive me if i posted this on the wrong sub forum.
</p></description>
		</item>
		<item>
			<title>Leon on "Using ObjC Objects in Box2D Contact Listener"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9213#post-53201</link>
			<pubDate>Wed, 01 Sep 2010 12:08:53 +0000</pubDate>
			<dc:creator>Leon</dc:creator>
			<guid isPermaLink="false">53201@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>I implemented a Contact listener with the following code:<br />
(box2D Header file is already included in prefixHeader)</p>
<p>CollisionContactListener.h<br />
<pre><code>class MyContactListener : public b2ContactListener {

}</code></pre>
<p>CollisionContactListener.mm<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CollisionContactListener.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;Vehicle.h&#34;

const int32 k_maxContactPoints = 2048;
struct ContactPoint
{
	b2Fixture* fixtureA;
	b2Fixture* fixtureB;
	b2Vec2 normal;
	b2Vec2 position;
	b2PointState state;
};

int32 m_pointCount;
ContactPoint m_points[k_maxContactPoints];

void BeginContact(b2Contact* contact)
{
	b2Fixture* fixtureA = contact-&#62;GetFixtureA();
	b2Fixture* fixtureB = contact-&#62;GetFixtureB();

	b2Body *bodyA = fixtureA-&#62;GetBody();
	b2Body *bodyB = fixtureB-&#62;GetBody();

	id userDataA = (id)bodyA-&#62;GetUserData();
	id userDataB = (id)bodyB-&#62;GetUserData();

	if([userDataA isKindOfClass:[Vehicle class] &#38;&#38; userDataB isKindOfClass:[Vehicle class]){
		Vehicle *vehicleA = (Vehicle*)userDataA;
		Vehicle *vehicleB = (Vehicle*)userDataB;
		if (vehicleA.currentLane != IZLaneOutOfScreen &#38;&#38; vehicleB != IZLaneOutOfScreen) {
			NSLog(@&#34;Collision on Screen!!!&#34;);
		}
	}
}

void EndContact(b2Contact* contact)
{
	NSLog(@&#34;end contact&#34;);
}

void PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
	const b2Manifold* manifold = contact-&#62;GetManifold();
}

void PostSolve(b2Contact* contact)
{
	const b2ContactImpulse* impulse;
}</code></pre>
<p>But I get errors , the compiler says that Vehicle was not declared and i get some errors like the following:</p>
<blockquote><p>Vehicle.h:21: error: misplaced '@property' Objective-C++ construct</p></blockquote>
<p>I tried to rename Vehicle.m to Vehicle.mm but the same errors occur.<br />
What could i do?
</p></description>
		</item>
		<item>
			<title>nomad_games on "[code] a basic manager for mic input detection"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18144#post-101793</link>
			<pubDate>Wed, 29 Jun 2011 21:08:11 +0000</pubDate>
			<dc:creator>nomad_games</dc:creator>
			<guid isPermaLink="false">101793@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have been researching a way to detect when a user blows into the microphone.  I have come across a few tutorials, but most are very old and do not fit my needs exactly.  I have rewritten some of the code and combined different approaches from these tutorials to make a basic "blow detection" manager.</p>
<p>As it is now, the manager will listen for mic input, detect when the noise crosses a certain threshold, and return a true/false for if the user is blowing into the mic.  There is also an experimental method for detecting how strongly the user blows into the mic, but it is pretty buggy and needs some work.</p>
<p>I have found that many other devs are asking about this method of input, so I am sharing what I have and will continue to improve upon it.</p>
<p>source code available at : <a href="https://github.com/NomadGames/BlowDetectionManager" rel="nofollow">https://github.com/NomadGames/BlowDetectionManager</a>
</p></description>
		</item>
		<item>
			<title>BrokenHabits on "Adding joints when collision detected"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18784#post-105385</link>
			<pubDate>Sun, 17 Jul 2011 02:53:39 +0000</pubDate>
			<dc:creator>BrokenHabits</dc:creator>
			<guid isPermaLink="false">105385@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>I'm hoping to find an answer to a problem I'm having.  I'm trying to add a weld joint between ObjectA and ObjectB when they collide.  Here is my contact listener:</p>
<p>void ContactListener::BeginContact(b2Contact* contact)<br />
{<br />
    b2Fixture* fixtureA = contact-&#62;GetFixtureA();<br />
    b2Fixture* fixtureB = contact-&#62;GetFixtureB();<br />
    b2Body* bodyA = fixtureA-&#62;GetBody();<br />
    b2Body* bodyB = fixtureB-&#62;GetBody();<br />
    BodyNode* bodyNodeA = (BodyNode*) bodyA-&#62;GetUserData();<br />
    BodyNode* bodyNodeB = (BodyNode*) bodyB-&#62;GetUserData();</p>
<p>    if (fixtureA-&#62;GetUserData() == @"ArrowHead" &#124;&#124; fixtureB-&#62;GetUserData() == @"ArrowHead")<br />
    {<br />
        if ([bodyNodeB isKindOfClass:[Acorn class]] &#124;&#124; [bodyNodeA isKindOfClass:[Acorn class]])<br />
        {</p>
<p>            b2WeldJointDef weldDef;<br />
            weldDef.Initialize(bodyA, bodyB, bodyA-&#62;GetWorldCenter());<br />
            bodyB-&#62;GetWorld()-&#62;CreateJoint(&#38;weldDef);</p>
<p>         }</p>
<p>The issue is that when this code is executed, I get the "b2Assert(IsLocked() == false);" error.  Has anyone had this issue before.  </p>
<p>I'm trying to get to dynamic bodies to "stick" together when they collide.  Thanks.
</p></description>
		</item>
		<item>
			<title>Dynex on "Optimal Collision Detection"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18329#post-102839</link>
			<pubDate>Mon, 04 Jul 2011 22:13:54 +0000</pubDate>
			<dc:creator>Dynex</dc:creator>
			<guid isPermaLink="false">102839@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey guys, I need some more advice. </p>
<p>My game is going to consist of many sprites (in the higher levels). These sprites include many different targets and many projectiles. </p>
<p>Would the best method of collision detection be to use CGRectIntersectsRect? Or should I dive into Box2d?<br />
I have CGRectIntersectsRect working right now for regular non-animated sprites, but I'm having trouble with animated ones (which they all will be in the end) </p>
<p>Have any of you had to deal with collision detection with many sprites (30-40)?
</p></description>
		</item>
		<item>
			<title>MrMojo on "I&#039;ve searched - but how to check for collision with rotated CGRect?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7150#post-41971</link>
			<pubDate>Thu, 17 Jun 2010 02:27:09 +0000</pubDate>
			<dc:creator>MrMojo</dc:creator>
			<guid isPermaLink="false">41971@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi there - I've searched the forums, and found the a few posts talking about how to test if a rotated sprite collides with a cgrect, but have tried the solutions posted and got no results ;-(</p>
<p>e.g.<br />
<a href="http://www.cocos2d-iphone.org/forum/topic/1693#post-10649" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/1693#post-10649</a></p>
<p>What I want to do is test if a ROTATED sprite collides with a touched location, but it doesn't seem to work - it still sees the sprite as not rotated when I do my collision test. I've added the following to my sprite class as suggested by most of the approaches i saw:</p>
<pre><code>-(CGRect) realContentRect
{
  CGRect rect = CGRectMake(0, 0, contentSize_.width, contentSize_.height);
  return CGRectApplyAffineTransform(rect, [self nodeToParentTransform]);
}

-(BOOL) intersectsRect:(CGRect) targetRect
{
  return CGRectIntersectsRect([self realContentRect], targetRect);
}

-(BOOL) intersectsPt:(CGPoint) targetPt
{
  CGRect targetRect = CGRectMake(targetPt.x, targetPt.y, 1, 1);
  return [self intersectsRect:targetRect];
}</code></pre>
<p>and my touchesEnded event tests for collision with my rotated player like so:</p>
<pre><code>-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
	UITouch *touch = [touches anyObject];
	CGPoint location = [touch locationInView:[touch view]];
	location = [[CCDirector sharedDirector] convertToGL:location];

	if ([player intersectsPoint:location])
	{
		NSLog(@&#34;clicked on rotated player&#34;);
	}
}</code></pre>
<p>any ideas why this doesnt work? it works as if the player sprite isn't rotated. thanks so much for any pointers!
</p></description>
		</item>
		<item>
			<title>dgtheman on "Scaling or moving the camera?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17777#post-99739</link>
			<pubDate>Sat, 18 Jun 2011 16:47:35 +0000</pubDate>
			<dc:creator>dgtheman</dc:creator>
			<guid isPermaLink="false">99739@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is it better to scale or zoom the camera? Some people say to scale the layer while others say to move the camera. I don't know which one to pick. Also I want to have collision detection later on and will probably do it with box2d. I know this is affected when scaling the layer. If zooming and panning the camera is the beat way can someone tell me how one achieves this.<br />
Thanks
</p></description>
		</item>
		<item>
			<title>parsa28 on "Using Box2d just for collision detection(no physics)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2692#post-16714</link>
			<pubDate>Wed, 28 Oct 2009 07:49:00 +0000</pubDate>
			<dc:creator>parsa28</dc:creator>
			<guid isPermaLink="false">16714@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello there, how can I use Box2d minimally and just for collision detection ? Do I still need to define a ground box,etc. ? Thanks in advance.
</p></description>
		</item>
		<item>
			<title>PinkSmartie on "Simply Collision Detection - Quick Question"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/15192#post-86221</link>
			<pubDate>Sat, 02 Apr 2011 19:27:14 +0000</pubDate>
			<dc:creator>PinkSmartie</dc:creator>
			<guid isPermaLink="false">86221@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Just a quick question probably a quick fix i just dunno...</p>
<p>I had collision detection working in my game when using CCSprite spriteWithFile etc</p>
<p>The collision detection method looks like so.. pretty standard i think...</p>
<pre><code>-(void)collisionCheck
{

	NSMutableArray *enemyToRemove = [[NSMutableArray alloc] init];

	CGRect playerRect = CGRectMake(
								   player.position.x - (player.contentSize.width/2),
								   player.position.y - (player.contentSize.height/2),
								   player.contentSize.width,
								   player.contentSize.height);

	for (CCSprite *enemy in _enemy)
	{
		CGRect EnemyRect = CGRectMake(
									  enemy.position.x - (enemy.contentSize.width/2),
									  enemy.position.y - (enemy.contentSize.height/2),
									  enemy.contentSize.width,
									  enemy.contentSize.height);

		//particleExplosion.position = enemy.position;

		if (CGRectIntersectsRect(EnemyRect, playerRect))
		{
			[enemyToRemove addObject:enemy];

		}
	}

	for (CCSprite *enemy in enemyToRemove)
	{
		[_enemy removeObject:enemy];
		[self removeChild:enemy cleanup:YES];
	}

	[enemyToRemove release];

}</code></pre>
<p>I switch added in animation using the atlas textures, works grand but my collision has gone is there something that needs to be changed.. am rather new to this so could easily be something simple..</p>
<p>Thanks in advance!
</p></description>
		</item>
		<item>
			<title>lap.felix on "3 fingers detection."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/13599#post-76457</link>
			<pubDate>Mon, 14 Feb 2011 21:59:22 +0000</pubDate>
			<dc:creator>lap.felix</dc:creator>
			<guid isPermaLink="false">76457@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>How can I make my pause menu appear when there is a 3-finger click ?
</p></description>
		</item>
		<item>
			<title>leftright on "Line Drawing Game"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/1656#post-10373</link>
			<pubDate>Wed, 02 Sep 2009 04:35:53 +0000</pubDate>
			<dc:creator>leftright</dc:creator>
			<guid isPermaLink="false">10373@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Everyone</p>
<p>We're planning to start work on a Flight Control/ Harbor Master style line drawing game using cocos2d. </p>
<p>Are there any code samples/resource that you know of to get started with?</p>
<p>Thanks!
</p></description>
		</item>
		<item>
			<title>EasyDev on "How do you detect if an action is already running ?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9211#post-53197</link>
			<pubDate>Wed, 01 Sep 2010 11:24:20 +0000</pubDate>
			<dc:creator>EasyDev</dc:creator>
			<guid isPermaLink="false">53197@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi… </p>
<p>All my question is in the title. I would want how to detect running actions on a CCSprite to do some conditions with that stuff. Is it possible ? I tried this : </p>
<p><code>if (CGRectIntersectsRect([perso boundingBox], [chaussure boundingBox]) &#38;&#38; (![chaussure isRunning])) {}</code></p>
<p>But I wanted to know if it was possible to detect if the CCSprite (chaussure) was running a specific action. </p>
<p>Thanks in advance,<br />
Best regards
</p></description>
		</item>
		<item>
			<title>ldaume on "Collision detection performance problems with tiledmap"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7173#post-42062</link>
			<pubDate>Thu, 17 Jun 2010 15:48:33 +0000</pubDate>
			<dc:creator>ldaume</dc:creator>
			<guid isPermaLink="false">42062@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>I need an exact collision detection and I tried something thats too heavy for the touch 2g :P.</p>
<p>I draw objects as bounding boxes around the obstacles with Tiled and as name I use "Obstacle".</p>
<p>So in my implemetation I make an array of CGRect's wich I get from the tmx.<br />
<pre><code>obstacles = [[NSMutableArray alloc] init];
for (NSDictionary *dict in [objects objects]) {
  if ([[dict valueForKey:@&#34;name&#34;] isEqualToString:@&#34;Obstacle&#34;]) {
    CGRect rect = CGRectMake([[dict valueForKey:@&#34;x&#34;] intValue],
                                                     [[dict valueForKey:@&#34;y&#34;] intValue],
                                                     [[dict valueForKey:@&#34;width&#34;] intValue],
                                                     [[dict valueForKey:@&#34;height&#34;] intValue]);
    [obstacles addObject:[NSValue valueWithCGRect:rect]];
  }
}</code></pre>
<p>And every frame I check if the CGRect of the player intersect one of the obstacles.<br />
In code:<br />
<pre><code>CGRect playerRect = CGRectMake(player.position.x-playerWidth/2, player.position.y-playerHeight/2, playerWidth, playerHeight);
  for (NSValue *rect in obstacles) {
    if (CGRectIntersectsRect([rect CGRectValue], playerRect)) {
      collided = YES;
    }
}</code></pre>
<p>Some hints?
</p></description>
		</item>
		<item>
			<title>Nyvaken on "Should I go chipmunk or Box2D?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/6841#post-40119</link>
			<pubDate>Fri, 04 Jun 2010 14:33:47 +0000</pubDate>
			<dc:creator>Nyvaken</dc:creator>
			<guid isPermaLink="false">40119@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I'm working on a tank game where the player views and controls a tank from above. I want to add some physics such as collision. When i collide with certain object i want them to respond naturally, to be rotated in a natural way etc.</p>
<p>This video shows a similar game with the physics I want to achieve (Collision with enemy tanks and the yellow bits).<br />
<a href="http://www.youtube.com/watch?v=wC_9rFi9Rqo" rel="nofollow">http://www.youtube.com/watch?v=wC_9rFi9Rqo</a></p>
<p>I started out with a normal cocos2d Application project. Should I stick to this or choose any of the other? </p>
<p>Any help is highly appreciated! :)
</p></description>
		</item>
		<item>
			<title>imrank1 on "spacemanager and spritesheets"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/5233#post-31272</link>
			<pubDate>Wed, 24 Mar 2010 03:51:26 +0000</pubDate>
			<dc:creator>imrank1</dc:creator>
			<guid isPermaLink="false">31272@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I recently switched to spritesheets and now have problems with collisions. My objects extend the cpCCSprite class like so : </p>
<p>@interface Boss : cpCCSprite {<br />
}</p>
<p>I have the init method like this :<br />
-(Boss * ) initWithCPBody: (cpShape *) mainBody  withManager:(SpaceManager*)spaceManager {</p>
<p>	if(self != nil){</p>
<p>	self = [Boss spriteWithShape:mainBody texture:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"spiderBoss1.png"].texture];<br />
	[self setAutoFreeShape:YES];</p>
<p>		[self setSpaceManager:spaceManager];</p>
<p>		frameCount = 0;</p>
<p>		NSMutableArray *animFrames = [NSMutableArray array];<br />
		for(int i = 1; i &#60; 15; i++) {</p>
<p>			CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"spiderBoss%d.png",i]];<br />
			[animFrames addObject:frame];<br />
		}</p>
<p>		CCAnimation *animation = [CCAnimation animationWithName:@"forwardAnimation" delay:0.2f frames:animFrames];<br />
		[self runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];</p>
<p>	}</p>
<p>	return self;<br />
}</p>
<p>It's a shooting game so I have a collision handler between bullets and enemies ( bosses ). The bullets are declared like so : </p>
<p>cpShape *bullet = 	[smgr addRectAt:gunPos mass:5 width:5 height:5 rotation:-CC_DEGREES_TO_RADIANS(soldierAngle)];<br />
			bullet-&#62;collision_type = kBulletCollisionType;<br />
			cpCCSprite *ballS= [ cpCCSprite spriteWithShape:bullet file:@"bullet.png"];</p>
<p>and so on..</p>
<p>however in the collision which is below I get a EXC_BAD_ACCESS<br />
on line cpCCSprite* shapeSprite = (cpCCSprite*)shape-&#62;data; in the following collision handler. I don't get any information. Is there somthing I need to do different? </p>
<p>- (int) handleCollisionWithRect:(cpShape*)shape<br />
						 enemy:(cpShape*)enemy<br />
					 contactPts:(cpContact*)contacts<br />
					numContacts:(int)numContacts<br />
					 normalCoef:(cpFloat)coef<br />
{</p>
<p>	//the enemy<br />
	Boss* sprite = (Boss*)enemy-&#62;data;</p>
<p>	[sprite decreaseEnergy:50];<br />
	if ( [sprite getEnergy] == 0 )<br />
	{</p>
<p>		if (sprite)<br />
		{<br />
			[sprite.parent removeChild:sprite cleanup:NO];<br />
			[smgr scheduleToRemoveAndFreeShape:enemy];<br />
			enemy-&#62;data = nil;<br />
		}</p>
<p>	}</p>
<p>//the bullet<br />
//ERROR HERE<br />
	cpCCSprite* shapeSprite = (cpCCSprite*)shape-&#62;data;<br />
	if (shapeSprite)<br />
	{<br />
		[shapeSprite.parent removeChild:shapeSprite cleanup:NO];<br />
		[smgr scheduleToRemoveAndFreeShape:shape];<br />
		shape-&#62;data = nil;<br />
	}</p>
<p>	return 1;<br />
}</p>
<p>thanks for the help
</p></description>
		</item>
		<item>
			<title>shivaz on "Using Chipmunk only for Collision detection"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/577#post-3451</link>
			<pubDate>Fri, 10 Jul 2009 13:19:49 +0000</pubDate>
			<dc:creator>shivaz</dc:creator>
			<guid isPermaLink="false">3451@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>For anyone interested in using Chipmunk only for collision detection, and not for any physics, then I have done up a sample project.</p>
<p>This may not be the best option for collision detection, and I may not have done it the best way, but for anyone who is interested - you can view the thread here:<br />
<a href="http://www.cocos2d-iphone.org/forum/topic/364" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/364</a></p>
<p>The sample is here:<br />
<a href="http://files.me.com/shivaz/5jb01u" rel="nofollow">http://files.me.com/shivaz/5jb01u</a></p>
<p>Do what you like with it, grab it while you can.</p>
<p>Justin
</p></description>
		</item>
		<item>
			<title>fchan on "Detection sprite above and below the camera view"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2696#post-16735</link>
			<pubDate>Wed, 28 Oct 2009 14:44:29 +0000</pubDate>
			<dc:creator>fchan</dc:creator>
			<guid isPermaLink="false">16735@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am trying to detect sprite that have spawned above or below the current camera view. Here's my implementation up to now:</p>
<p>    CGPoint glyphLocation = glyphObject.position;<br />
    CGRect mySurface = CGRectMake(0, (size.height/2+currentEyeLvlY)-size.height, size.width, size.height);<br />
    CGRect mySurface1 = CGRectMake(0, (size.height/2-currentEyeLvlY)+size.height, size.width, size.height);	</p>
<p>    if(!CGRectContainsPoint(mySurface, glyphLocation) &#38;&#38; (glyphObject.position.y &#62; size.height/2+currentEyeLvlY)) {<br />
        NSLog(@"Detect up spawn");<br />
    } else if(!CGRectContainsPoint(mySurface1, glyphLocation) &#38;&#38; (glyphObject.position.y &#60; size.height/2-currentEyeLvlY)) {<br />
        NSLog(@"Detect down spawn");<br />
    }</p>
<p>Basically, currentEyeLvlY is a variable where i keep track on where the camera is adjusted since I am using a button to scroll up and down. And I use this variable to adjust the camera. Now this detects, if a sprite appears in the right positions however, when my camera is where the sprites are, it's still detect it. What I would like it to do, is ignore it if the sprite is in the camera's view. Any help would be appreciated?
</p></description>
		</item>
		<item>
			<title>shivaz on "Chipmunk and Sprite not lining up."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/364#post-2080</link>
			<pubDate>Mon, 29 Jun 2009 13:25:15 +0000</pubDate>
			<dc:creator>shivaz</dc:creator>
			<guid isPermaLink="false">2080@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey All.</p>
<p>Weird problem. I have a sprite that is a sub class of AtlasSprite. It has a cpBody - and I have over-ridden the setPosition method. For some reason when I use the drawObject method to test the cpBody - the body is quite some distance away from the sprite! A consistant distance that seems to move with the sprite around the sprites anchor points. Some code to follow - any ideas what is going on?</p>
<p>I am only using chipmunk to do collision detection - and it looks okay, except the body is way off!</p>
<p>Justin</p>
<pre><code>mysprite.h
@interface mysprite : AtlasSprite
{
	cpBody *spriteBody;

mysprite.m
-(id) initWithCPBody: (cpBody *) bodyIn{
	self = [super init];
	if(self != nil){
		spriteBody = bodyIn;
	}
	return self;
}

-(void) setPosition:(cpVect)pos
{
    [super setPosition:pos];
    // Sync Chipmunk with sprite
    spriteBody-&#62;body-&#62;p = pos;
}

MotionLayer.m

// C function to update the location for each shape
static void eachShape(void *ptr, void* unused)
{
	cpShape *shape = (cpShape*) ptr;
	Sprite *sprite = shape-&#62;data;
	if( sprite ) {
		cpBody *body = shape-&#62;body;
		[sprite setPosition: cpv( body-&#62;p.x, body-&#62;p.y)];
		[sprite setRotation: (float) CC_RADIANS_TO_DEGREES( -body-&#62;a )];
	}
}

//Create a sprite
- (id) init
{
	self = [super init];
	if (self != nil) {

	mysprite *testSprite = [[mysprite alloc] initWithCPBody:[self makeSpriteX:-50 y:-50]];
	[self addChild:testSprite];
	[testSprite setPosition:cpv(416,320-54)];
	[testSprite setRotation:270];
	id action1 = [MoveBy actionWithDuration:2 position:ccp(-38,0)];
	id action = [Sequence actions:	action1,
					action1,
					action1,
					action1,
					action1,
					nil];
	[testSprite runAction: action];
}

-(cpBody *) makeSpriteX: (float) x y:(float) y
{
	AtlasSpriteManager *mgr = (AtlasSpriteManager*) [self getChildByTag:kTagSpriteManager];
	AtlasSprite *spriteTest = [AtlasSprite spriteWithRect:CGRectMake(0,0,30,60) spriteManager:mgr];
	[mgr addChild:spriteTest];

	spriteTest.position = ccp( x, y);
	spriteTest.anchorPoint = ccp(0.5f, 0.75f);

	cpVect verts1[] = {
		cpv(-15,-30),
		cpv(-15, 30),
		cpv(15, 30),
		cpv(15,-30),
	};

	cpBody *spriteBod = cpBodyNew(100.0f, INFINITY);
	spriteBod-&#62;p = cpv(x, y);
	spriteBod-&#62;v = cpv(0, 0);

	//cpSpaceAddBody(space, spriteBod);
	cpShape * spriteShape;

	spriteShape = cpPolyShapeNew(spriteBod, 4, verts1, cpv(x, y));	

	spriteShape-&#62;e = 0.9f; spriteShape-&#62;u = 0.9f;
	spriteShape-&#62;data = spriteTest;
	spriteShape-&#62;collision_type = 1; //this is new!
	cpSpaceAddShape(space, spriteShape);

	return spriteShape;
}</code></pre></description>
		</item>
		<item>
			<title>emalamisura on "Sprite Touch Detection after Action MoveTo not Working?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/484#post-2863</link>
			<pubDate>Mon, 06 Jul 2009 01:00:50 +0000</pubDate>
			<dc:creator>emalamisura</dc:creator>
			<guid isPermaLink="false">2863@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have the following code to detect touches, and it works fine. However once I do an Action MoveTo, and I move the sprite to a new location the original location is the only region where the touch detection works, the new location of the sprite is not working properly, anyone know why?</p>
<p>-(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event<br />
{<br />
	UITouch *touch = [touches anyObject];<br />
	CGPoint point = [touch locationInView: [touch view]];<br />
	point =  [[Director sharedDirector] convertCoordinate: point];</p>
<p>	CGRect rect = [mySprite rect];<br />
	if(CGRectContainsPoint(rect, point))<br />
	{<br />
		mySpriteClicked = YES;<br />
	}</p>
<p>	return kEventHandled;<br />
}</p>
<p>And then the Sprite object has the following:</p>
<p>- (CGRect) rect {<br />
	float w = [self contentSize].width;<br />
	float h = [self contentSize].height;<br />
	CGPoint point = CGPointMake([self position].x - (w/2), [self position].y - (h/2));</p>
<p>	return CGRectMake(point.x, point.y, w, h);<br />
}</p>
<p>If anyone could be of assistance it would be great, thanks!
</p></description>
		</item>

	</channel>
</rss>

