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

		<item>
			<title>Dani on "Pixel Perfect Collision Detection using Color Blending"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18522#post-103858</link>
			<pubDate>Sat, 09 Jul 2011 19:47:04 +0000</pubDate>
			<dc:creator>Dani</dc:creator>
			<guid isPermaLink="false">103858@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello everybody.</p>
<p>I would like to implement a function to <strong>detect collisions between 2 sprites at pixel level</strong>. There is a good solution I've used before in ActionScript 3, but I need help to integrate it with cocos2d framework.</p>
<p><strong>Original AS2 solution:</strong> <a href="http://gskinner.com/blog/archives/2005/08/flash_8_shape_b.html">http://gskinner.com/blog/archives/2005/08/flash_8_shape_b.html</a></p>
<p><strong>Improved AS3 solution:</strong> <a href="http://troygilbert.com/2007/06/pixel-perfect-collision-detection-in-actionscript3/">http://troygilbert.com/2007/06/pixel-perfect-collision-detection-in-actionscript3/</a></p>
<p>Now look at this image:</p>
<p><img src='http://img190.imageshack.us/img190/7687/pixelperfectsample.png' /></p>
<p>Look at the third case: the method consist on drawing the first sprite in RED, the second in WHITE (with DIFFERENCE blending mode), and look if there is CYAN in the mix. We only draw the data inside the intersection, not the whole sprites.</p>
<p>The steps:</p>
<ol>
<li>Check for bounding box collision.</li>
<li>Get the intersect rect.</li>
<li>Create a bitmap object with the size of the intersection.</li>
<li>Draw the sprite A in RED (taking into account scaling, rotation, etc) into the bitmap object.</li>
<li>Draw the Sprite B in WHITE with DIFFERENCE blending (taking into account scaling, rotation, etc) into the same bitmap object.</li>
<li>Look if there is CYAN color in the bitmap object.</li>
</ol>
<p><strong><br />
I don't know how and where to draw the intersection data for both objects (steps 3, 4 and 5). Any ideas?</strong></p>
<p>This is how the function could look:</p>
<pre><code>-(BOOL) isCollisionBetweenSpriteA:(CCSprite*)spr1 spriteB:(CCSprite*)spr2 pixelPerfect:(BOOL)pp
{
    BOOL isCollision = NO;
    CGRect intersection = CGRectIntersection([spr1 boundingBox], [spr2 boundingBox]);

    if (!CGRectIsEmpty(intersection))
    {
        // If we&#39;re not checking for pixel perfect collisions, return true
        if (!pp) {return YES;}

        // 1) Draw the Sprite 1 intersection content in RED color into a bitmap object (must check if it&#39;s rotated, scaled, etc)

        // 2) Draw the Sprite 2 intersection content in WHITE color using DIFFERENCE blending option into the same bitmap object

        // 3) Check if there is CYAN color in the mix (WHITE difference blended on RED makes CYAN)
    }

    return isCollision;
}</code></pre>
<p>Please, any help and ideas to solve this will be very much appreciated. And maybe this function is a good feature for the cocos2d-iphone Extensions.</p>
<p>Regards.
</p></description>
		</item>
		<item>
			<title>MandarX on "[Box2D] How to know when the shape hits the edges"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28887#post-142383</link>
			<pubDate>Thu, 02 Feb 2012 20:30:29 +0000</pubDate>
			<dc:creator>MandarX</dc:creator>
			<guid isPermaLink="false">142383@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello, </p>
<p>I'm learning Box2D</p>
<p>I put a sprite/shape in my scene/world</p>
<p>how can I know when it hits the edges?</p>
<p>(I have to play an effect)</p>
<p>thanks</p>
<p>MandarX
</p></description>
		</item>
		<item>
			<title>kingappdesigns on "Need help what am i doing worng it is not logging the collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28869#post-142242</link>
			<pubDate>Thu, 02 Feb 2012 04:08:18 +0000</pubDate>
			<dc:creator>kingappdesigns</dc:creator>
			<guid isPermaLink="false">142242@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>- (void)update:(ccTime)dt {<br />
    [[CCDirector sharedDirector] winSize];<br />
    CGRect duckRect = CGRectMake(<br />
                                       duckSprite.position.x - (duckSprite.contentSize.width/2),<br />
                                       duckSprite.position.y - (duckSprite.contentSize.height/2),<br />
                                       duckSprite.contentSize.width,<br />
                                       duckSprite.contentSize.height);</p>
<p>    CGRect crosshairRect = CGRectMake(<br />
                                 crosshair.position.x - (crosshair.contentSize.width/2),<br />
                                 crosshair.position.y - (crosshair.contentSize.height/2),<br />
                                 crosshair.contentSize.width,<br />
                                 crosshair.contentSize.height);<br />
    if (CGRectIntersectsRect(duckRect, crosshairRect)) {<br />
        CCLOG(@"Collision!");</p>
<p>        }<br />
}
</p></description>
		</item>
		<item>
			<title>Bartos on "Multiple contacts with Box2D Contactlistener"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28527#post-140439</link>
			<pubDate>Fri, 20 Jan 2012 18:46:51 +0000</pubDate>
			<dc:creator>Bartos</dc:creator>
			<guid isPermaLink="false">140439@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I'm new to both cocos2d and box2d. I'm having some difficulties with implementing some code that plays a sound everytime a ball in my game hits the player. I searched the forum and saw that some people were reporting similar problems, but I haven't really found a solution. Hopefully you guys can help :)</p>
<p>Following the Ray Wenderlicht breakout tutorial part 2, I created a MyContactListener class that implements BeginContact and EndContact and stores the contacts in a public vector. In the tick function of my HelloWorldLayer I iterate through the contacts in this vector and check if the bodies belonging to the contacting fixtures are the ball and the player. For the ball I just used a single circle shape, and for the player i used PhysicsEditor to create a shape (A single fixture with a single polygon, although the plist file suggests that physicsEditor made 1 fixture consisting of multiple polygons).  The problem is that I'm getting multiple contacts every time the ball hits the player, even though the bodies have only 1 fixture. Sometimes this means multiple beginContacts in a row, and then multiple endContacts in a row, and sometimes this means beginContact and endContact alternating multiple times in a row. Do you guys know what the problem is? Could it be related to the mutiple polygons in the fixture of the player body? </p>
<p>Let me know If I am being too vague and you need more info :) </p>
<p>Thanks
</p></description>
		</item>
		<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>eozkucur1 on "collision detection between two custom meshes with Bullet"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21838#post-121297</link>
			<pubDate>Fri, 14 Oct 2011 20:13:41 +0000</pubDate>
			<dc:creator>eozkucur1</dc:creator>
			<guid isPermaLink="false">121297@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi, I finally managed to use Bullet with Cocos3d to detect collision between custom concave meshes and want to share my work. I am developing a flight game and we have some rough terrain with hills and plains. I want to detect if the aircraft crashes to the ground, but the terrain is a concave shape, so bounding boxes do not work. </p>
