<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.2" -->
<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; Topic: One last time for collision...</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/31610</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Sat, 25 May 2013 06:18:03 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.2</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/topic/31610" rel="self" type="application/rss+xml" />

		<item>
			<title>clarus on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156594</link>
			<pubDate>Tue, 01 May 2012 06:29:44 +0000</pubDate>
			<dc:creator>clarus</dc:creator>
			<guid isPermaLink="false">156594@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The body is probably nil or invalid when you're making that SetTransform call. Are you sure you're setting the body correctly in the sprite when you create both it and the body?</p>
<p>Have you tried looking at the physics editor sample code to see how that sets things up? It might be easiest to work from that example, since you want to use PE anyway.
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156589</link>
			<pubDate>Tue, 01 May 2012 06:04:03 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">156589@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Ooohhh I really hate this.</p>
<p>So, I was thinking the right way to do this is to subclass CCSprite. Something like:<br />
<pre><code>JSprite
{
   b2Body *body;
} 

// Move the body when the sprite moves
-(void)setPosition:(CGPoint)position
{
   [super setPosition:position];
   body-&#62;SetTransform((b2Vec2(position.x/PTM_RATIO, position.y/PTM_RATIO)), 0);
}
// Do the same for rotation, anchor, etc...</code></pre>
<p>However, I'm getting an EXC_BAD_ACCESS error when it tries to set the transform. Maybe the world isn't initialized. Can anyone give me a rundown of the proper way to structure this for collision detection? I was going to use PhysicsEditor to define a body for each frame, and then use that with the sprites, but honestly this whole thing has been more trouble than its worth. Are there any engines or tools out there that offer better support for frame-specific hitboxes?
</p></description>
		</item>
		<item>
			<title>jyoung on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156176</link>
			<pubDate>Sat, 28 Apr 2012 21:41:32 +0000</pubDate>
			<dc:creator>jyoung</dc:creator>
			<guid isPermaLink="false">156176@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>It's a memory leak unless you call<br />
<pre><code>delete [] vertices;</code></pre>
<p>when you're done using it.
</p></description>
		</item>
		<item>
			<title>Nishith Sheth on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156072</link>
			<pubDate>Sat, 28 Apr 2012 04:34:29 +0000</pubDate>
			<dc:creator>Nishith Sheth</dc:creator>
			<guid isPermaLink="false">156072@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Move your Box2D files to libs folder which should be in your app folder  where all your cocos2D filles are located.then in build settings mention that libs folder in Search paths /Header Search paths .
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156070</link>
			<pubDate>Sat, 28 Apr 2012 03:41:21 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">156070@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Ah. And now all of a sudden, I get this error in GLES-Render.mm:</p>
<p>variable length array of non-pod element type 'b2vec2'</p>
<p>What's the proper way to fix this? It occurs on the line:<br />
<code>b2Vec2 vertices[vertexCount];</code></p>
<p>I can fix it by replacing it with:<br />
<code>b2Vec2 *vertices = new b2Vec2[vertexCount];</code></p>
<p>My C++ is rusty. am I creating a memory leak with this? Should I have resolved this another way?
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156067</link>
			<pubDate>Sat, 28 Apr 2012 03:09:05 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">156067@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Awesome. Got it. There was some old unused test class referencing the class I was using box2d in, and I also had to add the box2d library under Build Phases-&#62;Link Binary With Libraries. Thanks for the help guys.
</p></description>
		</item>
		<item>
			<title>clarus on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156057</link>
			<pubDate>Fri, 27 Apr 2012 21:14:10 +0000</pubDate>
			<dc:creator>clarus</dc:creator>
			<guid isPermaLink="false">156057@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>If any of your .m files include any headers (or include any headers that include any other headers) that use C++, you need to make those .mm files so that they compile with the Objective C++ compiler. So, other way around from what you were saying about box2d including headers. There's no disadvantage I'm aware of to using .mm for all.</p>
<p>If you use the standard C++ library, you need to link with it, but I guess the C++ compiler does that automatically, so ignore that comment for now.
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156050</link>
			<pubDate>Fri, 27 Apr 2012 20:02:16 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">156050@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I was only selectively making .m files into .mm, in this case the HelloWorldLayer.mm. What is the rule for converting these .mm files? Is it if the file including box2d includes another class, I have to make that class .mm as well, or is it the other way around (other classes including HelloWorldLayer must be .mm)? Is there any disadvantage to using .mm files at all?</p>
