<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using Cocos2D AtlasSpriteManager</title>
	<atom:link href="http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/feed/" rel="self" type="application/rss+xml" />
	<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/</link>
	<description>Programming projects and sample code</description>
	<lastBuildDate>Sun, 07 Mar 2010 21:37:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eric</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1870</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 14 Aug 2009 23:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1870</guid>
		<description>That is the point of using those static-class-variable managers...they are only allocated ONCE, so if I have 10 soldiers who all use two different sprite sheets, I only have two managers (one per sheet) in memory, with each AtlasSprite being attached to the correct manager. You could think of them as singletons, as there will only be one &#039;alloc&#039; called no matter how many objects use it.

The annoying part with this is when applying actions, you have to track the state to remember whether or not to apply the action to the AtlasSprite from sheet1 or sheet 2. In my game, this wasn&#039;t an issue since I didn&#039;t use actions that much, but for other games this could be a major hassle.

You are correct, you could just create many copies of the SpriteManagers and the texture manager would only load the sprite sheet once. However, you can&#039;t just make one AtlasSpriteManager per AtlasSprite as that just as slow as Sprite, so you still need to share the managers to some extent. And each time you create another Manager for the same texture, you are throwing away the entire performance gain that you get from using a single Manager for one texture.

Read on the cocos2d forums about why AtlasSpriteManager is there. It will not be dropped, because it is a useful tool that you can use to &#039;batch&#039; opengl calls without having to delve into the OpenGL yourself. By twisting your code around to fit this seemingly arbitrary design structure, you vastly increase the efficiency of the OpenGL code running underneath it by allowing OpenGL to copy many different parts of the same texture in one big operation, avoiding the overhead of many small operations.

