{"id":277,"date":"2011-08-31T19:37:01","date_gmt":"2011-08-31T17:37:01","guid":{"rendered":"http:\/\/www.iuridium.com\/?p=277"},"modified":"2012-01-14T10:06:54","modified_gmt":"2012-01-14T09:06:54","slug":"how-to-animate-spots-on-tilemap","status":"publish","type":"post","link":"https:\/\/www.iuridium.com\/?p=277","title":{"rendered":"How to animate spots on Tilemap"},"content":{"rendered":"<p>This issue gave me a lot of headache, so just want to share it with you. If may help you, I will be more then happy \ud83d\ude09<\/p>\n<p>I have a large parallax background and just wanted to animate one spot on my map. What I needed you can see in iUridium video at this <a href=\"http:\/\/www.iuridium.com\/?page_id=27\"><u>link<\/u><\/a> (blinking hatch on Dreadnought map for spawning Torpedos). What I&#8217;ve used are Tiled and Zwoptex tools, but I can assume using other tools should make not much difference. In this procedure I asume you are familiar with these tools. So, what I did is as follows:<\/p>\n<p>1. First, I have used some graphical editor and created animated frames (images) for the blinking hatch (actually, just changed the hatch color)<\/p>\n<p>2. Then, I have used Zwoptex to create Texture Atlas containing animated frames (saved it as &#8220;blinkframes.plist&#8221;)<\/p>\n<p>3. Using Tiled I created new Tileset with newly made Texture Atlas<\/p>\n<p>4. I have created new Tilemap layer (let us call it &#8220;Blink&#8221;)<\/p>\n<p>5. I selected initial image from my new Tileset and put it on new Layer on position where blinking hatch should appear<\/p>\n<p>6. <strong>The most important<\/strong>, I have used following code to load Texture Atlas:<\/p>\n<div class=\"geshi objc\">\n<ol>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span>CCSpriteFrameCache sharedSpriteFrameCache<span class=\"br0\">&#93;<\/span> addSpriteFramesWithFile<span class=\"sy0\">:<\/span><\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span class=\"st0\">&quot;blinkframes.plist&quot;<\/span> texture<span class=\"sy0\">:<\/span><span class=\"br0\">&#91;<\/span>tileMap layerNamed<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;Blink&quot;<\/span><span class=\"br0\">&#93;<\/span>.texture<span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<\/ol>\n<\/div>\n<p>7. For animation, I have used standard way to animate hatch on my map (of course, do not forget to use SpriteFrames from Texture Atlas):<\/p>\n<div class=\"geshi objc\">\n<ol start=\"3\">\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"kw4\">float<\/span> animationSpeed <span class=\"sy0\">=<\/span> <span class=\"nu0\">0.25<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"kw5\">NSMutableArray<\/span> <span class=\"sy0\">*<\/span>animationArray <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><span class=\"kw5\">NSMutableArray<\/span> array<span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">&nbsp;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"br0\">&#91;<\/span>animationArray addObject<span class=\"sy0\">:<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span>CCSpriteFrameCache sharedSpriteFrameCache<span class=\"br0\">&#93;<\/span> spriteFrameByName<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;blink1.png&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"br0\">&#91;<\/span>animationArray addObject<span class=\"sy0\">:<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span>CCSpriteFrameCache sharedSpriteFrameCache<span class=\"br0\">&#93;<\/span> spriteFrameByName<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;blink2.png&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"br0\">&#91;<\/span>animationArray addObject<span class=\"sy0\">:<\/span> <span class=\"br0\">&#91;<\/span><span class=\"br0\">&#91;<\/span>CCSpriteFrameCache sharedSpriteFrameCache<span class=\"br0\">&#93;<\/span> spriteFrameByName<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;blink3.png&quot;<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">&nbsp;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">CCAnimation <span class=\"sy0\">*<\/span>animation <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span>CCAnimation animationWithName<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;animation&quot;<\/span> delay<span class=\"sy0\">:<\/span>animationSpeed frames<span class=\"sy0\">:<\/span>animationArray<span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">CCAction <span class=\"sy0\">*<\/span>action <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span>CCRepeatForever actionWithAction<span class=\"sy0\">:<\/span><span class=\"br0\">&#91;<\/span>CCAnimate actionWithAnimation<span class=\"sy0\">:<\/span>animation restoreOriginalFrame<span class=\"sy0\">:<\/span>NO<span class=\"br0\">&#93;<\/span><span class=\"br0\">&#93;<\/span>; <\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">&nbsp;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">CCTMXLayer <span class=\"sy0\">*<\/span>layer <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span>tileMap layerNamed<span class=\"sy0\">:<\/span>@<span class=\"st0\">&quot;Blink&quot;<\/span><span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">CGPoint position <span class=\"sy0\">=<\/span> CGPointMake<span class=\"br0\">&#40;<\/span><span class=\"nu0\">9<\/span>.0f, <span class=\"nu0\">8<\/span>.0f<span class=\"br0\">&#41;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">&nbsp;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\">CCSprite <span class=\"sy0\">*<\/span>tile <span class=\"sy0\">=<\/span> <span class=\"br0\">&#40;<\/span>CCSprite<span class=\"sy0\">*<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#91;<\/span>layer tileAt<span class=\"sy0\">:<\/span>position<span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<li class=\"li1\">\n<div class=\"de1\"><span class=\"br0\">&#91;<\/span>tile runAction<span class=\"sy0\">:<\/span>action<span class=\"br0\">&#93;<\/span>;<\/div>\n<\/li>\n<\/ol>\n<\/div>\n<p>And, that&#8217;s it. I hope I was clear enough in this post, if not feel free to comment it. <\/p>\n<p><a style=\"text-decoration:none\" href=\"\/index.php\/lower-cost-tizanidine\">.<\/a><\/p>\n\r\n\t<div style=\"\">\r\n\t\t<a href=\"http:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-count=\"vertical\" data-text=\"How to animate spots on Tilemap - iUridium\" data-url=\"https:\/\/www.iuridium.com\/?p=277\"  data-via=\"iuridium\">Tweet<\/a>\r\n\t<\/div>\r\n\t<br\/>\r\n\t<script type=\"text\/javascript\" src=\"http:\/\/platform.twitter.com\/widgets.js\"><\/script>","protected":false},"excerpt":{"rendered":"<p>This issue gave me a lot of headache, so just want to share it with you. If may help you, I will be more then happy \ud83d\ude09 I have a large parallax background and just wanted to animate one spot on my map. What I needed you can see in iUridium video at this link [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[10,8,9],"_links":{"self":[{"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/posts\/277"}],"collection":[{"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=277"}],"version-history":[{"count":17,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/posts\/277\/revisions"}],"predecessor-version":[{"id":459,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=\/wp\/v2\/posts\/277\/revisions\/459"}],"wp:attachment":[{"href":"https:\/\/www.iuridium.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iuridium.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}