<?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; User Favorites: xyriskenn</title>
		<link>http://www.cocos2d-iphone.org/forum/profile/2541</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 02:49:23 +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/profile/2541" rel="self" type="application/rss+xml" />

		<item>
			<title>vennt on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15950</link>
			<pubDate>Mon, 19 Oct 2009 22:35:44 +0000</pubDate>
			<dc:creator>vennt</dc:creator>
			<guid isPermaLink="false">15950@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/133'>Mark</a></p>
<p>Thanks a bunch! Everything seems to be working.</p>
<p>I ended up modifying my init method to take the space.</p>
<pre><code>initWithCPSpace:(cpSpace*)space</code></pre>
<p>So now I'm doing this</p>
<pre><code>[self initChipmunk];

MySprite *icon = [[MySprite node] initWithCPSpace:space];
[self addChild:icon];</code></pre>
<p>Although I'm not sure if thats best practice, I think your second method sounds a bit better.
</p></description>
		</item>
		<item>
			<title>Mark Sawicki on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15917</link>
			<pubDate>Mon, 19 Oct 2009 16:47:14 +0000</pubDate>
			<dc:creator>Mark Sawicki</dc:creator>
			<guid isPermaLink="false">15917@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/2686'>vennt</a>,</p>
<p>Maybe you could either pass in the chipmunk space to your MySprite init , or don't try to add the shape and body to the space in the init of your object, but instead do it in your MainScene code, like:<br />
<pre><code>MySprite *icon = [MySprite node];
		cpSpaceAddBody(space, [icon body]);
		cpSpaceAddShape(space, [icon shape]);
		[self addChild:icon];</code></pre></description>
		</item>
		<item>
			<title>vennt on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15879</link>
			<pubDate>Mon, 19 Oct 2009 07:02:46 +0000</pubDate>
			<dc:creator>vennt</dc:creator>
			<guid isPermaLink="false">15879@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/2541'>XyrisKenn</a> thanks for the examples - I'm probably not really understanding it due to it being Box2d though, if I can't get this working maybe I'll start using Box2d...</p>
<p>@<a href='http://www.cocos2d-iphone.org/forum/profile/51'>jd</a> thanks for the tip, putting the cpSpace *space in the MyBox.h file gets rid of my build error. but now the simulator is crashing once the cocos2d splash screen appears.</p>
<p>FWIW, I've got the code successfully running if I put everything in one continuous block, but kind of defeats the purpose here ;)
</p></description>
		</item>
		<item>
			<title>jd on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15815</link>
			<pubDate>Sun, 18 Oct 2009 14:36:49 +0000</pubDate>
			<dc:creator>jd</dc:creator>
			<guid isPermaLink="false">15815@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/2686'>vennt</a> put cpSpace *space; in your .h file.
</p></description>
		</item>
		<item>
			<title>XyrisKenn on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15806</link>
			<pubDate>Sun, 18 Oct 2009 13:20:31 +0000</pubDate>
			<dc:creator>XyrisKenn</dc:creator>
			<guid isPermaLink="false">15806@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm up against the same issue but with Box2D. This is what I've found but don't completely understand yet.<br />
I think it's just a basic Obj-C/C++ technique of integrating class files with the main game implementation, but I come from actionscripting which is different.</p>
<p>The solution seems to do with making the main game scene accessible to the class files and calling the 'world' through a nested function. </p>
<p>Looking at Luke's example UIKit app at <a href="http://blog.zincroe.com/2009/05/iphone-and-box2d/" rel="nofollow">http://blog.zincroe.com/2009/05/iphone-and-box2d/</a> he builds classes for 'Ball' and 'Obstacle', but connects to the main class through an Actor class. I looked for a key Box2D function in 'Ball.m' and found: </p>
<p><code>[self setBody:[[self game] world]-&#62;CreateBody([self bodyDef])];</code></p>
<p>'game' is defined in the 'Actor' class files:</p>
<pre><code>Actor.h: 	MyGameViewController *game;
Actor.m: @synthesize game;</code></pre>
<p>...and his main scene is defined as a class:</p>
<p><code>@class MyGameViewController;  // which is where the main game logic is.</code></p>
<p>Ball class is called in the main game scene (MyGameViewController) as:</p>
<pre><code>MyGameViewController.h: @class Actor;
MyGameViewController.m: #<a href='http://www.cocos2d-iphone.org/forum/tags/import'>import</a> &#34;Actor.h&#34;</code></pre>
<p>...then in a function as<br />
<code>Ball *aBall = [[[Ball alloc] init] autorelease];</code></p>
<p>...so it seems 'Ball' and 'Obstacle' (Actor) classes in his example can access the physic's Box2D world.<br />
I'm sorting through Luke's work and not my own, I suggest asking him.
</p></description>
		</item>
		<item>
			<title>vennt on "Newb: How to separate files/classes (chipmunk)"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2530#post-15803</link>
			<pubDate>Sun, 18 Oct 2009 10:48:32 +0000</pubDate>
			<dc:creator>vennt</dc:creator>
			<guid isPermaLink="false">15803@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm learning Cocos and Chipmunk mostly through examples. Now trying to branch out a little bit. But I'm stuck.</p>
<p>Not sure if I'm even doing this correctly - but I've got 1 scene that I'm trying to initialize chipmunk:</p>
<pre><code>TestScene.m

-(void) initChipmunk
{
	// Start chipmunk
	cpInitChipmunk();
	space = cpSpaceNew();
	space-&#62;gravity = cpv(0, -100);
}</code></pre>
<p>I've got another class with my sprite that I'm trying to add to this scene with chipmunk</p>
<pre><code>MyBox.m

-(id) init
{
	if((self = [super init]))
	{
		Sprite *mySprite = [Sprite spriteWithFile:@&#34;Icon.png&#34;];
		CGSize s = [[Director sharedDirector] winSize];
		mySprite.position = ccp(s.width /2, s.height/2);
		[self addChild:mySprite z:0];

		body = cpBodyNew(100.0, INFINITY);
		body-&#62;p = cpv(s.width /2, s.height/2);
		cpSpaceAddBody(space, body);

		shape = cpCircleShapeNew(body, 20.0, cpvzero);
		shape-&#62;e = 0.5; // Elasticity
		shape-&#62;u = 0.8; // Friction
		shape-&#62;data = mySprite;
		shape-&#62;collision_type = 1;
		cpSpaceAddShape(space, shape);
	}
	return self;
}</code></pre>
<p>My issue is I do not know how to call these files from my TestScene.m init: Right now I'm doing something like this.</p>
<pre><code>TestScene.m

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

		MySprite *icon = [MySprite node];
		[self addChild:icon];

		[self schedule: @selector(step:)];
	}
	return self;
}</code></pre>
<p>I'm getting a build error in MyBox.m "error: 'space' undeclared (first use in function)"</p>
<p>I guess my chipmunk space is not present in the file, because its initialized in my scene file.</p>
<p>I'm not really sure if I'm going about this correctly, every demo/tutorial I've done has always added the chipmunk initialization, body creation, shape creation in one long  block, I was looking to sorta compartmentalize some of that...
</p></description>
		</item>

	</channel>
</rss>