Thanks, and good luck on your project!</description>
		<content:encoded><![CDATA[<p>That is the point of using those static-class-variable managers&#8230;they are only allocated ONCE, so if I have 10 soldiers who all use two different sprite sheets, I only have two managers (one per sheet) in memory, with each AtlasSprite being attached to the correct manager. You could think of them as singletons, as there will only be one &#8216;alloc&#8217; called no matter how many objects use it.</p>
<p>The annoying part with this is when applying actions, you have to track the state to remember whether or not to apply the action to the AtlasSprite from sheet1 or sheet 2. In my game, this wasn&#8217;t an issue since I didn&#8217;t use actions that much, but for other games this could be a major hassle.</p>
<p>You are correct, you could just create many copies of the SpriteManagers and the texture manager would only load the sprite sheet once. However, you can&#8217;t just make one AtlasSpriteManager per AtlasSprite as that just as slow as Sprite, so you still need to share the managers to some extent. And each time you create another Manager for the same texture, you are throwing away the entire performance gain that you get from using a single Manager for one texture.</p>
<p>Read on the cocos2d forums about why AtlasSpriteManager is there. It will not be dropped, because it is a useful tool that you can use to &#8216;batch&#8217; opengl calls without having to delve into the OpenGL yourself. By twisting your code around to fit this seemingly arbitrary design structure, you vastly increase the efficiency of the OpenGL code running underneath it by allowing OpenGL to copy many different parts of the same texture in one big operation, avoiding the overhead of many small operations.</p>
<p>Thanks, and good luck on your project!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Everson Siqueira</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1869</link>
		<dc:creator>Everson Siqueira</dc:creator>
		<pubDate>Fri, 14 Aug 2009 20:07:57 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1869</guid>
		<description>Thanks for answering! For all &#039;stickguys&#039; instances that look alike, you have a single, actually two sprite managers... But the point is: is those two sprite managers shared (like a &#039;static-class-variable&#039;) by all soldiers - or if you have 10 soldiers of the same look in scene you have 20 (because of the two) sprite managers on memory?

I suppose even if you have several sprite managers using the same texture, cocos2d keeps a single texture  on the openGLES memory - but someone more smart than me could really confirm it commenting after.

In the end, I guess the AtlasSpriteManager could be &#039;dropped&#039; from cocos2d... and its functionality could be put inside AtlasSprite directly - and atlasSprites would be using a Texture2d or something directly. I think it would make things easier and more flexible (mainly about Z).

By the way, congrats for StickWars! Wish you all the success!</description>
		<content:encoded><![CDATA[<p>Thanks for answering! For all &#8217;stickguys&#8217; instances that look alike, you have a single, actually two sprite managers&#8230; But the point is: is those two sprite managers shared (like a &#8217;static-class-variable&#8217;) by all soldiers &#8211; or if you have 10 soldiers of the same look in scene you have 20 (because of the two) sprite managers on memory?</p>
<p>I suppose even if you have several sprite managers using the same texture, cocos2d keeps a single texture  on the openGLES memory &#8211; but someone more smart than me could really confirm it commenting after.</p>
<p>In the end, I guess the AtlasSpriteManager could be &#8216;dropped&#8217; from cocos2d&#8230; and its functionality could be put inside AtlasSprite directly &#8211; and atlasSprites would be using a Texture2d or something directly. I think it would make things easier and more flexible (mainly about Z).</p>
<p>By the way, congrats for StickWars! Wish you all the success!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1868</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 14 Aug 2009 01:39:51 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1868</guid>
		<description>I&#039;m creating an &#039;inside particular&#039; because for one &#039;sprite&#039; character that has like 60-100 frames for all the animations, it approaches the max texture size of 1024x1024. So I end using 4-6 different sheets, each stored in their static members, which allows the managers to be re-used for sprites that share frames.

Some of this implementation is particular to my own game, though it may be helpful for other games.</description>
		<content:encoded><![CDATA[<p>I&#8217;m creating an &#8216;inside particular&#8217; because for one &#8217;sprite&#8217; character that has like 60-100 frames for all the animations, it approaches the max texture size of 1024&#215;1024. So I end using 4-6 different sheets, each stored in their static members, which allows the managers to be re-used for sprites that share frames.</p>
<p>Some of this implementation is particular to my own game, though it may be helpful for other games.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Everson Siqueira</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1867</link>
		<dc:creator>Everson Siqueira</dc:creator>
		<pubDate>Fri, 14 Aug 2009 01:29:50 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1867</guid>
		<description>Nice tutorial! The persuit of performance using AtlasSprites and the AtlasSpriteManager is taking a lot of my time also.

Question: are you creating an &quot;inside particular&quot; sprite manager for each &quot;sprite&quot; you raise? Is this because of the difficulty of controlling the z?

I am using a single (shared) sprite manager as a &quot;Static&quot; variable in my &quot;enemy&quot; class, used by all sprite instances.</description>
		<content:encoded><![CDATA[<p>Nice tutorial! The persuit of performance using AtlasSprites and the AtlasSpriteManager is taking a lot of my time also.</p>
<p>Question: are you creating an &#8220;inside particular&#8221; sprite manager for each &#8220;sprite&#8221; you raise? Is this because of the difficulty of controlling the z?</p>
<p>I am using a single (shared) sprite manager as a &#8220;Static&#8221; variable in my &#8220;enemy&#8221; class, used by all sprite instances.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1660</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Tue, 02 Jun 2009 13:32:38 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1660</guid>
		<description>You can take out those three Texture2D lines with no negative effects. So you can just have:

spriteManager1 = [[AtlasSpriteManager alloc] initWithFile:@”smallstick_common.png” capacity:50];

All those are doing is setting up the texture tool to use aliased textures (versus anti-aliased). Capacity refers to the number of AtlasSprites frames you plan to add as a child to that AtlasSpriteManager. If you are creating 50 frames (say 5 animations with 10 frames each) then you give it a capacity of 50. However, you do not have to be exact with this, you could leave it at 1 and it would just take a little more time at run-time to resize the array.</description>
		<content:encoded><![CDATA[<p>You can take out those three Texture2D lines with no negative effects. So you can just have:</p>
<p>spriteManager1 = [[AtlasSpriteManager alloc] initWithFile:@”smallstick_common.png” capacity:50];</p>
<p>All those are doing is setting up the texture tool to use aliased textures (versus anti-aliased). Capacity refers to the number of AtlasSprites frames you plan to add as a child to that AtlasSpriteManager. If you are creating 50 frames (say 5 animations with 10 frames each) then you give it a capacity of 50. However, you do not have to be exact with this, you could leave it at 1 and it would just take a little more time at run-time to resize the array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fionel</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1659</link>
		<dc:creator>fionel</dc:creator>
		<pubDate>Tue, 02 Jun 2009 08:31:06 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1659</guid>
		<description>Thanks for your reply.  I thought maybe you somehow use those 2 spritesheets to swap between all the spritesheets (if you have more than 2).  I guess there is no easy way out :)

there are a couple of snippets that I did not understand:

[Texture2D saveTexParameters];
[Texture2D setAliasTexParameters];
spriteManager1 = [[AtlasSpriteManager alloc] initWithFile:@&quot;smallstick_common.png&quot; capacity:50];	
[Texture2D restoreTexParameters];

what exactly is being done here?  What are all those calls made to Texture2D?  I tried looking at Texture2D.h but with basically no OpenGL background I couldn&#039;t understand.

Also, what does &quot;capacity&quot; mean for a textureAtlas anyway?</description>
		<content:encoded><![CDATA[<p>Thanks for your reply.  I thought maybe you somehow use those 2 spritesheets to swap between all the spritesheets (if you have more than 2).  I guess there is no easy way out <img src='http://johnehartzog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>there are a couple of snippets that I did not understand:</p>
<p>[Texture2D saveTexParameters];<br />
[Texture2D setAliasTexParameters];<br />
spriteManager1 = [[AtlasSpriteManager alloc] initWithFile:@&#8221;smallstick_common.png&#8221; capacity:50];<br />
[Texture2D restoreTexParameters];</p>
<p>what exactly is being done here?  What are all those calls made to Texture2D?  I tried looking at Texture2D.h but with basically no OpenGL background I couldn&#8217;t understand.</p>
<p>Also, what does &#8220;capacity&#8221; mean for a textureAtlas anyway?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1657</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Tue, 02 Jun 2009 02:55:40 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1657</guid>
		<description>Well there are a few things you could do. You could write a more general solution that instead of using hacked function1, function2, function3 methods, just set up everything in an array and run through it there. In each &#039;Touchable&#039;  you could keep a static copy of an array that contains references to the spritesheets, and make those changes accordingly. Or you could literally start just adding more &#039;hack&#039; functions in there, so you can use a 3rd or 4th spritesheet. I actually did this when I added a new object needed a third spritesheet.

However, I knew beforehand that no single Sprite would need to access more than 2 spritesheets, so this way took a little less time to throw together. It&#039;s not extensible coding, but sometimes you have to make sacrifices when pumping out updates every 1.5 weeks!

But the question is, since a single spritesheet can be up to 1024x1024, would you really need a sprite that needs to draw from more than 2-3 of them? Maybe you do, but I didn&#039;t for my game. Sorry I didn&#039;t come up with a more generic solution, but I&#039;m still relatively new to ObjC and Cocos2d.</description>
		<content:encoded><![CDATA[<p>Well there are a few things you could do. You could write a more general solution that instead of using hacked function1, function2, function3 methods, just set up everything in an array and run through it there. In each &#8216;Touchable&#8217;  you could keep a static copy of an array that contains references to the spritesheets, and make those changes accordingly. Or you could literally start just adding more &#8216;hack&#8217; functions in there, so you can use a 3rd or 4th spritesheet. I actually did this when I added a new object needed a third spritesheet.</p>
<p>However, I knew beforehand that no single Sprite would need to access more than 2 spritesheets, so this way took a little less time to throw together. It&#8217;s not extensible coding, but sometimes you have to make sacrifices when pumping out updates every 1.5 weeks!</p>
<p>But the question is, since a single spritesheet can be up to 1024&#215;1024, would you really need a sprite that needs to draw from more than 2-3 of them? Maybe you do, but I didn&#8217;t for my game. Sorry I didn&#8217;t come up with a more generic solution, but I&#8217;m still relatively new to ObjC and Cocos2d.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fionel</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1656</link>
		<dc:creator>fionel</dc:creator>
		<pubDate>Tue, 02 Jun 2009 02:39:46 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1656</guid>
		<description>Thanks for sharing your insight.  However, I&#039;m wondering what you would do if your sprite makes references to more than 2 spritesheets?</description>
		<content:encoded><![CDATA[<p>Thanks for sharing your insight.  However, I&#8217;m wondering what you would do if your sprite makes references to more than 2 spritesheets?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1649</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Sat, 30 May 2009 01:31:11 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1649</guid>
		<description>I did post the code...right above. What problems are you getting?</description>
		<content:encoded><![CDATA[<p>I did post the code&#8230;right above. What problems are you getting?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Austin</title>
		<link>http://johnehartzog.com/2009/05/using-cocos2d-atlasspritemanager/comment-page-1/#comment-1647</link>
		<dc:creator>Austin</dc:creator>
		<pubDate>Fri, 29 May 2009 23:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://johnehartzog.com/?p=262#comment-1647</guid>
		<description>This is a great tutorial that for some reason I can&#039;t get working. If you have the time can you post the source code? Thanks!</description>
		<content:encoded><![CDATA[<p>This is a great tutorial that for some reason I can&#8217;t get working. If you have the time can you post the source code? Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
