<?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; Topic: Chipmunk with cocos2d sprite and its body offset</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/2162</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 01:38:11 +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/topic/2162" rel="self" type="application/rss+xml" />

		<item>
			<title>jer on "Chipmunk with cocos2d sprite and its body offset"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2162#post-14003</link>
			<pubDate>Thu, 01 Oct 2009 20:26:57 +0000</pubDate>
			<dc:creator>jer</dc:creator>
			<guid isPermaLink="false">14003@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Yes, it has the same results, only a much bigger size of the shape/body
</p></description>
		</item>
		<item>
			<title>Mark Sawicki on "Chipmunk with cocos2d sprite and its body offset"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2162#post-13989</link>
			<pubDate>Thu, 01 Oct 2009 16:47:56 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">13989@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Have you tried to get this to work without scaling the sprite first?
</p></description>
		</item>
		<item>
			<title>jer on "Chipmunk with cocos2d sprite and its body offset"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2162#post-13983</link>
			<pubDate>Thu, 01 Oct 2009 16:24:41 +0000</pubDate>
			<dc:creator>jer</dc:creator>
			<guid isPermaLink="false">13983@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Nobody have any ideas on this?
</p></description>
		</item>
		<item>
			<title>jer on "Chipmunk with cocos2d sprite and its body offset"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2162#post-13575</link>
			<pubDate>Mon, 28 Sep 2009 04:04:05 +0000</pubDate>
			<dc:creator>jer</dc:creator>
			<guid isPermaLink="false">13575@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I have a sprite, a square which has a body, also a square. The body isn't lining up with the sprite even though the positions are the same and I'm not overriding setPosition:.</p>
<p>Basically, if the position on screen is x=100,y=100 with a size of the sprite 48x48, the body is lining up at x=124,y=76 with a size of 48x48. So the centre of the body is on the upper right hand corner of the sprite. Code i'm using to create the sprite &#38; body is below:</p>
<pre><code>- (void)createBlock:(Block*)block withAssets:(NSBundle*)assets
{
	BlockSprite* sprite;
	int x = block.bounds.origin.x;
	int y = block.bounds.origin.y;
	NSMutableString* c = [[NSMutableString alloc] init];

	switch(block.blockColour)
	{
		case kBlockColourGreen:
			[c setString:@&#34;green&#34;];
			break;
		case kBlockColourOrange:
			[c setString:@&#34;orange&#34;];
			break;
		case kBlockColourRed:
			[c setString:@&#34;red&#34;];
			break;
		case kBlockColourBlue:
			[c setString:@&#34;blue&#34;];
			break;
	}
	sprite = [BlockSprite spriteWithFile:[assets pathForResource:c ofType:@&#34;png&#34; inDirectory:@&#34;Blocks&#34;]];
	[c release];
	sprite.position = ccp(x, y);
	sprite.scaleY = 0.75f;
	sprite.scaleX = 0.75f;
	[self addChild:sprite];

	float halfWidth = block.bounds.size.width / 2;
	float halfHeight = block.bounds.size.height / 2;
	cpVect verts[] = {
		cpv(-halfWidth, -halfHeight),
		cpv(-halfWidth, halfHeight),
		cpv(halfWidth, halfHeight),
		cpv(halfWidth, -halfHeight)
	};

	cpBody* blockBody;
	if(block.blockColour == kBlockColourOrange &#124;&#124; block.blockColour == kBlockColourBlue &#124;&#124; [block.gravitySpeed intValue] == 0)
	{
		blockBody = cpBodyNew(INFINITY, cpMomentForPoly(INFINITY, 4, verts, cpvzero));
	}
	else
	{
		blockBody = cpBodyNew([block.mass floatValue], cpMomentForPoly([block.mass floatValue], 4, verts, cpvzero));
	}
	blockBody-&#62;p = cpv(block.bounds.origin.x, block.bounds.origin.y);
	blockBody-&#62;v = cpvzero;
	if((block.blockColour == kBlockColourGreen &#124;&#124; block.blockColour == kBlockColourRed) &#38;&#38; [block.gravitySpeed intValue] != 0)
		cpSpaceAddBody(space, blockBody);

	cpShape* blockShape = cpPolyShapeNew(blockBody, 4, verts, cpvzero);
	blockShape-&#62;e = 0.9f;
	blockShape-&#62;u = 0.9f;
	blockShape-&#62;collision_type = 1;
	sprite.scaleX = 1.0f;
	sprite.scaleY = 1.0f;
	blockShape-&#62;data = sprite;

	if(block.blockColour == kBlockColourOrange &#124;&#124; block.blockColour == kBlockColourBlue &#124;&#124; [block.gravitySpeed intValue] == 0)
	{
		blockBody-&#62;v = cpvzero;
		// Static object&#39;s victory is always YES.
		sprite.victory = YES;
		cpSpaceAddStaticShape(space, blockShape);
	}
	else
		cpSpaceAddShape(space, blockShape);

	sprite.scaleX = 0.75f;
	sprite.scaleY = 0.75f;
	sprite.space = space;
	sprite.shape = blockShape;
	[blockSprites addObject:sprite];
}</code></pre></description>
		</item>

	</channel>
</rss>

