<?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: coordinate - Recent Posts</title>
		<link>http://www.cocos2d-iphone.org/forum/tags/coordinate</link>
		<description>A fast, easy to use, free, and community supported 2D game engine</description>
		<language>en-US</language>
		<pubDate>Fri, 10 Feb 2012 03:33:31 +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/coordinate" rel="self" type="application/rss+xml" />

		<item>
			<title>Bill Hollings on "How to find a on-screen location of a CC3Node?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19730#post-110703</link>
			<pubDate>Mon, 15 Aug 2011 11:44:44 +0000</pubDate>
			<dc:creator>Bill Hollings</dc:creator>
			<guid isPermaLink="false">110703@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/11232'>hima</a></p>
<p>The <code>CC3Camera</code> <code>projectNode:</code> method will calculate and return the 2D screen location of any 3D node. The value is cached in the <code>projectedLocation</code> and <code>projectedPosition</code> properties of the 3D node</p>
<p>Be sure to read the API docs for each of those methods/properties to understand how to use them and interpret the returned values.</p>
<p>There is an example of using <code>projectNode:</code> (for logging 2D position of node that was touched) in the <code>CC3DemoMashUp</code> demo.</p>
<p>...Bill
</p></description>
		</item>
		<item>
			<title>baris on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-110659</link>
			<pubDate>Sun, 14 Aug 2011 23:23:08 +0000</pubDate>
			<dc:creator>baris</dc:creator>
			<guid isPermaLink="false">110659@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>ajohanss,</p>
<p>As far as I can understand, currently the best way to change the center of rotation is to add your node to a parent node and to rotate the parent node. If you want to move the center of rotation of your object by (2,0,0) for instance, you would set the location of your node to (-2,0,0) inside the parent.</p>
<p>My problem is not about changing the center of rotation.. but writing this, I realized that a similar hack might work for me as well.</p>
<p>Edit: That was an exercise in optimism, apparently.. A much more clear explanation of what I was trying to say is in this thread, with links to answers by Bill: <a href="http://www.cocos2d-iphone.org/forum/topic/16319" rel="nofollow">http://www.cocos2d-iphone.org/forum/topic/16319</a><br />
Sorry for not seeing that before... And I assume things haven't changed in the 3 months since?
</p></description>
		</item>
		<item>
			<title>ajohanss on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-110655</link>
			<pubDate>Sun, 14 Aug 2011 22:18:35 +0000</pubDate>
			<dc:creator>ajohanss</dc:creator>
			<guid isPermaLink="false">110655@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>I think I have a similar problem as described above.<br />
I have an object that I want to rotate around different points.</p>
<p>Is it possible to dynamically set the 'center of rotation' for a single object in runtime ?
</p></description>
		</item>
		<item>
			<title>baris on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-110544</link>
			<pubDate>Sat, 13 Aug 2011 19:30:27 +0000</pubDate>
			<dc:creator>baris</dc:creator>
			<guid isPermaLink="false">110544@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Thanks for the incredibly fast and detailed answer Bill, and sorry for replying late.. I thought the forum would send me an email for any replies, but I now see that it didn't.</p>
