{"author_name":"triplefox","cat":"LD #17 - Islands - 2010","comments":[],"epoch":1272116100,"likes":0,"metadata":{"p_key":"71149","p_author":"triplefox","p_authorkey":"391","p_urlkey":"106970","p_title":"Pincer \u2013 HUD and ammo","p_cat":"LD #17 - Islands - 2010","p_event":"LD17","p_time":"1272116100","p_likes":"0","p_comments":"0","p_status":"UPD5","us_key":"391","us_name":"triplefox","us_username":"\/author\/triplefox\/","event_start":"1271980800","event_key":"3","event_name":"LD17"},"text":"<p><a href=\"http:\/\/dl.dropbox.com\/u\/254701\/ld17\/8_25_am.swf\">Another build<\/a>, this one came almost an hour and a half after the last one. This one now shows the controls so I don&#8217;t have to go and write that here every time \ud83d\ude1b It also has limited ammo &#8211; you get one shot from the pickup.<\/p>\n <p>Something cool I used for this is a bit of code I had lying there, not sure that it would come to use: Layout.<\/p>\n <p>This is Layout:<\/p>\n <p><span id=\"more-17496\"><\/span>package fireball.gfx.util;<\/p>\n <p>import flash.display.DisplayObject;<\/p>\n <p>class Layout<br \/>\n {<\/p>\n <p>public static inline function sTopbTop(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px);<br \/>\n }<\/p>\n <p>public static inline function sTopbCenter(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px-ti.height*0.5);<br \/>\n }<\/p>\n <p>public static inline function sTopbBottom(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px-ti.height);<br \/>\n }<\/p>\n <p>public static inline function sCenterbTop(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES*0.5+px);<br \/>\n }<\/p>\n <p>public static inline function sCenterbCenterY(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES*0.5+px-ti.height*0.5);<br \/>\n }<\/p>\n <p>public static inline function sCenterbBottom(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES*0.5+px-ti.height);<br \/>\n }<\/p>\n <p>public static inline function sBottombTop(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES-px);<br \/>\n }<\/p>\n <p>public static inline function sBottombCenter(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES-px-ti.height*0.5);<br \/>\n }<\/p>\n <p>public static inline function sBottombBottom(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.YRES-px-ti.height);<br \/>\n }<\/p>\n <p>public static inline function sLeftbLeft(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px);<br \/>\n }<\/p>\n <p>public static inline function sLeftbCenter(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px-ti.width*0.5);<br \/>\n }<\/p>\n <p>public static inline function sLeftbRight(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(px-ti.width);<br \/>\n }<\/p>\n <p>public static inline function sCenterbLeft(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES*0.5+px);<br \/>\n }<\/p>\n <p>public static inline function sCenterbCenterX(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES*0.5+px-ti.width*0.5);<br \/>\n }<\/p>\n <p>public static inline function sCenterbRight(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES*0.5+px-ti.width);<br \/>\n }<\/p>\n <p>public static inline function sRightbLeft(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES-px);<br \/>\n }<\/p>\n <p>public static inline function sRightbCenter(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES-px-ti.width*0.5);<br \/>\n }<\/p>\n <p>public static inline function sRightbRight(ti : DisplayObject, px : Float) : Int<br \/>\n {<br \/>\n return Std.int(Game.XRES-px-ti.width);<br \/>\n }<\/p>\n <p>}<\/p>\n <p>Very simple, but highly useful. On all the functions that take an x and y coordinate, I can pass in Layout functions to transform them.<\/p>\n <p>However, I have a flaw in how I&#8217;m doing font rendering that is going to limit the utility of Layout for this game. The flaw is &#8211; Flash does not autosize TextFields at the moment of instantiation, as far as I can tell. Not only that, but I don&#8217;t use TextFields directly; I render them to bitmaps, because I want to cache that data. Hence to get around these flaws I&#8217;m oversizing the surfaces I draw the text to with a bad heuristic(32px height and width per character).<\/p>\n <p>I think that in the future I may switch to a solution based on the <a href=\"http:\/\/lab.polygonal.de\/2009\/12\/15\/font-rendering-with-the-fp10-drawing-api\/\">Polygonal library&#8217;s font rendering solution<\/a>. Although it&#8217;s a little bit cumbersome(compilation process vs. drop in a ttf), a little bit less Flash-friendly, this will give me good data to work from, and the basic render speed is faster too.<\/p>","time":"April 24th, 2010 8:35 am","title":"Pincer \u2013 HUD and ammo"}