<?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: traversing a curved path</title>
		<link>http://www.cocos2d-iphone.org/forum/topic/272</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:26:22 +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/272" rel="self" type="application/rss+xml" />

		<item>
			<title>Acceleroto on "traversing a curved path"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/272#post-1560</link>
			<pubDate>Wed, 24 Jun 2009 16:37:30 +0000</pubDate>
			<dc:creator>Acceleroto</dc:creator>
			<guid isPermaLink="false">1560@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Allen- this looks great.  I didn't know 0.8 had a bezier path either (I'm just starting to use 0.8 today).  I'm curious to see how it works.</p>
<p>-Bryan
</p></description>
		</item>
		<item>
			<title>allenfjordan on "traversing a curved path"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/272#post-1558</link>
			<pubDate>Wed, 24 Jun 2009 16:35:10 +0000</pubDate>
			<dc:creator>allenfjordan</dc:creator>
			<guid isPermaLink="false">1558@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Oh sweet.  I didn't realize that had been added in (I'm using 0.7.3).  Thanks for the tip... I'll try it out later.
</p></description>
		</item>
		<item>
			<title>jd on "traversing a curved path"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/272#post-1453</link>
			<pubDate>Wed, 24 Jun 2009 06:40:37 +0000</pubDate>
			<dc:creator>jd</dc:creator>
			<guid isPermaLink="false">1453@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>0.8 has bezier path.  See SpritesTest.m.
</p></description>
		</item>
		<item>
			<title>allenfjordan on "traversing a curved path"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/272#post-1447</link>
			<pubDate>Wed, 24 Jun 2009 05:52:08 +0000</pubDate>
			<dc:creator>allenfjordan</dc:creator>
			<guid isPermaLink="false">1447@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've been playing around with the idea of sprites following pre-defined paths.  I really just want the ability to move along arbitrary curves... I seem to remember there being a spline or bezier action in the python version of cocos2d, but I'm not sure if it was ever ported to this iPhone branch.  I might try to implement it myself later, but just as a test I made the following action:</p>
<pre><code>@implementation TraversePathAction

+(id) actionWithDuration: (ccTime) t path: (NSArray*) path {
	return [[[self alloc] initWithDuration:t path:path] autorelease];
}

-(id) initWithDuration: (ccTime) t path: (NSArray*) path {
	self = [super initWithDuration:t];
	if (self != nil) {
		pathArray = [path retain];
	}
	return self;
}

-(id) copyWithZone: (NSZone *)zone {
	Action *copy = [[[self class] allocWithZone:zone] initWithDuration:[self duration] path:pathArray];
	return copy;
}

-(void) start {
	[super start];

}

-(void) update: (ccTime) t {
	int pathPointCount = [pathArray count];
	int index = (int) ((((float)pathPointCount-1)+0.5f)*t);

	NSValue *value = [pathArray objectAtIndex:index];
	CGPoint movePoint = [value CGPointValue];
	//todo: interpolation

	[target setPosition:movePoint];
}

-(void) dealloc {
	[pathArray release];
	[super dealloc];
}

@end</code></pre>
<p>This works well if you set up the path array with CGPoint objects (contained in NSValue objects) representing a curve, but it needs a significant point resolution to appear smooth.  It could be improved (as I noted in the todo) by using interpolation... moving between array points based on the remaining time after integer index truncation.  </p>
<p>Have you guys implemented something similar or better?
</p></description>
		</item>

	</channel>
</rss>