<p>What I want to do is actually very basic.. I have a ball that I want to roll around the screen.</p>
<p>I can make it roll towards the right side of the screen:<br />
[ball runAction:[CC3RotateBy actionWithDuration:0.5 rotateBy:cc3v(0, 90, 0)]];</p>
<p>I can make it roll towards the bottom of the screen:<br />
[ball runAction:[CC3RotateBy actionWithDuration:0.5 rotateBy:cc3v(90, 0, 0)]];</p>
<p>But I can't figure out a simple way to roll it towards the right side, and THEN the bottom of the screen.. This doesn't work, because apparently (at least, this is my beginner's interpretation of what's happening) the first rotation also rotates the coordinate frame of my ball object, so the second rotation rotates it in a direction I don't want:<br />
[ball runAction:[CC3RotateBy actionWithDuration:0.5 rotateBy:cc3v(0, 90, 0)]];<br />
[ball runAction:[CC3RotateBy actionWithDuration:0.5 rotateBy:cc3v(90, 0, 0)]];</p>
<p>Am I missing something obvious here, or is there need to make 3d geometry calculations in order to achieve this?
</p></description>
		</item>
		<item>
			<title>hima on "How to find a on-screen location of a CC3Node?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/19730#post-110475</link>
			<pubDate>Sat, 13 Aug 2011 05:24:20 +0000</pubDate>
			<dc:creator>hima</dc:creator>
			<guid isPermaLink="false">110475@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Is there a way to find a screen location of a CC3Node? Unity3D has one and it's really convenient. Maybe there already is something like this but I couldn't find it from the source code :(
</p></description>
		</item>
		<item>
			<title>Bill Hollings on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-108540</link>
			<pubDate>Tue, 02 Aug 2011 21:03:36 +0000</pubDate>
			<dc:creator>Bill Hollings</dc:creator>
			<guid isPermaLink="false">108540@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/25656'>baris</a></p>
<p>Perhaps I'm not understanding the challenge you're facing, but rotating a node based on a swipe is trivial using a <code>CCAction</code>, or even by using the <code>updateBeforeTransform:</code> method of your node (as a specialized subclass), or of your customized <code>CC3World</code>. In all cases, it's just a matter of updating the rotation property. See the basic <em>hello, world</em> template project for an example of simple rotation of an object.</p>
<p>Rotation (or location, or scale) of a node is defined in terms of the node's parent node. So, you can create sophisticated assemblies of nodes where the rotation or movement of a parent node also carries its descendant nodes along with it, and each child can be rotated and moved within the context of the parent (eg- think of spinning tires on a car that is doing a barrel roll).</p>
<p>The parent of all nodes is <code>CC3World</code>, so in the simple case of adding a single box node to the world, movement and rotation are relative to the world. If the camera is added directly to the world as well, then both box and camera move and rotate within the world.</p>
<p>But perhaps you could expand on what you mean by <em>"hopping between coordinate systems"</em>.</p>
<p>...Bill
</p></description>
		</item>
		<item>
			<title>baris on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-108288</link>
			<pubDate>Mon, 01 Aug 2011 16:17:07 +0000</pubDate>
			<dc:creator>baris</dc:creator>
			<guid isPermaLink="false">108288@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I had a similar question.. But in CC3DemoMashUp, as far as my minimal understanding goes, there is no hopping between coordinate systems - the camera rotates, but always with respect to its own coordinate system.</p>
<p>In a situation where there is, for instance a single box in the middle of the screen that the user can rotate by swiping.. is there a default way to rotate the box with respect to an arbitrary coordinate system (in this case, the arbitrary coordinate system would be the initial coordinate system of the CC3MeshNode representing the box, rather than the rotated coordinate system)? Or is this something that should be achieved using some good old trigonometry?
</p></description>
		</item>
		<item>
			<title>Bill Hollings on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-100969</link>
			<pubDate>Sat, 25 Jun 2011 11:45:46 +0000</pubDate>
			<dc:creator>Bill Hollings</dc:creator>
			<guid isPermaLink="false">100969@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>@<a href='http://www.cocos2d-iphone.org/forum/profile/50949'>benji</a></p>
<p>Have a look at the way the camera is controlled in the <code>CC3DemoMashUp</code>. It uses joysticks...but the concept is the same. Either way, you're taking an X-Y coordinate (joystick <code>velocity</code> property...or finger movement) and mapping it to a delta rotation in any of three directions using the <code>rotation</code> property of your <code>CC3Node</code>, combined with the delta time.</p>
<p>...Bill
</p></description>
		</item>
		<item>
			<title>benji on "Transfer a rotation in another coordinate system"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/17920#post-100607</link>
			<pubDate>Thu, 23 Jun 2011 15:38:21 +0000</pubDate>
			<dc:creator>benji</dc:creator>
			<guid isPermaLink="false">100607@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi everyone,</p>
<p>I have a mesh loaded from a pod file and displayed in 3D using cocos3D. I would like to allow the user to rotate this object by sliding his finger on the screen. What I would like to do is to express a rotation in an arbitrary coordinate system where the x and y axis define a plan parallel to the screen of the phone and then transfer this rotation in the coordinate system of the mesh.<br />
Is there a clever way to do this in cocos3D without having to do all the trigonometry myself ?</p>
<p>Have a good day !
</p></description>
		</item>
		<item>
			<title>jiaren on "How to get co-ordinate in scaled Tilemap?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/11308#post-64042</link>
			<pubDate>Mon, 22 Nov 2010 03:12:45 +0000</pubDate>
			<dc:creator>jiaren</dc:creator>
			<guid isPermaLink="false">64042@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hi all,</p>
<p>Thank you every one for sharing knowledge in creating games - - I've learned a lot from this forum. I could find nearly every answer if I got any problem. However, it looks like no such topic covered yet for how to find the coordinate for a scaled Tiledmap.</p>
<p>Normally, I can use below function to get oordinate,</p>
<p>- (CGPoint)tileCoordForPosition:(CGPoint)position InMap:(CCTMXTiledMap *)map {<br />
	int x = position.x / map.tileSize.width;<br />
    int y = ((map.mapSize.height * map.tileSize.height) - position.y) / map.tileSize.height;</p>
<p>    return ccp(x, y);<br />
}</p>
<p>Could any expert here tell me how to sort it out in a scaled map? </p>
<p>Here I only apply scale in Y axis.</p>
<p>Thanks in advance.
</p></description>
		</item>
		<item>
			<title>horseshoe7 on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55155</link>
			<pubDate>Tue, 14 Sep 2010 19:11:03 +0000</pubDate>
			<dc:creator>horseshoe7</dc:creator>
			<guid isPermaLink="false">55155@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I figured out the vertical flip problem.  I had to reverse the top and bottom arguments of the glOrtho(...) call.</p>
<p>Then had to modify my touchToGameCoords method to also flip the y component.</p>
<p>Will try to merge this topic with the other <a href="http://www.cocos2d-iphone.org/forum/topic/9568">related post.</a> </p>
<p>Seriously, THANK YOU!!
</p></description>
		</item>
		<item>
			<title>horseshoe7 on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55153</link>
			<pubDate>Tue, 14 Sep 2010 18:57:10 +0000</pubDate>
			<dc:creator>horseshoe7</dc:creator>
			<guid isPermaLink="false">55153@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The first call of glLoadIdentity() just before glOrtho(..) got me closer to the goal.  Everything is still flipped from top to bottom.  That is, I get the top left corner displayed at the center of the screen instead of the bottom left corner.  The second glOrtho call wasn't necessary.</p>
<p>My touchToGameWorld coordinate converter works, of course, just everything is flipped.  Even the image is displayed as its upside-down mirror.</p>
<p>Last step is to solve this vertical flip problem.  Any idea what I need to do to accomplish that?
</p></description>
		</item>
		<item>
			<title>araker on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55149</link>
			<pubDate>Tue, 14 Sep 2010 18:26:03 +0000</pubDate>
			<dc:creator>araker</dc:creator>
			<guid isPermaLink="false">55149@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I'm still using 0.99.4, those methods are redefined somewhere else in 0.99.5 (search the project).</p>
<p>You're case is indeed not what I would expect. I think you're missing a few calls to glLoadIdentity() in the modelview matrix. That could be messing up the coordinate system.</p>
<p>So try this instead..</p>
<pre><code>-(void)visit{
	CGSize screenDims = [[CCDirector sharedDirector] displaySize]; // autorotation not dealt with here.  You will have to deal with that yourself.
	CGPoint camPos = [[controller gameCam] position];  // MyGameLayer keeps a pointer to its Scene Controller, i.e. [self parent] will also work.
	float camZoom = [[controller gameCam] zoom];
	[[CCDirector sharedDirector] setProjection:kCCDirectorProjectionCustom];
	//now set your projection
	glMatrixMode(GL_PROJECTION);
	//save current projection state
	glPushMatrix();
	glLoadIdentity();
	glOrthof(camPos.x -screenDims.width/(2*camZoom),
			 camPos.x +screenDims.width/(2*camZoom),
			 camPos.y +screenDims.height/(2*camZoom),
			 camPos.y -screenDims.height/(2*camZoom),
			 -1000,
			 1000);
	glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
	[super visit];

        //put it back
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();</code></pre>
<p>I'm not sure if the last call to glLoadIdentity() is necessary, you should try that out.
</p></description>
		</item>
		<item>
			<title>horseshoe7 on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55141</link>
			<pubDate>Tue, 14 Sep 2010 17:09:51 +0000</pubDate>
			<dc:creator>horseshoe7</dc:creator>
			<guid isPermaLink="false">55141@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I just don't understand how they all relate to each other, beyond what you just mentioned.</p>
<p>I looked in CCDirector, and those functions just say "override me!"</p>
<p>So, it's not a trivial solution.  Try going through my post, step by step and ask yourself what should happen at each point.  I don't think my problem has a simple solution, but that's just a gut feeling.
</p></description>
		</item>
		<item>
			<title>araker on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55140</link>
			<pubDate>Tue, 14 Sep 2010 16:57:53 +0000</pubDate>
			<dc:creator>araker</dc:creator>
			<guid isPermaLink="false">55140@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>OpenGL and cocos have a different coordinate system. In OpenGL the top left corner is (0,0) while in cocos the bottom left corner is (0,0). One other thing, OpenGL functions all work with the default coordinate system (portrait mode), so for instance when you're in landscape you'll have to swap x and y to make it work. Luckily cocos has some coordinate conversion functions build in, look at convertToGL and convertToUI in the CCDirector.
</p></description>
		</item>
		<item>
			<title>horseshoe7 on "non-trivial coordinate system problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/9580#post-55130</link>
			<pubDate>Tue, 14 Sep 2010 15:59:48 +0000</pubDate>
			<dc:creator>horseshoe7</dc:creator>
			<guid isPermaLink="false">55130@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello,</p>
<p>Related to <a href="http://www.cocos2d-iphone.org/forum/topic/9568">this post.</a></p>
<p>I want to subclass a CCLayer so I can override the visit method with my own openGL code that makes use of a custom camera object.</p>
<p>I am getting seriously confused with how the various coordinate systems are working.</p>
<p>For now, I'll keep everything in PORTRAIT mode, so we avoid confusion.</p>
<p>I'll just write down what I did and hopefully an expert can point out what I did wrong.</p>
<p>- Created a layer, then added an oversized (bigger than 320x480) image as a child.  Cocos2D sets the anchor point of this image to the center of it, so I reset it's anchor to 0,0 before adding it as a child.</p>
<p>- When running the scene, I received what I expected.  the bottom left of my image was at the bottom left of the screen.  Makes sense.  i haven't messed with anything yet.</p>
<p>- I added as a member of the layer, a "Camera" object, that basically keeps track of 3 floats - camX, camY, zoom.  When initializing this, I set it's X,Y = (0,0) and it's zoom to 1.0 (100%).</p>
<p>- then I overrode the visit method:<br />
<pre><code>-(void)visit{
	CGSize screenDims = [[CCDirector sharedDirector] displaySize]; // autorotation not dealt with here.  You will have to deal with that yourself.
	CGPoint camPos = [[controller gameCam] position];  // MyGameLayer keeps a pointer to its Scene Controller, i.e. [self parent] will also work.
	float camZoom = [[controller gameCam] zoom];
	[[CCDirector sharedDirector] setProjection:kCCDirectorProjectionCustom];
	//now set your projection
	glMatrixMode(GL_PROJECTION);
	//save current projection state
	glPushMatrix();
	glLoadIdentity();
	glOrthof(camPos.x -screenDims.width/(2*camZoom),
			 camPos.x +screenDims.width/(2*camZoom),
			 camPos.y +screenDims.height/(2*camZoom),
			 camPos.y -screenDims.height/(2*camZoom),
			 -1000,
			 1000);
	glMatrixMode(GL_MODELVIEW);

	[super visit];

	//put it back
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}</code></pre>
<p>Now, I thought the result of this would be the bottom left corner of my image being located at the centre of the screen, since I wanted to look at 0,0.  The result was that the top left corner of the image was displayed at the top left of the screen.</p>
<p>I am totally confused and have no idea what's going on behind the scenes.</p>
<p>I have worked with basic openGL before with C++.  Creating viewports, creating and placing cams, etc.  I'm probably missing a few key bits of information that give me the whole  picture.</p>
<p>Any help would be great!  I'm absolutely stuck on this one.
</p></description>
		</item>
		<item>
			<title>hm50 on "Need some inspiration for throwing objects..."</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/8228#post-47864</link>
			<pubDate>Mon, 26 Jul 2010 17:44:46 +0000</pubDate>
			<dc:creator>hm50</dc:creator>
			<guid isPermaLink="false">47864@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Hello All.  I am looking for a better, more gamer friendly way of throwing an object in my game. </p>
<p>I have a horizontally scrolling tilemap.<br />
The player needs to throw an object to hit a target.<br />
Currently, when the player throws the object I have the X and Y ending coord for the thrown object hard coded, so that the thrown object always goes to (player.position.x+100, 150).  I use 150 because that is where I have my targets arranged (all at 150 Y). </p>
<p>I want to add other targets at different Y values. </p>
<p>The game is somewhat fast paced (scrolling speed), the player is moved via a joystick and objects are thrown with a button press. </p>
<p>I am looking for a way for the player to select a target prior to throwing. </p>
<p>I am thinking I could use a second "target selection" button, what do you think?</p>
<p>The issue is then, how do I know when a tile with a particular GID is on the screen so that I can set it as a possible target?</p>
<p>Due to animations, sound effects, and a large tilesheet I am already taking a sizable FPS hit, so I need to keep it somewhat simple.</p>
<p>Thanks for any help you can give!</p>
<p>HM50
</p></description>
		</item>
		<item>
			<title>liwenqiu on "the origin point of GL-&gt;UI problem"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/7358#post-43134</link>
			<pubDate>Thu, 24 Jun 2010 04:36:42 +0000</pubDate>
			<dc:creator>liwenqiu</dc:creator>
			<guid isPermaLink="false">43134@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>hello everyone, im newbie to cocos2d for iphone, i studying develop iphone game, but there is problem of UI coordinate confused me,  i known the UI's origin point is left top corner, but in convertToUI function, why it assumed the left bottom corner as the origin,  when i hold the iphone as OrientatonPortrait.
</p></description>
		</item>
		<item>
			<title>riq on "Find Tile in isometric tilemap"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2988#post-38805</link>
			<pubDate>Wed, 26 May 2010 07:13:44 +0000</pubDate>
			<dc:creator>riq</dc:creator>
			<guid isPermaLink="false">38805@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>The formula used to place the isometric tiles is here:<br />
<a href="http://github.com/cocos2d/cocos2d-iphone/blob/release-0.99.3/cocos2d/CCTMXLayer.m#L600" rel="nofollow">http://github.com/cocos2d/cocos2d-iphone/blob/release-0.99.3/cocos2d/CCTMXLayer.m#L600</a>
</p></description>
		</item>
		<item>
			<title>Justatest on "Find Tile in isometric tilemap"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/2988#post-38790</link>
			<pubDate>Wed, 26 May 2010 03:17:27 +0000</pubDate>
			<dc:creator>Justatest</dc:creator>
			<guid isPermaLink="false">38790@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>i meet the same problem , did u solve it now ?
</p></description>
		</item>
		<item>
			<title>JavaWizKid on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24164</link>
			<pubDate>Sun, 24 Jan 2010 17:46:44 +0000</pubDate>
			<dc:creator>JavaWizKid</dc:creator>
			<guid isPermaLink="false">24164@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>How can I fix that? How do I check what has been removed and put it back?
</p></description>
		</item>
		<item>
			<title>Codemattic on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24161</link>
			<pubDate>Sun, 24 Jan 2010 17:29:00 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">24161@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>you run a loop from 0 to 9 for an array with 10 Sprites, but you occasionally remove a Sprite while in the middle of that loop, so now you have less than 10 Sprites in that array so you overstep its bounds.
</p></description>
		</item>
		<item>
			<title>JavaWizKid on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24139</link>
			<pubDate>Sun, 24 Jan 2010 13:02:23 +0000</pubDate>
			<dc:creator>JavaWizKid</dc:creator>
			<guid isPermaLink="false">24139@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>I've added this code to make the bullets move:</p>
<p>		for(int i = 0; i &#60; 10; i++)<br />
		{<br />
			float x = ((CCSprite *)[bulletsBuilder objectAtIndex:i]).position.x;<br />
			float y = ((CCSprite *)[bulletsBuilder objectAtIndex:i]).position.y;<br />
			x += 5;<br />
			[[bulletsBuilder objectAtIndex:i] setPosition:ccp(x, y)];</p>
<p>			if(((CCSprite *)[bulletsBuilder objectAtIndex:i]).position.x &#62; 490)<br />
			{<br />
				[self removeChild:((CCSprite *)[bulletsBuilder objectAtIndex:i]) cleanup:YES];<br />
				bulletNumber--;<br />
			}<br />
		}</p>
<p>However when the if function is called it errors with:</p>
<p>Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (-376( or possibly larger)) beyond bounds (10)'</p>
<p>Why?
</p></description>
		</item>
		<item>
			<title>Codemattic on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24124</link>
			<pubDate>Sun, 24 Jan 2010 04:40:16 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">24124@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>"Why are the coordinates float variables though?" You may want to scale the camera in and out - so if you zoomed in 200%, now ints can only reach every other x value. You may want to move your sprite by a fractional amount. You may want to use vector or linear or algebraic math - and thats not going to work well with ints. While you can only display pixels, your objects exist as floats. And yes a sprite displayed at 0.5,0.0 will look different than at 0.0,0.0 - opengl does antialiasing and such (you can actually turn this off and on by calling Texture's -setAliasTexParameters or -setAntiAliasTexParameters)
</p></description>
		</item>
		<item>
			<title>Codemattic on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24123</link>
			<pubDate>Sun, 24 Jan 2010 04:31:48 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">24123@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>intValue = (int) floatValue;</p>
<p>the (int) cast is optional, but the compiler may give you warnings without it.
</p></description>
		</item>
		<item>
			<title>Codemattic on "How to track ccsrpite images in an array?"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4024#post-24122</link>
			<pubDate>Sun, 24 Jan 2010 04:28:07 +0000</pubDate>
			<dc:creator>Codemattic</dc:creator>
			<guid isPermaLink="false">24122@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>NSLog(@"X: %i",bul.position.x);</p>
<p>x is a float not an int, try:</p>
<p>NSLog(@"X: %f",bul.position.x);
</p></description>
		</item>
		<item>
			<title>JavaWizKid on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24118</link>
			<pubDate>Sun, 24 Jan 2010 02:53:33 +0000</pubDate>
			<dc:creator>JavaWizKid</dc:creator>
			<guid isPermaLink="false">24118@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Ahh yes that worked thanks! Why are the coordinates float variables though? How can you have say 2.32 pixels on the x axis? How do I convert them into integers?
</p></description>
		</item>
		<item>
			<title>Questor on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24117</link>
			<pubDate>Sun, 24 Jan 2010 02:38:40 +0000</pubDate>
			<dc:creator>Questor</dc:creator>
			<guid isPermaLink="false">24117@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>JavaWizKid,</p>
<p>I think your NSLog format is incorrect, you are using:<br />
<pre><code>NSLog(@&#34;X Position: %i&#34;, ((CCSprite *)[bulletsBuilder objectAtIndex:bulletNumber]).position.x);
NSLog(@&#34;Y Position: %i&#34;, ((CCSprite *)[bulletsBuilder objectAtIndex:bulletNumber]).position.y);</code></pre>
<p>but it should be something like:<br />
<pre><code>NSLog(@&#34;X Position: % .2f&#34;, ((CCSprite *)[bulletsBuilder objectAtIndex:bulletNumber]).position.x);
NSLog(@&#34;Y Position: % .2f&#34;, ((CCSprite *)[bulletsBuilder objectAtIndex:bulletNumber]).position.y);</code></pre>
<p>Hope this helps,<br />
Q
</p></description>
		</item>
		<item>
			<title>JavaWizKid on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24115</link>
			<pubDate>Sun, 24 Jan 2010 02:10:55 +0000</pubDate>
			<dc:creator>JavaWizKid</dc:creator>
			<guid isPermaLink="false">24115@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>For CGPoint I get an error of: error: incompatible types in initialization
</p></description>
		</item>
		<item>
			<title>plasticpower on "CCSprite in Array"</title>
			<link>http://www.cocos2d-iphone.org/forum/topic/4026#post-24112</link>
			<pubDate>Sun, 24 Jan 2010 01:44:50 +0000</pubDate>
			<dc:creator>plasticpower</dc:creator>
			<guid isPermaLink="false">24112@http://www.cocos2d-iphone.org/forum/</guid>
			<description><p>Have you tried:</p>
<p>[[bulletsBuilder objectAtIndex:bulletNumber] setPosition:ccp(...,...)];<br />
/\ You might find that there's nothing in the array at this point and throw an exception, then you know you have some sort of an initialization issue.</p>
<p>Before your NSLog method:<br />
CGPoint *point = [[bulletsBuilder objectAtIndex:bulletNumber] position];<br />
NSLog(@"...", position.x, position.y);</p>
<p>Make sure you're initializing the NSMutableArray properly.<br />
You might have to do something like:</p>
<p>CCSprite *sprite = (CCSprite*)[bulletsBuilder objectAtIndex:bulletNumber];<br />
/\ This is what I normally do to make life easier if you need to do stuff with objects from the array.
</p></description>
		</item>

	</channel>
</rss>

