<?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: Texture Atlases and Core Animation</title>
	<atom:link href="http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/feed/" rel="self" type="application/rss+xml" />
	<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/</link>
	<description>Software should be simple.</description>
	<lastBuildDate>Sun, 18 Dec 2011 05:32:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Ben</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-353</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Sat, 08 Jan 2011 11:44:58 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-353</guid>
		<description>Without looking at the code I cant say for sure why you would be getting choppy performance with the CA stuff.  

I would run the performance stuff in instruments (or roll your own) and see where the bottlenecks are in the code.  If it seems like you are spending too much time in the CA methods, then double check how you are loading your layer contents and make sure you arent re-loading them every frame, etc.  (so load the contents once, and then change the contents rect every frame etc..)

Good luck!
-B</description>
		<content:encoded><![CDATA[<p>Without looking at the code I cant say for sure why you would be getting choppy performance with the CA stuff.  </p>
<p>I would run the performance stuff in instruments (or roll your own) and see where the bottlenecks are in the code.  If it seems like you are spending too much time in the CA methods, then double check how you are loading your layer contents and make sure you arent re-loading them every frame, etc.  (so load the contents once, and then change the contents rect every frame etc..)</p>
<p>Good luck!<br />
-B</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nader™</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-352</link>
		<dc:creator>Nader™</dc:creator>
		<pubDate>Fri, 07 Jan 2011 03:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-352</guid>
		<description>Hi Ben and Happy New Year;

I have made a lot of headway with my game, learned so much about animation, specifically, looking out for dropped frames and catching up, velocity calculations and determining key frames. However (you know this was coming), one thing still alludes me. 

When I used the UIKit animation routines, the animation where faultless, especially when it came to a scaled UIView and animating position. Using the manual frame by frame animation seems to suffer from dropped frames a little when using a scale of 1, however, when changing the scale of the entire scene to, say, 0.75, I get really bad choppy movement.

I thought this was probably because I was rendering frames perhaps twice in the same position and hence giving the allusion of choppy animation and compensated by calculating the number of frames required to traverse the scaled distance based on non scaled velocity. Even though, I was rendering less frames in the scaled view and increasing my delta per frame, I was still getting really choppy animation. When I reverted back to UIKit, it was silky smooth. 

I think I am missing something fundamental about animation in iOS, do you possible see what it might be?</description>
		<content:encoded><![CDATA[<p>Hi Ben and Happy New Year;</p>
<p>I have made a lot of headway with my game, learned so much about animation, specifically, looking out for dropped frames and catching up, velocity calculations and determining key frames. However (you know this was coming), one thing still alludes me. </p>
<p>When I used the UIKit animation routines, the animation where faultless, especially when it came to a scaled UIView and animating position. Using the manual frame by frame animation seems to suffer from dropped frames a little when using a scale of 1, however, when changing the scale of the entire scene to, say, 0.75, I get really bad choppy movement.</p>
<p>I thought this was probably because I was rendering frames perhaps twice in the same position and hence giving the allusion of choppy animation and compensated by calculating the number of frames required to traverse the scaled distance based on non scaled velocity. Even though, I was rendering less frames in the scaled view and increasing my delta per frame, I was still getting really choppy animation. When I reverted back to UIKit, it was silky smooth. </p>
<p>I think I am missing something fundamental about animation in iOS, do you possible see what it might be?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nader™</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-349</link>
		<dc:creator>Nader™</dc:creator>
		<pubDate>Mon, 22 Nov 2010 02:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-349</guid>
		<description>Well I have made some really great progress but I thought I would share some interesting information I gathered along the way.

When I first implemented the CADisplayLink, I noticed that my frame rates would stall, especially under situations where there was a lot of gestures going on. I kept thinking how using NSTimer didn&#039;t seem to suffer from this but DisplayLink does. I was beginning to question this entire approach but thought surely these guys knew what they were talking about, hence I must be doing something wrong.

I then decided to roll my own gesture recognition methods and that seem to have cleared it all up. The UIGestureRecognizer appears to play havoc with high frame rate animation. The NSTimer seems less prone to it but call still suffer dropped frames.

Now I guess I just need to do some trial and error to determine what speed gestures constitute a swipe and how much travel needs to occur. FUN.....not!</description>
		<content:encoded><![CDATA[<p>Well I have made some really great progress but I thought I would share some interesting information I gathered along the way.</p>
<p>When I first implemented the CADisplayLink, I noticed that my frame rates would stall, especially under situations where there was a lot of gestures going on. I kept thinking how using NSTimer didn&#8217;t seem to suffer from this but DisplayLink does. I was beginning to question this entire approach but thought surely these guys knew what they were talking about, hence I must be doing something wrong.</p>
<p>I then decided to roll my own gesture recognition methods and that seem to have cleared it all up. The UIGestureRecognizer appears to play havoc with high frame rate animation. The NSTimer seems less prone to it but call still suffer dropped frames.</p>
<p>Now I guess I just need to do some trial and error to determine what speed gestures constitute a swipe and how much travel needs to occur. FUN&#8230;..not!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-348</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Mon, 15 Nov 2010 05:15:46 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-348</guid>
		<description>Hey Nader,

in relation to a master clock, I would say that in most cases this is the best way to go.  If performance isn&#039;t an issue (a rarity on the iDevices :-)  then having multiple clocks is an OK solution.  However, each timer you have running requires extra overhead, so if you can keep it to a single master then all the better.

the CADisplayLink is basically already a singleton master clock, however I generally make another object (sometimes a singleton) that handles all the scheduling for any objects that need it.  

However, once you have a master scheduler then you can also do clever things like set up delayed scheduling (much like NSObject&#039;s performSelector:withDelay method, but synced to your timer.)  So i will set up some methods that are like: call this selector on this object after this many seconds, or call this selector on this object every x seconds etc... and let the scheduler handle the dispatch. (basically as you suggested, this is how I have objects &#039;register&#039; for updates. but I have a few different ways so that I can have one-offs and somethings that are only updateing every 5 seconds or something as well as things that need updates every frame.)

Once you have a master scheduler, then things like sharing information between threads becomes a bit easier.  You can schedule some special times to query the other threads and let them update your scene objects at times when you are not calling any other scheduled objects.

Cheers!
-B</description>
		<content:encoded><![CDATA[<p>Hey Nader,</p>
<p>in relation to a master clock, I would say that in most cases this is the best way to go.  If performance isn&#8217;t an issue (a rarity on the iDevices :-)  then having multiple clocks is an OK solution.  However, each timer you have running requires extra overhead, so if you can keep it to a single master then all the better.</p>
<p>the CADisplayLink is basically already a singleton master clock, however I generally make another object (sometimes a singleton) that handles all the scheduling for any objects that need it.  </p>
<p>However, once you have a master scheduler then you can also do clever things like set up delayed scheduling (much like NSObject&#8217;s performSelector:withDelay method, but synced to your timer.)  So i will set up some methods that are like: call this selector on this object after this many seconds, or call this selector on this object every x seconds etc&#8230; and let the scheduler handle the dispatch. (basically as you suggested, this is how I have objects &#8216;register&#8217; for updates. but I have a few different ways so that I can have one-offs and somethings that are only updateing every 5 seconds or something as well as things that need updates every frame.)</p>
<p>Once you have a master scheduler, then things like sharing information between threads becomes a bit easier.  You can schedule some special times to query the other threads and let them update your scene objects at times when you are not calling any other scheduled objects.</p>
<p>Cheers!<br />
-B</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nader™</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-347</link>
		<dc:creator>Nader™</dc:creator>
		<pubDate>Mon, 15 Nov 2010 00:16:39 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-347</guid>
		<description>This was great.

I implemented the design pattern you gave and it really has made such a difference to the animation. I have such a granular level of control and the animation is really smooth. Great tip about having odd and even frames, where by using odd and even frames for positioning and only even frames for image masking, that a fine example of knowledge vs experience.

I have a question about the clock implementation. Is it standard practice to implement a master clock that all animations are driven from or implement a clock per animation group?

If the practice is a master clock, then I was thinking of making a singleton static clock object where by I register and de-register selectors to perform in the background. But is it worth the effort, or is just having a clock per animation group adequate. 

FYI, my term animation group refers to say a clock for the sprite that is allocated dynamically as the sprite does something and a clock perhaps for an animation that is constantly going in the background.

Sorry to keep firing off these questions at you but getting access to a seasoned game developer is a rarity and ever so valuable.</description>
		<content:encoded><![CDATA[<p>This was great.</p>
<p>I implemented the design pattern you gave and it really has made such a difference to the animation. I have such a granular level of control and the animation is really smooth. Great tip about having odd and even frames, where by using odd and even frames for positioning and only even frames for image masking, that a fine example of knowledge vs experience.</p>
<p>I have a question about the clock implementation. Is it standard practice to implement a master clock that all animations are driven from or implement a clock per animation group?</p>
<p>If the practice is a master clock, then I was thinking of making a singleton static clock object where by I register and de-register selectors to perform in the background. But is it worth the effort, or is just having a clock per animation group adequate. </p>
<p>FYI, my term animation group refers to say a clock for the sprite that is allocated dynamically as the sprite does something and a clock perhaps for an animation that is constantly going in the background.</p>
<p>Sorry to keep firing off these questions at you but getting access to a seasoned game developer is a rarity and ever so valuable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nader™</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-346</link>
		<dc:creator>Nader™</dc:creator>
		<pubDate>Wed, 10 Nov 2010 05:30:14 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-346</guid>
		<description>Wow, that is a completely different approach to what I am doing today. I have never written a game before, most of my application development has been enterprise/utility based and so never had to address these sorts of issues as you pointed out.

I will need time to digest what you have written and look into it&#039;s implementation.

I cannot thank you enough for your guidance. This site is a very valuable resource for people like me as I have out grown stackoverflow (well perhaps not from what you are showing me).

I&#039;ll look into the IGDAM, this is all new to me :-)</description>
		<content:encoded><![CDATA[<p>Wow, that is a completely different approach to what I am doing today. I have never written a game before, most of my application development has been enterprise/utility based and so never had to address these sorts of issues as you pointed out.</p>
<p>I will need time to digest what you have written and look into it&#8217;s implementation.</p>
<p>I cannot thank you enough for your guidance. This site is a very valuable resource for people like me as I have out grown stackoverflow (well perhaps not from what you are showing me).</p>
<p>I&#8217;ll look into the IGDAM, this is all new to me :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-345</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Wed, 10 Nov 2010 00:54:40 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-345</guid>
		<description>Hey Nader,

For anything sprite related (even when I am not using OpenGL) I tend to implement a master clock that runs at some integer fraction of the display rate (ie nowadays I use the CADisplayLink, but used NSTimers or NSThreads before CADisplaylink was available on most devices.  (I think for now it has become pretty safe to support 3.3.1 and above which mean you always have a CADisplaylink for your timing needs :-)

So with that in mind I tend to design all my animating objects with an update method built in (sort of standard game loop style)  and in that update method I handle any state changes that need to occur.  So if my update is running a 60 fps and my animation is running at 12 fps then every 5 frames I update the animation sprite, but every frame I might be updating the position so that the movement is nice and smooth. 

Obviously this is more work than just using the core animations but if you need to sync your animations with movement, then I would say that trying to shoehorn CA into that role is probably not the best idea. (this isnt to say it cant be done, but once you get more than a few independently moving and animating sprites then it gets a bit dicey in terms of performance and keeping everything in sync)

A great deal of the really slick UIKit stuff is really good for user interfaces (where much of the animation is secondary to the actual function of the interface, so if you miss a frame here and there, or your slide out animation is a few frames too slow nobody will ever notice)  Once you start doing games you generally need to have better control so it is usually worthwhile to roll your own animation system that is tailored to your specific problem set.

Cheers!
-B

Hey, if you are in melbourne you should be coming to the IGDAM meetups, http://igdamelbourne.org/  once a month, usually on a tuesday (was one just last night)  come and say howdee :-)</description>
		<content:encoded><![CDATA[<p>Hey Nader,</p>
<p>For anything sprite related (even when I am not using OpenGL) I tend to implement a master clock that runs at some integer fraction of the display rate (ie nowadays I use the CADisplayLink, but used NSTimers or NSThreads before CADisplaylink was available on most devices.  (I think for now it has become pretty safe to support 3.3.1 and above which mean you always have a CADisplaylink for your timing needs :-)</p>
<p>So with that in mind I tend to design all my animating objects with an update method built in (sort of standard game loop style)  and in that update method I handle any state changes that need to occur.  So if my update is running a 60 fps and my animation is running at 12 fps then every 5 frames I update the animation sprite, but every frame I might be updating the position so that the movement is nice and smooth. </p>
<p>Obviously this is more work than just using the core animations but if you need to sync your animations with movement, then I would say that trying to shoehorn CA into that role is probably not the best idea. (this isnt to say it cant be done, but once you get more than a few independently moving and animating sprites then it gets a bit dicey in terms of performance and keeping everything in sync)</p>
<p>A great deal of the really slick UIKit stuff is really good for user interfaces (where much of the animation is secondary to the actual function of the interface, so if you miss a frame here and there, or your slide out animation is a few frames too slow nobody will ever notice)  Once you start doing games you generally need to have better control so it is usually worthwhile to roll your own animation system that is tailored to your specific problem set.</p>
<p>Cheers!<br />
-B</p>
<p>Hey, if you are in melbourne you should be coming to the IGDAM meetups, <a href="http://igdamelbourne.org/" rel="nofollow">http://igdamelbourne.org/</a>  once a month, usually on a tuesday (was one just last night)  come and say howdee :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nader™</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-344</link>
		<dc:creator>Nader™</dc:creator>
		<pubDate>Wed, 10 Nov 2010 00:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-344</guid>
		<description>Hi Ben;

This saved me such a lot of R&amp;D. Before reading this post, I was actually using cached arrays of images depending on what the sprite was doing, however I was using the NSTimer to swap images much like your approach. I have gone from 60 image frames to one, and re-implemented my cached arrays of image to caches arrays of frames.

Thanks so much for the blog post....

I have one question though. In my old approach, I have two animations going, one to swap out images and the other to move the location of the spite and I am not sure I had the best practice implemented.

I would use an animation block (iOS4 style) for the center position over a duration &quot;x&quot; and implement the animation delegate &quot;animation did start&quot; where I would start a timer. The timer would call a selector to swap out the images every x/(Frame Numbers). I can&#039;t help but feel this approach is prone to falling out of sync between the two animations. Should I be doing this all from a timer where the selector not only draws the new frame but moves it too using the transaction block?

Your insight and design pattern would be greatly appreciated.

P.S. I am in Melbourne too ;-)</description>
		<content:encoded><![CDATA[<p>Hi Ben;</p>
<p>This saved me such a lot of R&amp;D. Before reading this post, I was actually using cached arrays of images depending on what the sprite was doing, however I was using the NSTimer to swap images much like your approach. I have gone from 60 image frames to one, and re-implemented my cached arrays of image to caches arrays of frames.</p>
<p>Thanks so much for the blog post&#8230;.</p>
<p>I have one question though. In my old approach, I have two animations going, one to swap out images and the other to move the location of the spite and I am not sure I had the best practice implemented.</p>
<p>I would use an animation block (iOS4 style) for the center position over a duration &#8220;x&#8221; and implement the animation delegate &#8220;animation did start&#8221; where I would start a timer. The timer would call a selector to swap out the images every x/(Frame Numbers). I can&#8217;t help but feel this approach is prone to falling out of sync between the two animations. Should I be doing this all from a timer where the selector not only draws the new frame but moves it too using the transaction block?</p>
<p>Your insight and design pattern would be greatly appreciated.</p>
<p>P.S. I am in Melbourne too ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: logix812</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-277</link>
		<dc:creator>logix812</dc:creator>
		<pubDate>Sun, 12 Jul 2009 17:33:55 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-277</guid>
		<description>Ben, I would LOVE to get my hands on the atlas program of yours, I started writing my own, but hey, whatever saves time =).  I also played with pixen (http://opensword.org/Pixen/) but I could not get the transparency to output for the PNG sequence.  Also it would make the atlases greater than 1024, which would still mean I need to edit them for openGL usage.

Basically I vote for you doing a post on your program =)</description>
		<content:encoded><![CDATA[<p>Ben, I would LOVE to get my hands on the atlas program of yours, I started writing my own, but hey, whatever saves time =).  I also played with pixen (<a href="http://opensword.org/Pixen/" rel="nofollow">http://opensword.org/Pixen/</a>) but I could not get the transparency to output for the PNG sequence.  Also it would make the atlases greater than 1024, which would still mean I need to edit them for openGL usage.</p>
<p>Basically I vote for you doing a post on your program =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://benbritten.com/2009/05/11/texture-atlases-and-core-animation/comment-page-1/#comment-274</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Fri, 10 Jul 2009 22:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://benbritten.com/?p=251#comment-274</guid>
		<description>Hey Logix,

Yes you are absolutely correct. In fact I would definitely suggest pre-calculating your atlas positions prior to your animation.

I have a little program that builds the atlases for me from individual images (if I ever have free time, i might even do a post about it).

In any case I generate a plist meta file with all the frame positions in the atlas and then load that meta data at the same time I load the image (usually sometime before the animation is required)

This is also handy because you can then be very clever about your image usage.  For instance, the last four or five frames of the example animation are really only about half the height of the first few, that is a pretty big waste of space (and memory).  Instead I pack them into the atlas with the minimum amount of space around them and just record a center offset so that I can (in core animation or OpenGL) move it to the right position in the animation cell.  

This way you can pack your atlases much much tighter and save tons of space on the iPhone :-)

Anyway, it is early here so hopefully that makes some amount of sense.

Cheers!
-B</description>
		<content:encoded><![CDATA[<p>Hey Logix,</p>
<p>Yes you are absolutely correct. In fact I would definitely suggest pre-calculating your atlas positions prior to your animation.</p>
<p>I have a little program that builds the atlases for me from individual images (if I ever have free time, i might even do a post about it).</p>
<p>In any case I generate a plist meta file with all the frame positions in the atlas and then load that meta data at the same time I load the image (usually sometime before the animation is required)</p>
<p>This is also handy because you can then be very clever about your image usage.  For instance, the last four or five frames of the example animation are really only about half the height of the first few, that is a pretty big waste of space (and memory).  Instead I pack them into the atlas with the minimum amount of space around them and just record a center offset so that I can (in core animation or OpenGL) move it to the right position in the animation cell.  </p>
<p>This way you can pack your atlases much much tighter and save tons of space on the iPhone :-)</p>
<p>Anyway, it is early here so hopefully that makes some amount of sense.</p>
<p>Cheers!<br />
-B</p>
]]></content:encoded>
	</item>
</channel>
</rss>

