Blog

  • Dish Network is Opt-Out Telemarketing

    I just got a telemarketing call on my cellphone from Dish Network trying to sell me on getting Cinemax. I’d cancel it, except my wife digs TV and I don’t have a neighbor I can watch SciFi Friday at.

    I just called and changed the contact number to my wife’s cell, and apparently they can enter a note to put it on the do not call list. Sounded to me like she was typing a custom note in a TextBox created for customer wishes that’s saved in some obscure database table.

    I’m fixin’ to email them and see if I can get my 2 Cingular rollover minutes back. Maybe Cingular can block the number? This is a business phone so I can’t have telemarketers costing me time and money.

  • Diesel & Battlefield: ActionScript 3 Blitting Engine for Tile-Based Games

    Diesel is a blitting engine for Flash Player 8.5 using ActionScript 3. Uses 1 bitmap to paint to vs. using many DisplayObjects in an effort to utilize less CPU & RAM.

    Skip to Introduction if you want to know more about Diesel, or read on for background as to why I’m posting this.

    Contents

    Preface

    I was originally using this project as a part 2 & 3 followup to my blitting post, but realized it is a ton of work. Even getting simple benchmarks down on alpha software is pointless because many memory bugs are fixed in later versions, rendering your previous benchmarks worthless. For example, I’ve found a bug with flash.display.Loader where, if you issue a ton of loads, say over 1900, each load allocates almost a meg of memory. The problem is, even if you delete the loader as well as what it loads, the memory isn’t freed. This is known and will apparently be fixed in a later build.

    Not to mention I’m still learning ActionScript 3, so my style of coding has changed the more I learn, making it hard to keep 2 different approaches to a problem in sync: using Sprites vs. blitting to 1 bitmap.

    I will say this with confidence; blitting is far more scaleable than using a multitude of Sprites. While the memory usage for blitting is far below what the Sprites use, the processing isn’t what I’d hope it’d be. Additionally, I’d forgotten just how much RAM bitmaps can take. So, even if you make a 2880×2880 blank, transparent bitmap in RAM, it still takes about 44megs.

    I still believe, however, that blitting is the future of Flash games, and all I need to do is optimize the Diesel engine a bit more, and she’ll be a more attractive alternative to utilizing Sprites for game development.

    My original goal in posting was to show my older version of Battlefield, a simple tile-based map engine based on Sprites, and one based on Diesel. A milestone I had reached as getting the TileMap, a base class, to using blitting only, and scrolling via double-buffering (copying pixels from a larger bitmap, not-shown off-screen). While this made the map scroll really fast, when I started adding Sprites, it still kept a good refresh rate, but started using way more processor than I had experienced in earlier tests on a smaller scale using Flash Player 8.

    Frustrated, I realized I had to re-write even all of the sub-classes in Battlefield that rendered sprites, as well as the main walking character. I did so at the cost of not updating the older Sprite one with which to do benchmarking at a later date. Don’t care, though, because again, I feel blitting is worth spending more time on perfecting and optimizing.

    So, without further adu, I present a really early build of Diesel, a blitting engine, and Battlefield a simple tile-based engine example that uses Diesel.

    TOP

    Introduction

    With the addition of Bitmap classes in Flash Player 8, developers now have the ability to utilize blitting and double-buffering techniques to create resource efficient gaming engines in the Flash Player. Diesel is a set of ActionScript 3 classes that provide a conveinent display engine to take advantage of these new player features.

    TOP

    Why should I care?

    Diesel uses 1 bitmap to draw to vs. hundreds of MovieClips. This results in a more scaleable engine, allowing for more moving sprites, lower usage of RAM & Processor, and better refresh rates.

    TOP

    What’s wrong with MovieClips for games?

    While MovieClip’s are conveinant to code & design with, they are not efficient when dealing with a multitude of bitmaps for games. They also do not scale well when you need to create many of them, and have them all move on the screen at the same time. Finally, large bitmaps in Flash traditionally have not scrolled very fast when used as tile-based game backgrounds. You either have to use 1 large bitmap that is pre-rendered, or you can use tiles in the traditional sense, but neither is an optimal solution for games.

    Big bitmaps are not an ideal solution for a couple reasons. First off, it’s not dynamic; you have to create this before hand. While you can load it in dynamically, you have to use MovieClips atop it to generate any effects. Secondly, even if you mask a certain area of the screen, the rest of the bitmap is still drawn the screen, taking up a lot of processor & ram and sacrificing a good refresh rate (smoothness of the animation).

    For tile based games, you have 2 solutions. Either draw all of your tiles as multiple MovieClips, and have all of them created in one parent MovieClip. When moving your map, you simply move the main MovieClip that houses them. While this makes coding easy, it suffers from resource usage, namely reduced refresh rate, and it gets worse the more tiles you create. This is even before you start putting gaming sprites on the screen.

    Your other solution is to create the tiles on the fly based on the direction the character in the game moves. While this is a lot more scalable than the above, allowing you to create bigger maps, you suffer from redraw speed when creating the new tiles. The creation & destroying operations that you use on the tiles takes up a lot of processor, reducing the continual smoothness of your animations.

    TOP

    How is Diesel better?

    It uses a technique called double-buffering. By using 1 bitmap, you solve a bunch of issues MovieClips have traditionally caused. First, you have 1 bitmap, not hundreds. Each sprite in your game is represented as a data object, but it’s bitmap data is copied to the main big bitmap. All sprites are copied to this main big bitmap. This big bitmap is actually not shown, but is off-screen and not in the Display List. A portion (or all of it) is copied to an on-screen bitmap that is repainted when something moves or changes.

    This uses significantly less RAM because each sprite in your game is actually just a data object vs. a Sprite or MovieClip. You store basic information like x and y position as well as width and height as BitmapSprites. They are then added to the BitmapDisplayObject, much like you add MovieClips to the Display List. BitmapDisplayObject is just a flash.display.Bitmap that renders all of the BitmapSprites added to it’s list of things to draw.

    Additionally, the entire bitmap does not have to be drawn. For example, many tile-based games consist of a large map, but only a small portion is shown. For this reason, only a small portion of the map can be shown, and thus drawn, not the whole thing. So, when repainting, only those portions of the screen that need to be redrawn are, not the whole thing, nor things not shown.

    TOP

    Why not use the Display List in Flash Player 8.5?

    In my tests, Diesel uses less RAM, and uses less processor vs. using Sprites and the Display List.

    TOP

    How do I use it?

    Simply import the classes into your project. I’ve done my best to match the syntax like the ActionScript 3 flash.display.DisplayObject syntax.

    For example in ActionScript 3, if you want to create a sprite and show it, you do something like:

    import flash.display.Sprite;
    var my_sprite:Sprite = new Sprite();
    addChild(my_sprite);

    Diesel’s code works on the same concept of seperating the object from the actual drawing. However, instead of adding your BitmapSprite, the Sprite equivalent, to the normal Display List, you instead create a BitmapSpriteDisplayObject, and add your BitmapSprites to it. The BitmapSpriteDisplayObject class is just a flash.display.Bitmap with optimized code to handle drawing BitmapSprites.

    An example of creating a BitmapSprite, and showing it, just like you would create a Sprite to show it, is:

    import com.jxl.diesel.view.core.BitmapSpriteDisplayObject;
    import com.jxl.diesel.view.core.BitmapSprite;
    // create your BitmapSpriteDisplayObject
    var bsdo:BitmapSpriteDisplayObject = new BitmapSpriteDisplayObject();
    // add it to the Display List so it's shown
    addChild(bsdo);

    // now, create your BitmapSprite
    var my_bSprite:BitmapSprite = new BitmapSprite();
    // and add him to the BitmapSpriteDisplayObject
    bsdo.addBitmapSprite(my_bSprite);

    You can add and remove as many BitmapSprites as you want. Additionally, you can create multiple BitmapSpriteDisplayObjects.

    TOP

    Conclusion

    I am definately interested in contributions, suggestions, and/or criticisms. If you’re seriously interested in helping improve the engine so it performs like Andre Michelle wrote it, and/or taking Battlefield to another level, drop me a line in the comments, and I’ll hit you up with Subversion access.

    TOP

    Examples

    Example of Diesel & Battlefield drawing sprites on a walkable map. Click once on the tiles to give focus, and then use arrow keys to move.

    Example of Diesel loading tiles at runtime, extracting the bitmap data from a bunch of PNG’s, and drawing them to the map.

    TOP

    Source Code

    Diesel & Battlefield Source Code

    • SVN
      username: public
      password: public
    • SVN
    • ZIP (beta1) Get latest build from SVN

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 2.5 License.

    TOP

  • JXL on 2005

    The Bad

    I lost a good friend in the war. I got really scared I had potentially lost more in the bombing of London.

    Microsoft pays Real over a lawsuit. My wife’s new Alienware starts the year off badly, and ends up with a fried mother board. I still need to call support because it’s under warranty I hope, but I’m never buying another Alienware ever again, and I suggest you do not either. They are not all the hype makes them out to be, and their support is pathetic.

    The Weird

    Xamlon launches, headed by one of my Flash idols, only to mysteriously stay in beta. Haven’t really heard a lot of activity from this area. The inventor of the internet smokes crack when discussing his creation. It takes a full year for credit card usage at fast food restaurants to travel 20 miles up the highway finally reaching the exit where I live. The weirdest of all, the W3C wants to standardize RIA’s…wtf?

    The Surprises

    Everyone is taking pictures with their phones at New Years. It seems everyone uses a phone to take pictures now, and it’s the norm. Adobe acquires Macromedia. The last, great Central App is released. I saw AJAX not suck. I saw Laszlo not suck. Jakob Neilsen acknowledges Flash can have good uses, and suggests we use the v2 Flash components.

    The Cool & Good

    2005 started off just like 2004; every recruiter and their mom wanted qualified Flash Developers. I blogged for help. I’ve used that list garnered extensively over the year, removing only 1 name, and moving some names higher up the list based on needs & client feedback. Flash finally got a pimp RichTextEditor. Flashcom brought the world together. iTunes delivered music, but GameTap gave us games!

    I fell in love with open source Flash development via FAME, only to fall out of love end of year. By the end of the year, I was fed up with Flash for pure application development alone, and MTASC’s future, the open source compiler for Flash and the core of FAME, had its code start to freeze as it’s author pursues other endeavors. Beginning of the end for me in that realm.

    Dofus, a MMORPG (massively multiplayer online role-playing game) done in Flash becomes free. I was really irritated with the comments on that entry; it felt like people were doing everything in their power to dissuade any of the coolness factor from the client being done in Flash to how all powerful the server was. Not sure where the insecurity came from… maybe cause Flash proved itself in that defining moment?

    Yahoo! releases Yahoo! Maps, and makes good on Mike Chamber’s suggestion about Yahoo! "showcasing Flash" and how Yahoo! will help push the Flash Platform.

    Flex Builder 2 lights up the Web 2.0 conference. A super model digs Flash Lite. My man Darron Schall releases FlashVNC, which hints at the revolution Flash Player 8.5 will bring with it’s new features. This is corraborated by FlashTelnet and FlashAIM.

    Me Personally

    2005 was the year of Flex for me, most definately. I started the year hoping to spread the wonderful joy working in Flex is to other Flash Developers. I still had time for both Flash & Flex, even 2 years later still discovering new, useful classes in the v2 component framework. By the end of the year, I started to come to terms with being a Flex Developer vs. a Flash one.

    Still, Flash permeates my life, and SWF in general. My CaptivatePlayer gets so popular, it scores me a DevNet article. I actually had a lot of angst & frustration towards Macromedia and the direction they were taking Flash development earlier this year. I felt very left out, and squashed by stockholder interests. I respected that from a business point of view, but still felt personally betrayed. Thankfully, they shared a vision, got a lot of our feedback, and my faith is once again restored & renewed. I even managed to make it into Flash. In celebration, Guy and I enjoyed Margarits, Grapes, and Flash 8 Video.

    On a personal life note, a lot of closure was reached this year as well as some personal goals. I got to speak at MXDU again. I did my part to fight terrorism. I got a new router, a distaste for Cisco owned LinkSys, and a new respect for D-link. I graduated, and got my BA. I think my favorite part, though, was getting a new puppy, and celebrating my 1 year anniversary with my wife in Canada for some burn out therapy.

    Conclusion

    Being overally serious makes me feel uncomfortable. I guess that’s why the Web 2.0 explosion this year really irked me because people are so gung ho about this un-definable concept. I dig concepts, though, and I dig all the positivity, zeal, and desire to create & help people with technology that AJAX & Web 2.0 have helped contribute too. Hopefully next year Flash & Flex will add immensely as well.

    Till then, the 2 most important things for me this year were Storming Mortar with Ninja Wizards, and using Nigel Pegg’s DataGrid to save Microsoft.