<p>Also, how would I include the c++ dylib? I haven't seen mention of that anywhere.
</p></description>
		</item>
		<item>
			<title>clarus on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156019</link>
			<pubDate>Fri, 27 Apr 2012 16:02:06 +0000</pubDate>
			<dc:creator>clarus</dc:creator>
			<guid isPermaLink="false">156019@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Well, that indicates that the standard C++ headers aren't being found (assuming you're including things like &#60;cassert&#62; where you're referencing them). I'd expect that to be because you've included a header from a .m instead of a .mm. Are all of your files .mm now? If not, do any of the .m files include a header (or another header, and so on) that includes a box2d or other c++ header? If so, that's the issue.</p>
<p>Also, you haven't gotten there yet, but you'll want to make sure you link with the standard C++ dylib.
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-156003</link>
			<pubDate>Fri, 27 Apr 2012 14:48:35 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">156003@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Any ideas?
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155923</link>
			<pubDate>Fri, 27 Apr 2012 03:21:39 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">155923@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Here's how my project is set up:<br />
<a href="http://sleekmedia.com/Misc/config2.png" rel="nofollow">http://sleekmedia.com/Misc/config2.png</a></p>
<p>Basically, I dropped cocos2D into my project as a separate target so that I could use ARC in my game's source code (converted using the Edit-&#62;Refactor-&#62;Convert To Arc menu option). I used this tutorial: <a href="http://www.tinytimgames.com/2011/07/22/cocos2d-and-arc/" rel="nofollow">http://www.tinytimgames.com/2011/07/22/cocos2d-and-arc/</a></p>
<p>However, if I try to actually include box2d into say, the HelloWorldLayer.mm, I get errors in b2Settings.h:<br />
Lexical or Preprocessor Issue<br />
'cassert' file not found</p>
<p>Can anyone please instruct me on how to get box2d working in a project like this? I'm willing to give physics collision a go, since I can think of other enhancements to my game I could use it for, but I can't do anything if I can't get the library working in the first place. Is there a static version of this library I could just add to Build Phases-&#62;Link Library With Binaries?</p>
<p>Thanks.
</p></description>
		</item>
		<item>
			<title>jyoung on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155364</link>
			<pubDate>Tue, 24 Apr 2012 23:34:59 +0000</pubDate>
			<dc:creator>jyoung</dc:creator>
			<guid isPermaLink="false">155364@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>You say you don't need physics, but I would still use an engine to handle collisions for you as opposed to writing your own code. You'll save a lot of time.</p>
<p>Check out PhysicsEditor or SpriteHelper. They let you define polygon collision shapes in a GUI and export them to plists that you can read into your physics world. These shapes are very easily rotated in the physics world and synced up with graphics.</p>
<p>Re: scaling, I think there is a branch of box2d that supports it. If not, it'd be pretty easy to scale all the vertex coordinates relative to some center point and re-create the collision shape if needed.</p>
<p>What kind of compilation errors are you getting? Every place you use box2d needs to be in .mm since box2d is c++.
</p></description>
		</item>
		<item>
			<title>whitewidget on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155273</link>
			<pubDate>Tue, 24 Apr 2012 15:22:54 +0000</pubDate>
			<dc:creator>whitewidget</dc:creator>
			<guid isPermaLink="false">155273@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>A Box2D Body is declared separate from a Sprite so it doesn't really know what you do to the Sprite unless you inform it. AFAIK, if it's not something within scope of CCSprite, then it won't get automatically affected by what you do with it, so unless you use the Sprite's rectangle for collision checking, don't expect any bounding shapes that you make to automatically follow the Sprite's properties.</p>
<p>If you scale a sprite, you'd have to destroy your shape and redefine it to the new size by applying the same scale modifier values as you did to your sprite to define the new shape. If you rotate a sprite, then you have to translate the body to have the same rotation (you will be constantly updating the body position to that of the sprite anyway, so adding the rotation isn't a big deal).</p>
<p>So in a sense it would be the same as you just declaring circles, and moving them and resizing them as the sprite is scaled/rotated. You can place the circle in a certain position relative to the position of the sprite using cos and sin functions on the sprite's rotation, then just have a multiplier for the radius of the circle for when you scale the sprite. If you want this to be automatic, then overload the CCSprite's setRotation and setScale/setScaleX/setScaleY methods to include the transformation to your bounding shapes.</p>
<p>I don't think it's fair to blame this on Cocos2D though...
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155264</link>
			<pubDate>Tue, 24 Apr 2012 14:45:17 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">155264@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks for all the responses. </p>