<p>For those who know about Bullet, the key thing is to pass vertex and index array to Bullet correctly and optimize static meshes with btBvhTriangleMeshShape class. As far as I understood, the objects with btBvhTriangleMeshShape class are immune to transformations applied afterwards, so for dynamic objects, btConvexTriangleMeshShape class can be used.</p>
<p>Below is my singleton class which acts as a bridge between Cocos3d and Bullet. It uses minimal code from Bullet, just enough to detect collisions on demand. I copied btBulletCollisionCommon.h and directories BulletCollision and LinearMath from Bullet source into my project.</p>
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#60;Foundation/Foundation.h&#62;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CC3MeshNode.h&#34;

@interface CollisionDetector : NSObject
{}
+ (CollisionDetector*)sharedDetector;
@property (nonatomic,retain) NSMutableDictionary* cc3Objects; // environmental objects
@property (nonatomic,retain) NSMutableDictionary* cc3RefObjects; // our protagonist objects :)
-(void) addShapeSphere:(CC3Node*) sh withId:(int)shId withRadius:(float) r;
-(void) addShape:(CC3MeshNode*) sh withId:(int)shId isStatic:(BOOL)isStatic;
-(void) addStaticObject:(CC3Node*) obj withId:(int)objId withShape:(int)shapeId;
-(void) addReferenceObject:(CC3Node*) obj withId:(int)objId withShape:(int)shapeId;
-(int) checkCollision:(int)refObjId;
@end

#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CollisionDetector.h&#34;
#include &#34;btBulletCollisionCommon.h&#34;
#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;CC3VertexArrayMesh.h&#34;
#include &#60;map&#62;
#include &#60;string&#62;
#include &#60;iostream&#62;

@implementation CollisionDetector
@synthesize cc3Objects;
@synthesize cc3RefObjects;

static CollisionDetector *sharedDT = nil;
#<a href='http://www.cocos2d-iphone.org/forum/tags/define'>define</a> MAX_COLL_OBJECTS 50
static btCollisionObject*	objects[MAX_COLL_OBJECTS];
static btCollisionObject*	refObjects[MAX_COLL_OBJECTS];
static btCollisionWorld*	collisionWorld = 0;
static btCollisionShape* shapes[MAX_COLL_OBJECTS];
static int contactObjId;

+ (CollisionDetector*)sharedDetector
{
    if (sharedDT == nil) {
        sharedDT = [[super alloc] init];
        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
        btDbvtBroadphase*	broadphase = new btDbvtBroadphase();
        collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);
        sharedDT.cc3Objects=[NSMutableDictionary dictionaryWithCapacity:10];
        sharedDT.cc3RefObjects=[NSMutableDictionary dictionaryWithCapacity:10];
        contactObjId=-1;
    }
    return sharedDT;

}

