Programming

Accurate Timing With Actionscript 3

     Finally made some time to update my blog!!! I've been working hard and added lots of new classes to my library which i used for my own games. I'll be updating this site with new classes and examples over the coming months - so be sure to stay tuned for all the updates!

     First on the list is the problem of timers and timing in general with Flash. Well not with flash as such, but with the web browsers. It seems that the flash player plugins for web browsers aren't very accurate at all when it comes to timing. You can ask flash in AS3 for any timer delay you like (from 1ms upwards). But the flash player will not deliver such small resolutions and even on larger delays, has a big variation between TimerEvents firing. I've written my own timing code, and implemented my own timers in AS3 and added them to my ever expanding library for anyone to use! Read on if you want to know how and why you would use these classes.

Actionscript 3 Sprite Trails

     I need a simple sprite with a small trail for a game i'm working on so i had to create some way of tracking sprites and giving them a trail. Heres the simple demo i've created - i wonder if someone could turn it into a game idea? It's just some round blobs "swimming" from left to right. It's pretty rough, but atleast you can see what i mean by sprite "trails".

Actionscript 3 Animated Sprite Engine Library

     Finally had time for an update! Here are the animated sprite classes that i've mention before, which are being used in my nearly finished game. I've done some basic testing and built the main base for my animation system (i'll extend it to animated tiles for backgrounds later). I couldn't find an animated bitmap class on the web for Actionscript 3 that i could use for my specific requirements - so i've made my own. Heres a quick run down of the features:

  • Simple XML animation format
  • Unlimited number of "states" to define different actions for each sprite
  • Each frame can be any size rectangle, located anywhere on the animation image (not just repeating rectangles like most systems)
  • Possiblity to have huge sprites (can use multiple images for a single sprite - only limited to 2880 bitmap size maximum per asset)
  • A frame can be located anywhere on the image and can reuse a frame multiple times in a single state aswell as across multiple states
  • Optional handle/hotspot for handling sprites instead of top left
  • Minimizes overdraw by specifying smallest rectangles not just fixed width & size for each frame (handy for bin packing images)
  • No loop, normal looping or ping-pong style animation looping
  • Play animation forwards or backwards
  • Start animation at any frame, and jump to any frame
  • Allows both animated sprites & bitmaps (sprite has a child bitmap)
  • Clone animatedBitmaps to save processing the XML file multiple times
  • FRAME_CHANGED and ANIMATION_COMPLETE events
  • Play animation once, loop animation infinitely or specify number of loops
  • Each frame can have a specific number of milliseconds delay, allowing fine control over complex animations
  • Sprite animation playback speed can be adjusted to slowdown or speedup the whole animation on the fly
  • Set current state by statename as well as index
  • Uses ENTER_FRAME instead of timers for animation update (useTimer option if you want to use timers for specific animations)
  • Stagelayer object to separate animated sprites/bitmaps into layers (needed for ENTER_FRAME and handy for collisions)
  • 4 Different Rendering methods for memory use vs speed (and for different requirements as one type doesn't fit all)
    • FRAME_BUFFER_REFERENCE (uses original bitmapData & scrollRect)
    • FRAME_BUFFER_OVERSIZED (uses a single growing bitmapData & copyPixels)
    • FRAME_BUFFER_CACHED (uses a seperate bitmapData for each frame & caches it when first generated with copyPixels)
    • FRAME_BUFFER_UNIQUE (uses a new bitmapData & copyPixels everytime the frame changes)
  • Uses frame time delta with smoothing for smoother animation (includes option to turn it off)

Plans for this blog and actionscript programming

     I've finally decided what to focus on with this blog - developing a general purpose game library to assist in helping people make games easier. I'm actually writing a lot of base code to use in my own games (like the hittest function i blogged about earlier). At the moment, i can't find a decent fairly complete set of libraries to do basic things needed for games in actionscript 3. Theres a lot of good stuff out there, but none of it is integrated with anything else, so you have to spend a fair bit of time hacking things together. So i've changed my mind as to this blog's use - i was going to use it to post snippets of code here and there when i found out things in AS3 to help someone learn it like i am doing, but theres quite a few sites out there doing that already and plus you can't really produce lots of really helpful code in small snippets.

AS3 Preloader With MochiAd, MochiBot, Simple Domain Locking and Glossy Vista Style Progress Bar

     As promised in my last blog entry, heres my version of an AS3 preloader. It's the second time i've typed this out, as the first time i had lost my cookies while messing around in another firefox window and when i came to post this entry it just said access denied and it had all gone! Lovely! Anyway the main points of my preloader are

  • MochiAds & MochiBot already integrated
  • Simple domain site locking implemented
  • Nice glossy style progress bar
  • Reusable code, not integrated heavily into a project
  • Easy to add to existing AS3 project
  • Pure AS3 classes
  • Works with FlashDevelop or Flex Builder
  • Minimal Delays, fairly small size

And most of all i'm giving all the source code away, not just snippets :)

Vista Glossy Progress Bar In Actionscript 3

     This time i wanted to make a nice progress bar for the preloader i've made. First of all, the usual check of Google. Plenty of hits, mostly for AS2 - a few for AS3 but nothing that takes my fancy. I did see a nice turning "barbershop pole" stripe bar, which i started out aiming for but before i'd written much code i figured a nice thing to do would be to simulate the nice glossy progress bars seen in windows vista. If it hasn't got anything else right, it has nice progress bars. Even though they still run on "microsoft time" and hardly give you a good indication of how long something is going to take, they do stand out and look the business.

Cleaning Up After Yourself In Actionscript 3 (Lack Of Class Destructors)

     Haven't written anything on here in a few days, been busy learning more AS3 and getting on with my 2 current game projects. I've got a list of things todo, plus some things i've found out about actionscript as i'm learning which might be helpful to others.

     My background is from all sorts of programming, i think a rough list is BASIC, PASCAL, AMOS, BLITZBASIC, AREXX, ASM (680x0), C, C++, ASM (80x86), LUA and now Actionscript 3. Having spent a lot of time with C++ and Delphi (oop pascal) i've got quite used to doing things in a certain way. Actionscript 3 in Flash 9 is pretty good so far, certainly i could never have created anything useful in flash previously - i think i have two left thumbs ;). I can just about "operate" paintshop pro/photoshop, but haven't really produce anything i'd be in a hurry to show! So flash and it's designer friendly interface wasn't for me. Since choosing AS3 as my new language to work on, it's been a slow start - but getting better, theres a definite way to do things with is a bit different. 

Actionscript 3 hitTestObject and Pixel Perfect Collision Detection

     For a flash game project, i needed to see if a number of sprites had collided. I soon found out that hitTestObject doesn't support perfect collisions for non-shape sprites, so i needed another solution.

     After wasting some time discovering hitTestObject only supports bounding rectangles for non shape sprites, i needed to find a pixel perfect collision detection method that worked on any sprites. One of the ways i've done it in the past is quite common, and has been used a lot over the years. You can approximate most sprites fairly well using a series of circles to form a collision detection area. Then it's fairly easy and reasonably fast to see if any circles have collided. This time however, i wanted to use pixel perfect accuracy, but i wasn't sure if flash was powerful enough to cope with such a task. It turns out that Flash Player 9 and actionscript 3 handle the job reasonably well with a clever bit of code from some smart cookies.

Getting Started With Actionscript 3

A little howto on setting up your open source AS3 programming IDE, what to download and some installations tips!

      So you want to start programming in actionscript, outside of Adobe CS3? I'd recommend trying FlashDevelop. I use it for all my flash/flex development at the moment, and even when i purchase CS3 or Flex i'll probably still use FlashDevelop for pure coding. It offers a very clean interface, works well and doesn't have to much in the way of clutter. There are other options, such as Eclipse (with FDT Powerflasher) or obviously Adobe Flex Builder 3. I'll be concentrating mainly on Flashdevelop, as i've found this is simple and fairly straight forward to use.


Theme & Icons by N.Design Studio
Syndicate content