Flixel Category

  • Using Flixel 2.5 and the Kongregate API

    Versions of Flixel before 2.5 had a handy little class called FlxKong, which neatly wrapped-up the Kongregate API and made it simple to use in your games. It was dropped in the 2.5 release however, and with the introduction of the new camera system and modified display list it made it a bit harder than before to get working. I wrote my own class to get around it, but after some posts on the flixel forums asking for help I figured it made sense to package my class into the Flixel Power Tools and release it.

    At the time of writing the class is only in the dev branch on github, but is pretty much feature complete and ready for use. Using it is simple, just import the class:

    import org.flixel.plugin.photonstorm.API.FlxKongregate;

    .. and then init the API. This downloads the Kongregate API SWF from their server and stores it locally for use:

    FlxKongregate.init(apiHasLoaded);
    
    private function apiHasLoaded():void
    {
    	FlxKongregate.connect();
    }
    

    The “apiHasLoaded” function is your own, it will be fired once the API SWF is downloaded. When this happens you can connect to it as above. The connection is pretty much instant, and you then have access to all of the API functions which I’ve exposed via the class, such as:

    FlxKongregate.isLocal
    FlxKongregate.isGuest
    FlxKongregate.getUserId
    FlxKongregate.getUserName
    FlxKongregate.showSignInBox
    FlxKongregate.showShoutBox
    FlxKongregate.submitStats
    
    etc etc 
    

    Also the api object itself is available via FlxKongregate.api, so you can call any service they have that I’ve not yet exposed in this class.

    There is a Test in the Demo Suite which shows how to use it. Here’s a direct link to the as file.

    Lots of the Kongregate API only works when your game is actually run on Kongregate itself. And equally lots of it such as micro-transactions don’t work at all unless your game is part of their private beta test. So don’t go calling functions randomly! Do check their documentation first.

    Using FlxKongregate without the Flixel Power Tools

    I fully understand if you don’t want to include the whole of my Power Tools library just to use this one class. So here’s how to make it run stand-alone:

    Download the FlxKongregate.as file from github and copy it into your src folder.

    Open it into FlashDevelop (or whatever editor you use) and edit the package. FlashDevelop will even prompt you that the package is wrong and automatically correct it! The default is:

    package org.flixel.plugin.photonstorm.API

    But if you have copied it into your src folder, you should remove everything after “package”. Equally if you have placed it into your own folder, you should make the package line reflect this.

    Once you’ve done that you can use the API as normal.

    Have fun 🙂

  • Video of me coding Breakout in Flixel in 20 mins

    Having spent the past couple of days deep in Microsoft Word writing tech specs, I was desperate to do some coding. But I only had a 1 hour lunch break available. So I picked a game: Breakout (Atari 2600 style), found a reference screen shot online to get the colours from, fired-up FlashDevelop, hit record and started coding.

    20mins later and it was done. I then hastily cut this video together and uploaded to YouTube (which ironically took longer than coding did). Here’s the video embedded. I sped it up x2 for sanity sake, and it’s a nice way of hiding my typos 🙂 If you can please watch it in HD on the YouTube site, it’s much easier to see what I’m coding!

    Watch on YouTube

    Ok so it’s not a gaming master-piece, but there’s a real solid shell of a game here you are free to take and expand as you wish. The first thing you may want to do is drop the “cheat wall” from the bottom, add some lives, a score and level progression 🙂

    Full source code after the jump.

    Read More

  • FlxBitmapFont – A Bitmap Font class for Flixel 2 released

    Today I released my FlxBitmapFont package to Google Code. This allows you to use bitmap fonts directly in your Flixel 2 games:

    The bitmap fonts are just an extension of a Flixel Sprite, meaning you can throw them around, collide with them, scale them, rotate them and generally cause havoc. Or of course they could just be UI elements, proving a score/lives count. But at least the choice is yours 🙂

    11 fonts are included, 2 sample programs and comprehensive documentation in the form of a PDF file. I’ve also published that here on my blog: http://www.photonstorm.com/flxbitmapfont and I will update both my blog and the Google Code archive as needed.

    Anyway I hope you have fonty fun with this! Look out for a number of new Flixel classes from me in the coming months, or catch me on the flixel forums where I help moderate the place.

  • Dealing with the FlxU.overlap kill in Flixel 2

    FlxU.overlap in Flixel 2 uses the new FlxQuadTree to handle collisions. It allows you to pass in either a single object (say an FlxSprite), a group of objects (FlxGroup), or even a group of groups! To be honest the more you give it, the more useful it proves to be.

    However it’s got one annoying side-effect: if you don’t specify a custom function to deal with the collision, it will kill() your objects. This is often a far from ideal end result. For example if you had a bullet and an enemy being compared – you may want the bullet to be killed instantly, but the enemy to be only “hurt” by this, reducing it’s health.

    The only way I’ve found to do this so far is to override the “kill” method of FlxSprite (in my Enemy class) and then perform the logic in there. Reduce health, update animation, health < 0, then kill it for real.

    This isn’t ideal, but it certainly works – so if you’re stuck in a similar bind with FlxU.overlap, this may help.

    Also it’s worth mentioning (as this caught me out too) – if you do specify a custom function for overlap, make sure it returns a Boolean. False will ignore the overlap, true will say you’ve dealt with it. If you don’t return this value it appears to default to killing your objects again.

  • FlxSnake – A simple Snake game for Flixel 2.23+

    I’ve been playing with Flixel a lot recently, and over on the forums someone was having trouble getting a “snake” game to work. I always applaud people who “start simple”, rather than diving in the deep end and sinking without trace.

    So I spent lunch time today knocking together a simple snake game in Flixel 2.23.

    There are no graphics (just blocks), but it shows how to use an FlxGroup to handle single to many collision checks, simple sprite controls and of course a basic snake game mechanic. The whole thing is just one single class file with no external requirements.

    It’s up on my GitHub account here: http://github.com/photonstorm/FlxSnake

    And if you want to join in, the forum thread is here: http://flixel.org/forums/index.php?topic=1261.0 (I’m a moderator on the Flixel forums, so drop by and say hi!)