-(void) addShapeSphere:(CC3Node*) sh withId:(int)shId withRadius:(float) r
{
    btSphereShape* shp=new btSphereShape(r);
    NSLog(@&#34;sphere shape added with id: %d , radius: %g&#34;,shId,r);
    shapes[shId]=shp;
}

-(void) addShape:(CC3MeshNode*) sh withId:(int)shId isStatic:(BOOL)isStatic
{
    CC3VertexArrayMesh* mesh=((CC3VertexArrayMesh*)(sh.mesh));
    btTriangleIndexVertexArray* tiva=new btTriangleIndexVertexArray();
    btIndexedMesh im;
    im.m_vertexBase = (unsigned char*)mesh.vertexLocations.elements;
    im.m_vertexStride = mesh.vertexLocations.elementStride;
    im.m_numVertices = mesh.vertexLocations.elementCount;
    im.m_triangleIndexBase = (const unsigned char*)mesh.vertexIndices.elements;
    im.m_triangleIndexStride = mesh.vertexIndices.elementStride*3;
    im.m_numTriangles = mesh.vertexIndices.elementCount/3;
    im.m_indexType=PHY_SHORT;
    im.m_vertexType=PHY_FLOAT;
    tiva-&#62;addIndexedMesh(im,PHY_SHORT);
    [mesh retainVertexIndices];
    [mesh retainVertexLocations];
    if(isStatic){
        btBvhTriangleMeshShape* shp=new btBvhTriangleMeshShape(tiva,true);
        shapes[shId]=shp;
    }else{
        btConvexTriangleMeshShape* shp=new btConvexTriangleMeshShape(tiva);
        shapes[shId]=shp;
    }
}

-(void) addStaticObject:(CC3Node*) obj withId:(int)objId withShape:(int)shapeId
{
    [cc3Objects setObject:obj forKey:[NSNumber numberWithInt:objId]];
    btCollisionObject* collisionObj=new btCollisionObject();
    collisionObj-&#62;setCollisionShape(shapes[shapeId]);
    collisionObj-&#62;setUserPointer((void*)objId);
    objects[objId]=collisionObj;
    collisionWorld-&#62;addCollisionObject(collisionObj);
}

-(void) addReferenceObject:(CC3Node*) obj withId:(int)objId withShape:(int)shapeId
{
    [cc3RefObjects setObject:obj forKey:[NSNumber numberWithInt:objId]];
    btCollisionObject* collisionObj=new btCollisionObject();
    collisionObj-&#62;setCollisionShape(shapes[shapeId]);
    int a=MAX_COLL_OBJECTS;
    collisionObj-&#62;setUserPointer((void*)a);
    refObjects[objId]=collisionObj;
}

struct btMyResult : public btCollisionWorld::ContactResultCallback
{
	virtual	btScalar	addSingleResult(btManifoldPoint&#38; cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
	{
        if(((int)(colObj1-&#62;getUserPointer()))!=MAX_COLL_OBJECTS){
            contactObjId=(int)(colObj1-&#62;getUserPointer());
        }else if(((int)(colObj0-&#62;getUserPointer()))!=MAX_COLL_OBJECTS){
            contactObjId=(int)(colObj0-&#62;getUserPointer());
        }else{
            std::cout&#60;&#60;&#34;unexpected collision&#34;&#60;&#60;std::endl;
        }
        return 0;
	}
};

-(int) checkCollision:(int)refObjId
{
    contactObjId=-1;
    CC3Node* nd=[self.cc3RefObjects objectForKey:[NSNumber numberWithInt:refObjId]];
    btCollisionObject* collisionObj=refObjects[refObjId];
    collisionObj-&#62;getWorldTransform().setOrigin(btVector3(nd.globalLocation.x,nd.globalLocation.y,nd.globalLocation.z));
    CC3Vector4 quat=nd.transformMatrix.extractQuaternion;
    collisionObj-&#62;getWorldTransform().setRotation(btQuaternion(quat.x,quat.y,quat.z,quat.w));
    btMyResult collisionCallback;
	collisionWorld-&#62;contactTest(collisionObj,collisionCallback);
    return contactObjId;
}

@end</code></pre>
<p>In my CC3World class, I use it on demand as:</p>
<pre><code>// in initializeWorld
    CC3MeshNode* terrain;
    CC3MeshNode* myF16;
    // initialize nodes. In my case, they are loaded from a POD file.
    [[CollisionDetector sharedDetector] addShape:terrain withId:0 isStatic:YES];
    [[CollisionDetector sharedDetector] addShape:myF16 withId:1 isStatic:NO];
    [[CollisionDetector sharedDetector] addStaticObject:terrain withId:0 withShape:0];
    [[CollisionDetector sharedDetector] addReferenceObject:myF16 withId:0 withShape:1];

// in updateBeforeTransform
    int result=[[CollisionDetector sharedDetector] checkCollision:0];
    if(result!=-1){
        // reference object #0 collided with object #result
    }</code></pre>
<p>I hope it helps.
</p></description>
		</item>
		<item>
			<title>Andreas Loew on "PhysicsEditor is here!!!!!"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/13456#post-75498</link>
			<pubDate>Thu, 10 Feb 2011 19:29:50 +0000</pubDate>
			<dc:creator>Andreas Loew</dc:creator>
			<guid isPermaLink="false">75498@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,</p>
<p>many of you might already know me from TexturePacker - now I have a new high quality tool for you:</p>
<p><a href="http://www.physicseditor.de/features">PhysicsEditor</a></p>
<p><em>Stop copy and paste!</em><br />
           <em>Stop worrying about ccw or cw!</em><br />
                      <em>Stop worrying about convex or not.</em></p>
<p>Features:</p>
<ul>
<li>Automated shape tracing(!!!)</li>
<li>Automated handling of convex polygons(!!!)</li>
<li>Automated handling of polygon oriantation(!!!)</li>
<li>Anchorpoint editor(!!!)</li>
<li>Support for Box2D and Chipmunk</li>
<li>plilst files for cocos2d</li>
<li>box2d loader code included</li>
<li>Demo</li>
</ul>
<p>The main advantage is that you can use the exporters already shipped with PhysicsEditor or simply create your own! A flexible template engine lets you export what ever text format you need.</p>
<p>The download includes a fully working demo.</p>
<p>How to use it in your code? Forget about copy and pasting vertex lists!</p>
<p>This is for box2d users:</p>
<p>Load the plist file<br />
<pre><code>[[GB2ShapeCache sharedShapeCache]   addShapesWithFile:@&#34;shapedefs.plist&#34;];</code></pre>
<p>Add the polygons to a shape<br />
<pre><code>[[GB2ShapeCache sharedShapeCache]  addFixturesToBody:body
                                   forShapeName:@&#34;shapename&#34;];</code></pre>
<p>Set the anchor point:<br />
<pre><code>[sprite setAnchorPoint:[[GB2ShapeCache sharedShapeCache]
    anchorPointForShape:@&#34;shapename&#34;]];</code></pre>
<p>Done!</p>
<p>Since I am not so familiar with chipmunk I could use some help in setting up a loader in the best way for it.</p>
<p>Cheers<br />
Andreas
</p></description>
		</item>
		<item>
			<title>MisterHedge on "[Problem] Getting TileMap collision and DPad movement to work together"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28254#post-138982</link>
			<pubDate>Wed, 11 Jan 2012 01:04:03 +0000</pubDate>
			<dc:creator>MisterHedge</dc:creator>
			<guid isPermaLink="false">138982@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hey all,</p>
<p>Okay, I've been having a problem. I'm making a simple tiled RPG-like game using Tiled and Cocos2D. Following one of Ray Wenderlich's tutorials (found here: <a href="http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2" rel="nofollow">http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2</a> ), I managed to add collision to my tiled map. However, I didn't like the way he implemented movement in the game and instead opted for a directional pad. I found a very nice bit of code called EasyArrows (found here: <a href="http://www.cocos2d-iphone.org/forum/topic/7692" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/7692</a> ) that accomplished exactly what I was hoping to do. The problem I'm facing is that I can get the two to work separately but not together. Before I add EasyArrows, the collision and movement work just fine. After I add EasyArrows, my character sprite completely ignores the collision, but he moves how I want him to.</p>
<p>As you might have guessed, I'm a bit of a newbie still, but I'm starting to get the hang of things. One of the best ways to learn is to make mistakes, eh? :P</p>
<p>If you'd like to see any specific segments of code, let me know. I'll post them here.</p>
<p>Thanks guys!</p>
<p>EDIT:</p>
<p>I've decided to go ahead and put my code in anyway.</p>
<p>"stLayer" is the collision tile layer in my Tiled map (see Ray's tutorial for details)<br />
"mage" is my player sprite</p>
<p>-----</p>
<p>HelloWorldLayer.m</p>
<pre><code>// This is the part of the EasyArrows code that you place within the HelloWorldLayer
-(void)update:(ccTime)dt{

    if ([[menu getButton:2]isSelected])
    {
        mage.position = ccp(mage.position.x,mage.position.y + 3);
    }
    if ([[menu getButton:8]isSelected])
    {
        mage.position = ccp(mage.position.x,mage.position.y - 3);
    }
    if ([[menu getButton:4]isSelected])
    {
        mage.position = ccp(mage.position.x + 3,mage.position.y);
    }
    if ([[menu getButton:6]isSelected])
    {
        mage.position = ccp(mage.position.x - 4,mage.position.y);
    }
}

// This is Rey&#039;s code for the collision

-(void) setPlayerPosition:(CGPoint)position{
    CGPoint tileCoord = [self tileCoordForPosition:position]; 

    int tileGid = [stLayer tileGIDAt:tileCoord]; 

    if(tileGid){ 

        NSDictionary *properties = [theMap propertiesForGID:tileGid]; 

        if(properties){
            NSString *collision = [properties valueForKey:@&#34;Collidable&#34;];
            if (collision &#38;&#38; [collision compare:@&#34;True&#34;] ==NSOrderedSame) {
                return;
            }
        }

    }

    mage.position = position;
}

// This converts tiles to coordinates
-(CGPoint)tileCoordForPosition:(CGPoint)position{
    int x = position.x/theMap.tileSize.width;
    int y = ((theMap.mapSize.height * theMap.tileSize.height)-position.y)/theMap.tileSize.height;
    return ccp(x,y);
}</code></pre></description>
		</item>
		<item>
			<title>tetna on "Firing Bullets user is moving."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28098#post-138128</link>
			<pubDate>Thu, 05 Jan 2012 08:35:35 +0000</pubDate>
			<dc:creator>tetna</dc:creator>
			<guid isPermaLink="false">138128@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>i am experimenting on this open source app game with an old version of cocos2d</p>
<p>i have successfully inserted enemies and have collision detected also... now i want</p>
<p>is to put on some projectiles to make it look more awesome however i tried ray's tutorial</p>
<p><a href="http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial" rel="nofollow">http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial</a></p>
<p>but the projectiles still aren't shooting.. </p>
<p>PS: my target is moving or jumping rather..</p>
<p>here is what i did:</p>
<pre><code>-(void)TouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
   AtlasSprite *bird = (AtlasSprite *) [spriteManager getChildByTag:kBird];

   UITouch *touch = [touches anyObject];
   CGPoint location = [touch locationInView:[touch view]];
   location = [[Director sharedDirector]convertCoordinate:location];

   CGSize winSize = [[Director sharedDirector]winSize];
   Sprite *projectile = [Sprite spriteWithFile:@&#34;psn.png&#34;];
   projectile.position = ccp(bird.position.y,bird.position.x);

   int offX = location.x - projectile.position.x;
   int offY = location.y - projectile.position.y;

   [self addChild:projectile];

   int realX = winSize.width + (projectile.contentSize.width/2);
   float ratio = (float) offY / (float) offX;
   int realY = (realX *ratio) + projectile.position.y;
   CGPoint realDest = ccp(realX, realY);

   int offRealX = realX - projectile.position.x;
   int offRealY = realY - projectile.position.y;
   float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
   float velocity = 480/1;
   float realMoveDuration = length/velocity;

   [projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest],
                     [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
}</code></pre>
<p>i hope someone could help and that would be great :)
</p></description>
		</item>
		<item>
			<title>tetna on "Simple Collision Detection for Newbie"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/28053#post-137909</link>
			<pubDate>Wed, 04 Jan 2012 07:41:57 +0000</pubDate>
			<dc:creator>tetna</dc:creator>
			<guid isPermaLink="false">137909@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>im really new to cocos2d and i downloaded this open source app.</p>
<p>what im trying to do is to put enemies on the app and hopefully add some other functions</p>
<p>i have successfully added the enemies however im stucked at this collision detection. as i said im new to cocos2d and i really dont know anything about</p>
<p>box2d and chipmunk.. i dont have knowledge in java or in c++</p>
<p>maybe there's some other way to detect collision??</p>
<p>here a sample of my code:<br />
Code:<br />
<pre><code>- (id)init {
//	NSLog(@&#34;Game::init&#34;);

	if(![super init]) return nil;

	gameSuspended = YES;

	AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];

	[self initPlatforms];

	AtlasSprite *bird = [AtlasSprite spriteWithRect:CGRectMake(608,16,44,32) spriteManager:spriteManager];
	[spriteManager addChild:bird z:4 tag:kBird];

	AtlasSprite *bonus;

	for(int i=0; i&#60;kNumBonuses; i++) {
		bonus = [AtlasSprite spriteWithRect:CGRectMake(608+i*32,256,25,25) spriteManager:spriteManager];
		[spriteManager addChild:bonus z:4 tag:kBonusStartTag+i];
		bonus.visible = NO;
	}

//	LabelAtlas *scoreLabel = [LabelAtlas labelAtlasWithString:@&#34;0&#34; charMapFile:@&#34;charmap.png&#34; itemWidth:24 itemHeight:32 startCharMap:&#039; &#039;];
//	[self addChild:scoreLabel z:5 tag:kScoreLabel];

	BitmapFontAtlas *scoreLabel = [BitmapFontAtlas bitmapFontAtlasWithString:@&#34;0&#34; fntFile:@&#34;bitmapFont.fnt&#34;];
	[self addChild:scoreLabel z:5 tag:kScoreLabel];
	scoreLabel.position = ccp(160,430);

	[self schedule:@selector(step:)];

	isTouchEnabled = YES;
	isAccelerometerEnabled = YES;

	[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kFPS)];

	[self startGame];
	[self schedule:@selector(gameLogic:) interval:5.0];
	return self;

}

-(void)addTarget {

	Sprite *target = [Sprite spriteWithFile:@&#34;waa.gif&#34;];
	target.position = ccp(300,400);

	[self addChild:target];

	CGSize winSize = [[Director sharedDirector]winSize];
	int minX = target.contentSize.height/2;
	int maxX = winSize.height -target.contentSize.height/2;
	int rangeX = maxX - minX;
	int actualX = (arc4random() % rangeX) +minX;

	int minDuration = 2.0;
	int maxDuration = 4.0;
	int rangeDuration = maxDuration - minDuration;
	int actualDuration = (arc4random() % rangeDuration) + minDuration;

	id actionMove = [MoveTo actionWithDuration:actualDuration position:ccp(-target.contentSize.width/2,actualX)];
	id actionMoveDone = [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)];
	[target runAction:[Sequence actions:actionMove, actionMoveDone,nil]];

}

-(void)spriteMoveFinished:(id)sender {
	Sprite *sprite = (Sprite *)sender;
	[self removeChild:sprite cleanup:YES];
}
-(void)gameLogic:(ccTime)dt {
	[self addTarget];

}</code></pre>
<p>PS: i have read other topics about this but i dont really understand a thing</p>
<p>i hope someone could help i really need it.. thanks
</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>sm_frost on "Custom sliding collision help"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25755#post-134152</link>
			<pubDate>Mon, 19 Dec 2011 07:34:49 +0000</pubDate>
			<dc:creator>sm_frost</dc:creator>
			<guid isPermaLink="false">134152@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The following code works well for sliding collision but when i have two sprite objects next to each other just so that a third object can be placed between them in the right way, the third object will bounce from one side to the other.  I need to figure out a way to stop this from happening.</p>
<p>the collide function is called from a for loop that iterates through all sprites on the field.</p>
<p> collideBy is = 3  // the speed that an average sprite moves ( creates a padding buffer so you don't activate the wrong side for collision )</p>
<pre><code>-(void)collide :(CCSprite *)sprite1 :(CCSprite *)sprite2{

    //bottem
    if (sprite1.position.y&#62;sprite2.position.y &#38;&#38; sprite2.position.x&#62;sprite1.position.x-sprite1.contentSize.width+collideBy &#38;&#38; sprite2.position.x&#60;sprite1.position.x+sprite1.contentSize.width-collideBy) {
        sprite2.position= ccp(sprite2.position.x,sprite1.position.y-sprite1.contentSize.height);
    }

    //left
    if((sprite1.position.x&#62;sprite2.position.x &#38;&#38; sprite2.position.y&#62;sprite1.position.y-sprite1.contentSize.height+collideBy &#38;&#38; sprite2.position.y&#60;sprite1.position.y+sprite1.contentSize.height-collideBy) ){
        sprite2.position= ccp(sprite1.position.x-sprite1.contentSize.width,sprite2.position.y);
    }

    //top
    if (sprite1.position.y&#60;sprite2.position.y &#38;&#38; sprite2.position.x&#62;sprite1.position.x-sprite1.contentSize.width+collideBy &#38;&#38; sprite2.position.x&#60;sprite1.position.x+sprite1.contentSize.width-collideBy) {
        sprite2.position= ccp(sprite2.position.x,sprite1.position.y+sprite1.contentSize.height);

    }

    //right
    if(sprite1.position.x&#60;sprite2.position.x &#38;&#38; sprite2.position.y&#62;sprite1.position.y-sprite1.contentSize.height+collideBy &#38;&#38; sprite2.position.y &#60; sprite1.position.y + sprite1.contentSize.height-collideBy){
        sprite2.position=ccp(sprite1.position.x+sprite1.contentSize.width,sprite2.position.y);

    }

}</code></pre></description>
		</item>
		<item>
			<title>jay18001 on "Collision Detection Problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25391#post-132182</link>
			<pubDate>Thu, 08 Dec 2011 01:09:05 +0000</pubDate>
			<dc:creator>jay18001</dc:creator>
			<guid isPermaLink="false">132182@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm not using chipmunk or box2d<br />
I making a several sprites with the same name<br />
<pre><code>index = (arc4random() % 4) + 1;
    NSString *fileName = [NSString stringWithFormat:@&#34;bug%d.png&#34;, index];
    myBug = [CCSprite spriteWithFile:fileName];</code></pre>
<p>and I need to detect if the individual images hit a static sprite.</p>
<p>All the ways that I've seen only worked 10% of the time or not at all. i found out what why it's not working. It's not working because when i detect if one hit the static sprite the point will be changed by anther spawning. </p>
<p>Any Ideas to get it to work. Thanks
</p></description>
		</item>
		<item>
			<title>nomad_games on "editing CCParticleSystem to detect collision of particles"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/18372#post-103056</link>
			<pubDate>Tue, 05 Jul 2011 23:44:58 +0000</pubDate>
			<dc:creator>nomad_games</dc:creator>
			<guid isPermaLink="false">103056@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello all,</p>
<p>I am trying to detect when the individual particles from a particle system collide with a sprite in my layer.  I have read several posts from devs who are trying to do the same thing.  I realize that this is going to be pretty CPU expensive, but it's the only way to do what I want to do.</p>
<p>I believe that if I could somehow gain access to the array of particles owned by CCParticleSystem, I could then check the points of each individual particle against the sprite's bounding box.  Currently CCParticleSystem does not have this property, and I am having trouble adding it.</p>
<p>I have gotten the furthest with this post: <a href="http://www.cocos2d-iphone.org/forum/topic/4758" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/4758</a></p>
<p>What I specifically need help with is adding a property that holds the array and linking it up.</p>
<p>Any help would be appreciated.  Thanks!
</p></description>
		</item>
		<item>
			<title>erdiyerli on "Collision between player and obstacle"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/25473#post-132587</link>
			<pubDate>Sat, 10 Dec 2011 13:36:31 +0000</pubDate>
			<dc:creator>erdiyerli</dc:creator>
			<guid isPermaLink="false">132587@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi</p>
<p>    I have an obstacle in my game <a href="http://dl.dropbox.com/u/1848977/pipe1.png" rel="nofollow">http://dl.dropbox.com/u/1848977/pipe1.png</a><br />
and want to colide it with player. You see some areas of the pipe are cut. What I want to do is to check if the player could pass the obstacle from that areas. I tried to use CGRectIntersect but it didin't work as I want.How can I do that any idea ?
</p></description>
		</item>
		<item>
			<title>TheDevil on "[box2d] Restrict Impulse after collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/24732#post-130366</link>
			<pubDate>Wed, 30 Nov 2011 09:46:22 +0000</pubDate>
			<dc:creator>TheDevil</dc:creator>
			<guid isPermaLink="false">130366@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is there a way, other that restitution and density, to bound the maximum impulse that box2d applies to two bodies on collision?<br />
Im my case, there are two circles that collide. Now the feel with which they bounce off each other seems fine, but if collide with very high speed, the bounce all around the screen. In postSolve in the contact listener I can the see the impulse value that are going to be applied to the bodies and I want to be able to limit it. Am I think in the wrong direction here? Is there any way to achieve this?
</p></description>
		</item>
		<item>
			<title>TheDevil on "MouseJoint Move Body"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/23846#post-128745</link>
			<pubDate>Fri, 25 Nov 2011 13:32:14 +0000</pubDate>
			<dc:creator>TheDevil</dc:creator>
			<guid isPermaLink="false">128745@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
I am trying collision between two dynamic bodies. One body drops from the top of the screen. The other body is created on TouchBegan and is moves around according to the touch point using a mouse joint. The problem is that the bodies dont react to the collision all the time. In the contact listener the collision is registered but the force is not applied to the body that is falling from the top of the screen. If I swipe slowly or if I hold the finger in place then the force is applied. I have tried increasing the positionIterations and the velocityIterations and also setting both the bodies to bullet. But nothing seems to be working. Both the bodies are circles and are set as dynamic bodies.<br />
Any help is appreciated.
</p></description>
		</item>
		<item>
			<title>oeva on "Box2d Cocos2d circle crash on contact with ground"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22700#post-125801</link>
			<pubDate>Sun, 13 Nov 2011 09:51:29 +0000</pubDate>
			<dc:creator>oeva</dc:creator>
			<guid isPermaLink="false">125801@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>This is my first question here so sorry if I do something wrong or this is too long. I have been reading this tutorial by Ray Wenderlich, I have modified it so it is flatter and gradually goes down hill. Basically I have a ball roll down a bumpy hill, but at the moment the ball only drops from about 100 pixels above. When ever the touch the app crashes (the app is a Mac Cocos2d Box2d app). The ball code is this:</p>
<p>CGSize winSize = [CCDirector sharedDirector].winSize;<br />
self.oeva = [CCSprite spriteWithTexture:[[CCTextureCache sharedTextureCache] addImage:@"Ball.png"]rect:CGRectMake(0, 0, 64, 64)];<br />
_oeva.position = CGPointMake(68, winSize.height/2);<br />
[self addChild:_oeva z:1];<br />
b2BodyDef oevaBodyDef;<br />
oevaBodyDef.type = b2_dynamicBody;<br />
oevaBodyDef.position.Set(68/PTM_RATIO, (winSize.height/2)/PTM_RATIO);<br />
// oevaBodyDef.userData = _oeva;<br />
_oevaBody = world-&#62;CreateBody(&#38;oevaBodyDef);<br />
b2BodyDef bodyDef;<br />
bodyDef.type = b2_dynamicBody;</p>
<p>bodyDef.position.Set(60/PTM_RATIO, 400/PTM_RATIO);<br />
bodyDef.userData = _oeva;<br />
b2Body *body = world-&#62;CreateBody(&#38;bodyDef);</p>
<p>// Define another box shape for our dynamic body.<br />
b2CircleShape dynamicBox;<br />
dynamicBox.m_radius = 70/PTM_RATIO;//These are mid points for our 1m box</p>
<p>// Define the dynamic body fixture.<br />
b2FixtureDef fixtureDef;<br />
fixtureDef.shape = &#38;dynamicBox;<br />
fixtureDef.density = 1.0f;<br />
fixtureDef.friction = 0.3f;<br />
body-&#62;CreateFixture(&#38;fixtureDef);<br />
That works fine. This is the terrain code, this also works fine:</p>
<p>-(void)generateTerrainWithWorld: (b2World *) inputWorld: (int) hillSize;{<br />
b2BodyDef bd;<br />
bd.position.Set(0, 0);</p>
<p>body = inputWorld-&#62;CreateBody(&#38;bd);</p>
<p>b2PolygonShape shape;<br />
b2FixtureDef fixtureDef;<br />
currentSlope = 0;</p>
<p>CGSize winSize = [CCDirector sharedDirector].winSize;<br />
float xf = 0;<br />
float yf = (arc4random() % 10)+winSize.height/3;<br />
int x = 200;<br />
for(int i = 0; i &#60; maxHillPoints; ++i) {<br />
    hillPoints[i] = CGPointMake(xf, yf);<br />
    xf = xf+ (arc4random() % x/2)+x/2;<br />
    yf = ((arc4random() % 30)+winSize.height/3)-currentSlope;<br />
    currentSlope +=10;<br />
}</p>
<p>int hSegments;</p>
<p>for (int i=0; i&#60;maxHillPoints-1; i++) {<br />
    CGPoint p0 = hillPoints[i-1];<br />
    CGPoint p1 = hillPoints[i];<br />
    hSegments = floorf((p1.x-p0.x)/cosineSegmentWidth);<br />
    float dx = (p1.x - p0.x) / hSegments;<br />
    float da = M_PI / hSegments;<br />
    float ymid = (p0.y + p1.y) / 2;<br />
    float ampl = (p0.y - p1.y) / 2;</p>
<p>    CGPoint pt0, pt1;<br />
    pt0 = p0;<br />
    for (int j = 0; j &#60; hSegments+1; ++j) {</p>
<p>        pt1.x = p0.x + j*dx;<br />
        pt1.y = ymid + ampl * cosf(da*j);</p>
<p>        fullHillPoints[fullHillPointsCount++] = pt1;</p>
<p>        pt0 = pt1;<br />
    }        </p>
<p>}</p>
<p>b2Vec2 p1v, p2v;<br />
for (int i=0; i&#60;fullHillPointsCount-1; i++) {<br />
    p1v = b2Vec2(fullHillPoints[i].x/PTM_RATIO,fullHillPoints[i].y/PTM_RATIO);<br />
    p2v = b2Vec2(fullHillPoints[i+1].x/PTM_RATIO,fullHillPoints[i+1].y/PTM_RATIO);<br />
    shape.SetAsEdge(p1v, p2v);<br />
    body-&#62;CreateFixture(&#38;shape, 0);<br />
}<br />
}</p>
<p>However when ever the two collide the app crashes. The crash error is:</p>
<p>Thread 6 CVDisplayLink: Program received signal: "SIGABRT"</p>
<p>The error occurs on line 96 of b2ContactSolver.cpp:</p>
<p>b2Assert(kNormal &#62; b2_epsilon);<br />
The error log is:</p>
<p>Assertion failed: (kNormal &#62; 1.19209290e-7F), function b2ContactSolver, file /Users/coooli01/Documents/Xcode Projects/Cocos2d/Hill Slide/Hill Slide/libs/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 96.</p>
<p>Sorry if I rambled on for too long, i've been stuck on this for ages.
</p></description>
		</item>
		<item>
			<title>hamstachasa on "Draw a CGRect (or make visible)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21267#post-118256</link>
			<pubDate>Mon, 26 Sep 2011 22:36:19 +0000</pubDate>
			<dc:creator>hamstachasa</dc:creator>
			<guid isPermaLink="false">118256@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am using CGRectIntersectsRect to detect collisions in my game. It is a scrolling game, and I can't get my bounding box to match up with where it is supposed to be. What i am looking for is a way to make these CGRects (bounding boxes) visible. I tried doing the following: </p>
<pre><code>-(void) drawBoundingBox: (CGRect) rect;
{
    CGPoint vertices[4]={
        ccp(rect.origin.x,rect.origin.y),
        ccp(rect.origin.x+rect.size.width,rect.origin.y),
        ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height),
        ccp(rect.origin.x,rect.origin.y+rect.size.height),
    };
    ccDrawPoly(vertices, 4, YES);
}</code></pre>
<p>But it isn't showing up. What am I doing wrong? Cheers!
</p></description>
		</item>
		<item>
			<title>Tadegol on "Remove cpShape after collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22461#post-124656</link>
			<pubDate>Sat, 05 Nov 2011 22:52:46 +0000</pubDate>
			<dc:creator>Tadegol</dc:creator>
			<guid isPermaLink="false">124656@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hello, </p>
<p>Sorry if my topic is on worng section. </p>
<p>I have a very headache with handler collision on chopmunk. i need some help please.<br />
My problem:</p>
<p>i'm trying to remove(clear, disappear, delete or something like that) some shape after his collision. </p>
<p>Code:</p>
<p>- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event<br />
{</p>
<p>    UITouch *touch = [touches anyObject];<br />
    CGPoint location= [touch locationInView:[touch view]];<br />
    location = [[CCDirector sharedDirector] convertToGL:location];</p>
<p>    cpShape *ballShape = [sm addCircleAt:ccp(100, 200) mass:5 radius:25];<br />
    cpCCSprite *flake= [cpCCSprite spriteWithShape:ballShape file:@"ballon.png"];<br />
    flake.position = ccp(location.x, location.y);</p>
<p>    id animation = [CCMoveTo actionWithDuration:2 position:ccp(flakeImage.position.x-20, flakeImage.position.y-200)];</p>
<p>    [flake runAction:animation];</p>
<p>    flake.shape-&#62;collision_type=1;<br />
    flower.shape-&#62;collision_type=2;<br />
    [self addChild:flake];</p>
<p>    [sm addCollisionCallbackBetweenType:1 otherType:2 target:self selector:@selector(handleCollision:arbiter:space:)];</p>
<p>}</p>
<p>This method works fine,draw a shape that is falling and making a collapse to other one .</p>
<p>- (void) handleCollision:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space<br />
{<br />
    CP_ARBITER_GET_SHAPES(arb,a,b);<br />
    switch(moment)<br />
    {<br />
        case COLLISION_BEGIN:<br />
            //do something at the beginning<br />
            NSLog(@"Has been collision");<br />
            //Remove shape<br />
             [sm removeAndFreeShape:a];<br />
            break;<br />
    }</p>
<p>}<br />
Here is the problem,  NSLog(@"Has been collision"); works fine, but  when execute [sm removeAndFreeShape:a]; i have "EXC_BAD_ACCESS".</p>
<p>Please, any suggestion or solution to solve this ?</p>
<p>Thanks.
</p></description>
		</item>
		<item>
			<title>MarkHilton on "Smooth Collisions"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22535#post-125099</link>
			<pubDate>Tue, 08 Nov 2011 19:28:44 +0000</pubDate>
			<dc:creator>MarkHilton</dc:creator>
			<guid isPermaLink="false">125099@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi Guys,</p>
<p>I'm new to game dev so I'm sure this is most likely easier than I think.</p>
<p>Background:</p>
<p>Not using any physics engine. just cocos2d</p>
<p>2 sprites collide with each other (rounded sprite) one moving, the other static. I have that part of the collision working fine, I know the rotation of the sprites and radius.  I have a Joystick handling movement of one sprite.</p>
<p>Problem:<br />
How would I go about making it so if the user continues to apply a direction to the moving sprite it can only move around the circumference of the static sprite. Other than rotating the sprite away from it</p>
<p>Any help would be great,<br />
Mark
</p></description>
		</item>
		<item>
			<title>kosa_nostra on "Realistic collisions with blocks"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22444#post-124566</link>
			<pubDate>Sat, 05 Nov 2011 00:34:19 +0000</pubDate>
			<dc:creator>kosa_nostra</dc:creator>
			<guid isPermaLink="false">124566@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi,<br />
I'm working on a little game involving physics. I use chipmunk. I created a cpBody and a cpShape attached to a CCSprite. This represents a "block" (a long rectangle). When a collision occurs between this block or some other objects, the block moves just linearly. For example, when the top of the block is hit, I'd like to see the block rotate, and not just move as if it has been hit to its center.</p>
<p>Any help would be great !</p>
<p>Regards,<br />
Kosa
</p></description>
		</item>
		<item>
			<title>gcc on "Box2D collision issue"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22161#post-123074</link>
			<pubDate>Wed, 26 Oct 2011 10:30:41 +0000</pubDate>
			<dc:creator>gcc</dc:creator>
			<guid isPermaLink="false">123074@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello!</p>
<p>First of all, this is my very very first Box2D project, so sorry if my questions are noob questions :) Thanks!</p>
<p>I need a little help to resolve my problem with Box2D and collision. I made a circle shape (dynamic body) and I added 12 little circle shape with weld joint on the edge of the big circle. This is the "wheel". I also added a box shape (a rectangle, dynamic body) as a "sticker" on the right side of the composition. This would be something like a trap door. The both of these are joined (RevoluteJoint) to the ground to fix the position of them. So, if I rotate the wheel with touch and SetTransform() then the collision doesn't work properly. If I rotate the wheel with SetAngularVelocity() then the collision is perfect. The gravity is zero. I made a sandbox from a basic cocos2d template. What's the problem?</p>
<p>The other problem is that when I not include after the SetTransform() call the SetAngularVelocity(0.0001f) call then only the joint lines are moving/rotating or I don't know they are doing...</p>
<p>I would like to create a fortune wheel: Something like this: <a href="http://www.wkbingo.com/photo_08/fortune_wheel.jpg">Fortune Wheel</a></p>
<p>Here's the problem:<br />
<img src="http://f.cl.ly/items/2x143M3U2I461G3F2s0v/collisionProblem.jpg" /></p>
<p>I think the best is that you can download the sample I made: <a href="http://cl.ly/1V1E0H410z022q2k441F" rel="nofollow">http://cl.ly/1V1E0H410z022q2k441F</a></p>
<p>Thanks for your time!
</p></description>
		</item>
		<item>
			<title>firephysics on "bulletBodyDef"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/22010#post-122341</link>
			<pubDate>Fri, 21 Oct 2011 02:11:29 +0000</pubDate>
			<dc:creator>firephysics</dc:creator>
			<guid isPermaLink="false">122341@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I am having a problem with tunneling. I think that I am setting up the body definition right for the bullet body. But I am still experiencing alot of tunneling. Here is the code I am using to set up the body.</p>
<p>        b2BodyDef bulletBodyDef;<br />
	bulletBodyDef.type = b2_dynamicBody;<br />
	bulletBodyDef.position.Set(place.position.x/32,place.position.y/32);<br />
	bulletBodyDef.userData = sprite;<br />
	_body = _world-&#62;CreateBody(&#38;bulletBodyDef);	</p>
<p>	b2CircleShape circle;<br />
	circle.m_radius = 5/32;</p>
<p>	b2FixtureDef ballShapeDef;<br />
	ballShapeDef.shape = &#38;circle;<br />
	ballShapeDef.density = .1f;<br />
	ballShapeDef.friction = .2f;<br />
	ballShapeDef.restitution = .2f;<br />
	_body-&#62;CreateFixture(&#38;ballShapeDef);</p>
<p>Reading the box2d manual it says that if you want to set something as a bullet do "bodyDef.bullet = true;" this way it turns on CCD, When I do this though, it doesn't compile. Any ideas?
</p></description>
		</item>
		<item>
			<title>Theronen on "Application crashes whenever any type of chipmunk collision occurs."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21915#post-121794</link>
			<pubDate>Tue, 18 Oct 2011 01:51:12 +0000</pubDate>
			<dc:creator>Theronen</dc:creator>
			<guid isPermaLink="false">121794@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Chipmunk has recently developed an issue where it crashes on any collision. As far as I can tell this only applies to newly created projects. I have identical code running perfectly fine in previous applications, but in any newly created project the application crashes. When a collision occurs I get the error in this block of code in the cpCollision.c file:<br />
<pre><code>int
cpCollideShapes(const cpShape *a, const cpShape *b, cpContact *arr)
{
	// Their shape types must be in order.
	cpAssert(a-&#62;klass-&#62;type &#60;= b-&#62;klass-&#62;type, &#34;Collision shapes passed to cpCollideShapes() are not sorted.&#34;);

	collisionFunc cfunc = colfuncs[a-&#62;klass-&#62;type + b-&#62;klass-&#62;type*CP_NUM_SHAPES];
	return (cfunc) ? cfunc(a, b, arr) : 0;
}</code></pre>
<p>The "EXC_BAD_ACCESS" error is occurring on the seventh line, otherwise seen as:<br />
<pre><code>collisionFunc cfunc = colfuncs[a-&#62;klass-&#62;type + b-&#62;klass-&#62;type*CP_NUM_SHAPES];</code></pre>
<p>This crash occurs between static and dynamic bodies alike, circles or polygons, no exceptions. This issue is still present in an application as simple as:<br />
<pre><code>#<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;GameLayer.h&#34;

@implementation GameLayer

+ (CCScene *) scene
{
	CCScene *gameScene = [CCScene node];
    GameLayer *gameLayer = [GameLayer node];
    [gameScene addChild: gameLayer];
    return gameScene;
}

- (void)createSpace
{
    space = cpSpaceNew();
    space-&#62;gravity = ccp(0, -100);
}

- (id) init
{
	if( (self=[super init]))
    {
        [self createSpace];

        cpBody *body2 = cpBodyNew(1.0, 1.0);
        body2-&#62;p = ccp(240, 200);
        cpSpaceAddBody(space, body2);

        cpShape *shape2 = cpCircleShapeNew(body2, 50,  CGPointZero);
        cpSpaceAddShape(space, shape2);        

        cpBody *body1 = cpBodyNew(1.0, 1.0);
        body1-&#62;p = ccp(240, 0);
        cpSpaceAddBody(space, body1);

        cpShape *shape1 = cpCircleShapeNew(body1, 50,  CGPointZero);
        cpSpaceAddShape(space, shape1);
        cpBodyApplyForce(body1, ccp(0, 100), CGPointZero);

        [self scheduleUpdate];
	}
	return self;
}

- (void)update:(ccTime)dt
{
    cpSpaceStep(space, dt);
}

- (void) dealloc
{
	cpSpaceFree(space);
	space = NULL;
    [super dealloc];
}

@end</code></pre>
<p>Any assistance would be extremely appreciated.
</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>Theronen on "Box2D Custom Polygon Collision"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21732#post-120767</link>
			<pubDate>Wed, 12 Oct 2011 01:56:52 +0000</pubDate>
			<dc:creator>Theronen</dc:creator>
			<guid isPermaLink="false">120767@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>For my current project I need to create a custom box2D polygon, however, I am running into issues. The primary issue is that the body won't collide, at the moment it acts exactly like a sprite. Here is a screenshot of what the body looks like, it has 8 vertices defined with the top right point first going counter-clockwise. I have tried rearranging the points to no avail.</p>
<p><img src="http://img831.imageshack.us/img831/5743/box2dcustompolygon.png" alt="" /></p>
<p>And here is the code to create the main polygon:<br />
<pre><code>b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position = b2Vec2(100/PTM_RATIO, 100/PTM_RATIO);
    body = world-&#62;CreateBody(&#38;bodyDef);

    b2FixtureDef fixtureDef;
    b2PolygonShape shape;

    int num = 8;
    b2Vec2 verts[] =
    {
        b2Vec2(33.0f / PTM_RATIO, 77.0f / PTM_RATIO),
        b2Vec2(-13.0f / PTM_RATIO, 77.0f / PTM_RATIO),
        b2Vec2(-18.0f / PTM_RATIO, 43.0f / PTM_RATIO),
        b2Vec2(-94.0f / PTM_RATIO, 20.5f / PTM_RATIO),
        b2Vec2(-94.0f / PTM_RATIO, -9.2f / PTM_RATIO),
        b2Vec2(121.0f / PTM_RATIO, -9.2f / PTM_RATIO),
        b2Vec2(121.0f / PTM_RATIO, 8.0f / PTM_RATIO),
        b2Vec2(50.2f / PTM_RATIO, 8.0f / PTM_RATIO)
    };

    shape.Set(verts, num);
    fixtureDef.shape = &#38;shape;

    fixtureDef.density = 1.0;
    fixtureDef.friction = 5.0;
    fixtureDef.restitution = 0.5;

    body-&#62;CreateFixture(&#38;fixtureDef);</code></pre>
<p>Thanks in advance for any help.
</p></description>
		</item>
		<item>
			<title>zKarp on "Rotate World (b2World)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21481#post-119366</link>
			<pubDate>Mon, 03 Oct 2011 15:47:39 +0000</pubDate>
			<dc:creator>zKarp</dc:creator>
			<guid isPermaLink="false">119366@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is there a way to rotate the World while moving everything inside of in-respect to the world. (So basically like you are turning your iPhone but without actually turning it). I would like to have a control of turning the world with buttons. I currently have it change gravity +-Angle then find xVector and yVector with constant 9.81 resultant. I currently am use a Tilemap for the "world" with 1 layer being the design/scene while other is collision layer. Need them to stay constant distance and in the "right space"</p>
<p>I tried rotation of the TileMap and collision layers however the collision layers get screwed up and Tilemap rotates on 0,0 (where it was anchored).</p>
<p>Any ideas or better approaches would be great. I've been googling and researching all over, nothing concrete yet.
</p></description>
		</item>
		<item>
			<title>h202 on "Collsion optimization  question"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/21537#post-119639</link>
			<pubDate>Wed, 05 Oct 2011 03:57:42 +0000</pubDate>
			<dc:creator>h202</dc:creator>
			<guid isPermaLink="false">119639@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have around 100 sprite objects for which I'm checking collision against a laser object like</p>
<p>for(int i=1; i&#60;=100; i++)<br />
{<br />
if CGRectIntersectsRect (laser.boundingBox, obj[i].boundingBox);<br />
      {<br />
             //some stuff here<br />
      }</p>
<p>}</p>
<p>My game design is like this that at a given time only three or four objects are present on the screen. </p>
<p>The whole game loop goes like this</p>
<p>1. Obj[1] is created and moved outside the screen bounds then it disappears.<br />
2. Obj[2] is created and the above step is repeated</p>
<p>in short  One by One objects are created and then moved outside the screen before I release them.</p>
<p>One drawback I see with this approach is that I'm taking an extra overhead in checking the 100 sprite collisons for only 2-3  objects that are  actually present on screen.</p>
<p>Is there any approach that i can use to limit this overhead at run time
</p></description>
		</item>

	</channel>
</rss>