<p>PDog, that is how you would check for collisions in a basic fashion, and it's the efficient solution I'm going for (I would recommend adding flags so that you can prevent checking for enemy vs enemy collisions, etc). Actually comparing circles for collision is the easy part. The challenge is how to define those collision circles/boxes. What if you have a sprite that has an irregular shape? You may want to use several circles. Not a problem in terms of checking for collision, but how do you set it? In code? That would be a huge pain if you have lots and lots of sprites. You'd also have to draw the collision spheres and rebuild every time you wanted to visualize changes you made to the collision for each sprite. This seems like it should be a common task, but I can't find a tool for defining collision boxes/circles anywhere.</p>
<p>Pterodactyl, pixel perfect collision is expensive, but more importantly unsuitable for many kinds of games. For example, I use a lot of bird enemies. Their wings shouldn't damage the player - just the main body. Likewise, if the player performs a kick, enemies that hit your back shouldn't be damaged.</p>
<p>IUridium, I tried to implement box2d last night, but I spent hours and couldn't get it to work. It just wouldn't compile for me. My project uses ARC, and I have the cocos2d project as an additional target in order to exclude it from ARC. Any time I tried to add box2d, whether through search user header files, or adding it directly to the project or whatever, I would get compiler errors. If I could actually get box2d to work, I would consider using it for collision even though it seems like overkill. What happens to a physics body if you scale or transform the sprite? Will the body follow suit?</p>
<p>Martin, the collision check itself is dead simple, but defining the circles is the problem. Additionally, you have to consider that the sprite may be transformed. For example, if I have a collision circle that is not in the center of the sprite, and that sprite is rotated/scaled, how can I get a workspace position and orientation for it? Collision bounds should follow the same transformations as the sprite.
</p></description>
		</item>
		<item>
			<title>Martin on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155211</link>
			<pubDate>Tue, 24 Apr 2012 10:57:56 +0000</pubDate>
			<dc:creator>Martin</dc:creator>
			<guid isPermaLink="false">155211@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Comparing two circles for collision is dead simple. Check if the distance of the centeres is smaller than the sum of both circles' radius. You can approximate a lot of shapes with several circles and put one big circle around it to optimize by pretesting the outer "bounding box circle". Rotating also is possible by rotating your circle center points around your object center.
</p></description>
		</item>
		<item>
			<title>iUridium on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155209</link>
			<pubDate>Tue, 24 Apr 2012 10:53:51 +0000</pubDate>
			<dc:creator>iUridium</dc:creator>
			<guid isPermaLink="false">155209@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Why you do not want to use Box2D for collision? It should work perfectly for what you need. Check these tutorials:<br />
- <a href="http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone" rel="nofollow">http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone</a><br />
- <a href="http://www.iuridium.com/?p=548" rel="nofollow">http://www.iuridium.com/?p=548</a>
</p></description>
		</item>
		<item>
			<title>Pteriedaktyl on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155180</link>
			<pubDate>Tue, 24 Apr 2012 08:07:07 +0000</pubDate>
			<dc:creator>Pteriedaktyl</dc:creator>
			<guid isPermaLink="false">155180@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Did you consider "Pixel perfect" collision detection?
</p></description>
		</item>
		<item>
			<title>PDog on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155170</link>
			<pubDate>Tue, 24 Apr 2012 07:01:02 +0000</pubDate>
			<dc:creator>PDog</dc:creator>
			<guid isPermaLink="false">155170@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Perhaps something like this: <a href="http://www.71squared.com/2010/03/collision-detection-methods/" rel="nofollow">http://www.71squared.com/2010/03/collision-detection-methods/</a> may help?</p>
<p>Unfortunately, there doesn't really seem to be a way to efficiently create a bounding circle without using a series of rectangles.
</p></description>
		</item>
		<item>
			<title>GoldenJoe on "One last time for collision..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/31610#post-155167</link>
			<pubDate>Tue, 24 Apr 2012 06:38:01 +0000</pubDate>
			<dc:creator>GoldenJoe</dc:creator>
			<guid isPermaLink="false">155167@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Okay. I have a "runner" type game. Sometimes enemies appear to attack the player. Bound rects are inaccurate because my enemies aren't boxes, and they get screwed up by rotation actions anyway. I don't need any physics in my game. Is there ANYTHING AT ALL out there that I can use to define hitboxes and hurtboxes, preferably with circles, and use that data to check for collisions in my game? I so completely frustrated with cocos2d at this point, I'm ready to look at porting what I have over to Unity. I cannot stand to waste another entire day trying to get this library to configure properly with ARC and box2d (which I shouldn't even need to use for simple collision).
</p></description>
		</item>

	</channel>
</rss>
