{"id":416,"date":"2011-09-24T16:42:07","date_gmt":"2011-09-24T15:42:07","guid":{"rendered":"http:\/\/www.aymericlamboley.fr\/blog\/?p=416"},"modified":"2011-09-26T18:29:15","modified_gmt":"2011-09-26T17:29:15","slug":"introduction-to-embed-art-in-the-citrus-engine","status":"publish","type":"post","link":"http:\/\/www.aymericlamboley.fr\/blog\/introduction-to-embed-art-in-the-citrus-engine\/","title":{"rendered":"Introduction to Embed art in the Citrus Engine"},"content":{"rendered":"<p>Update : using metadata tag Embed is not the easiest path if you want to target iOS, take a look on this post using <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/finally-using-swc-in-the-citrus-engine\/\" target=\"_blank\"><strong>SWC<\/strong><\/a>.<\/p>\n<p>Today this is a quick post based on an older one : <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/create-objects-and-art-in-the-citrus-engine\" target=\"_blank\">Create objects and art in the citrus engine<\/a>.<\/p>\n<p>If you want to target iOS platform for your game, you must know that you can&#8217;t load swf at runtime. Indeed all your data must be &#8220;packaging&#8221; in one file an .ipa. So you are not able to load external data. To pass over that restriction, you need to use the metadata tag Embed properties. This is a blog post for <a href=\"http:\/\/www.bit-101.com\/blog\/?p=853\" target=\"_blank\">Embedding Ressources with AS3<\/a>.<\/p>\n<p>So, what we will do today is to adapt the previous post to be able to target iOS. I don&#8217;t have enough time to do it entirely, so this will only be an introduction, sorry.<\/p>\n<p>Let&#8217;s start now : on your level.fla add AS code to embed some assets :<\/p>\n<pre lang=\"actionscript3\">[Embed(source=\"..\/..\/assets\/grass.png\")]\r\nvar GrassPic:Class;\r\nGrass.picture = GrassPic;\r\n\r\n[Embed(source=\"..\/..\/assets\/elements.png\")]\r\nvar BackgroundElementPic:Class;\r\nBackgroundElement.picture = BackgroundElementPic;\r\n\r\n[Embed(source=\"..\/..\/assets\/background.png\")]\r\nvar BackgroundPic:Class;\r\nBackground.picture = BackgroundPic;\r\n\r\n[Embed(source=\"..\/..\/assets\/objects\/Roseau.swf\")]\r\nvar RoseauAnim:Class;\r\nRoseau.animation = RoseauAnim;<\/pre>\n<p>Here we are using the dynamic property of MovieClip, more information about it : <a href=\"http:\/\/livedocs.adobe.com\/flash\/9.0\/main\/wwhelp\/wwhimpl\/common\/html\/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000786.html\" target=\"_blank\">Adobe doc<\/a>. Don&#8217;t forget to name your stage MovieClip!<br \/>\nThen into your background MovieClip add this code :<\/p>\n<pre lang=\"actionscript3\">var className = \"com.citrusengine.objects.CitrusSprite\";\r\nvar params = {\r\n\tview: this.picture\r\n}<\/pre>\n<p>Don&#8217;t forget the <em>this<\/em> or it will not work! Now, your asset is embed \ud83d\ude09<br \/>\nIt is really easy to embed graphics, but what about SWF ? How can we handle animation on this ?<\/p>\n<p>Go back into our two older methods : roseauTouche &#038; roseauFin. And change the code for :<\/p>\n<pre lang=\"actionscript3\">private function _roseauTouche(cEvt:ContactEvent):void {\r\n\t\r\n\tif (cEvt.other.GetBody().GetUserData() is Hero) {\r\n\t\t\r\n\t\t ((MovieClip(SpriteArt(view.getArt(cEvt.fixture.GetBody().GetUserData())).content).getChildAt(0) as DisplayObjectContainer).getChildAt(0) as MovieClip).gotoAndPlay(\"white\");\r\n\t}\r\n}\r\n\r\nprivate function _roseauFin(cEvt:ContactEvent):void {\r\n\t\r\n\tif (cEvt.other.GetBody().GetUserData() is Hero) {\r\n\t\t\r\n\t\tvar roseauMC:MovieClip = MovieClip(SpriteArt(view.getArt(cEvt.fixture.GetBody().GetUserData())).content);\r\n\t\tvar loader:Loader = roseauMC.getChildAt(0) as Loader;\r\n\t\tvar mc:MovieClip = (loader as DisplayObjectContainer).getChildAt(0) as MovieClip;\r\n\t\tmc.gotoAndPlay(\"black\");\r\n\t}\r\n}<\/pre>\n<p>Dammit!! It is the same code for this two functions, the first is just more condensed. I will not explain more, because I&#8217;m always surprised of those lines&#8230; \ud83d\ude00 However you can find informations <a href=\"http:\/\/www.actionscript.org\/forums\/showthread.php3?t=230318\" target=\"_blank\">here<\/a> and <a href=\"http:\/\/www.bit-101.com\/blog\/?p=1435\" target=\"_blank\">there<\/a>.<\/p>\n<p><a href=\"http:\/\/www.aymericlamboley.fr\/blog\/wp-content\/uploads\/2011\/09\/CitrusArtV2.zip\"><strong>My zip<\/strong><\/a>. There is some problem with hero movement (jump and move to travel) due to the update on the last CE&#8217;s version. I don&#8217;t know where it comes from, but you can use it without problem. I made some test from scratch and it works \ud83d\ude09<\/p>\n<p>I know that there is lot of works to do from there, but that&#8217;s a good start. You need to put your level into an asset in your state finally, and see what happen. You would write a new function to ObjectMaker to enable that, probably.<\/p>\n<p>I wouldn&#8217;t dig into it more, because I&#8217;m not sure it is the best way&#8230; It is a bit complex if you want to manage animation. The updateAnimation method of PhysicsObject class doesn&#8217;t work this way. And moreover there is an other method to embed data :<br \/>\n&#8220;Remember you can specify a MovieClip linkage ID as your view property rather than a path to a SWF\/PNG. If you&#8217;re using Flash Develop, FDT or Flash Builder, you can embed your MovieClip graphics that you made in the Flash IDE using SWCs&#8221;.<\/p>\n<p>Anyway that was a cool introduction to embed assets, isn&#8217;t it ?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update : using metadata tag Embed is not the easiest path if you want to target iOS, take a look on this post using SWC. Today this is a quick post based on an older one : Create objects and art in the citrus engine. If you want to target iOS platform for your game, &hellip; <a href=\"http:\/\/www.aymericlamboley.fr\/blog\/introduction-to-embed-art-in-the-citrus-engine\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Introduction to Embed art in the Citrus Engine<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[4,51,33,11],"tags":[82,15,50,37,34,81,36],"_links":{"self":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/416"}],"collection":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":11,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":420,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/posts\/416\/revisions\/420"}],"wp:attachment":[{"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.aymericlamboley.fr\/blog\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}