Home | Rules and Guide | Sign In/Create Account | Write a Post | Reddit | #ludumdare on irc.afternet.org (Info)

Ludum Dare 26 — April 26th-29th Weekend — Theme: Minimalism

  • Judging Ends: in 20 hours, 2 minutes, 10 seconds
  • Play and Rate Games | View All Games | Edit | View My Entry
    Twitter | #ludumdare on irc.afternet.org

    [ Warmup Weekend | Real World Gatherings | Tools | Ludum Deals (yep, we got it) ]


    Pincer – HUD and ammo

    Posted by (twitter: @triplefox)
    April 24th, 2010 8:35 am

    Another build, this one came almost an hour and a half after the last one. This one now shows the controls so I don’t have to go and write that here every time :P It also has limited ammo – you get one shot from the pickup.

    Something cool I used for this is a bit of code I had lying there, not sure that it would come to use: Layout.

    This is Layout:

    package fireball.gfx.util;

    import flash.display.DisplayObject;

    class Layout
    {

    public static inline function sTopbTop(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px);
    }

    public static inline function sTopbCenter(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px-ti.height*0.5);
    }

    public static inline function sTopbBottom(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px-ti.height);
    }

    public static inline function sCenterbTop(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES*0.5+px);
    }

    public static inline function sCenterbCenterY(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES*0.5+px-ti.height*0.5);
    }

    public static inline function sCenterbBottom(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES*0.5+px-ti.height);
    }

    public static inline function sBottombTop(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES-px);
    }

    public static inline function sBottombCenter(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES-px-ti.height*0.5);
    }

    public static inline function sBottombBottom(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.YRES-px-ti.height);
    }

    public static inline function sLeftbLeft(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px);
    }

    public static inline function sLeftbCenter(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px-ti.width*0.5);
    }

    public static inline function sLeftbRight(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(px-ti.width);
    }

    public static inline function sCenterbLeft(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES*0.5+px);
    }

    public static inline function sCenterbCenterX(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES*0.5+px-ti.width*0.5);
    }

    public static inline function sCenterbRight(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES*0.5+px-ti.width);
    }

    public static inline function sRightbLeft(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES-px);
    }

    public static inline function sRightbCenter(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES-px-ti.width*0.5);
    }

    public static inline function sRightbRight(ti : DisplayObject, px : Float) : Int
    {
    return Std.int(Game.XRES-px-ti.width);
    }

    }

    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.

    However, I have a flaw in how I’m doing font rendering that is going to limit the utility of Layout for this game. The flaw is – Flash does not autosize TextFields at the moment of instantiation, as far as I can tell. Not only that, but I don’t use TextFields directly; I render them to bitmaps, because I want to cache that data. Hence to get around these flaws I’m oversizing the surfaces I draw the text to with a bad heuristic(32px height and width per character).

    I think that in the future I may switch to a solution based on the Polygonal library’s font rendering solution. Although it’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.

    Leave a Reply

    You must be logged in to post a comment.


    All posts, images, and comments are owned by their creators.

    [cache: storing page]