The Source for Java Technology Collaboration
User: Password:



Chet Haase

Chet Haase's Blog

Timing is Everything

Posted by chet on February 15, 2005 at 02:06 PM | Comments (1)

In my Freebird! blog I got several requests for information/examples on writing time-based Java code. I've finally written an article and posted a source code project on this topic. The code builds upon the existing timing facilities in Java and adds some interesting higher-level functionality. The article explains how it all works. Check them out and let me know what you think.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • I read your timing article last week, but it wasn't until today that a thought struck me, which I thought I'd pass on.

    In a previous life I did a spot of games programming. This was long before the advent of 3D games consoles and the like, when everything (well mostly everything!) was 2D. Back in those days the movements of images around the screen (sprites, as they are now called - although strictly speaking that is an incorrect term) was typically controlled by mini-programming languages. Like a primitive bytecode, if you like. The hordes of enemy ships swirling down the screen in Galaxian (?) were in fact following simple patterns which moved them to relative or absolute points on the screen until particular cirsumtances were met (like they exited off the side of the screen).

    I wondered if your timing API might benefit from a similar tactic? It may be overkill, or it may be the flexibility needed to make your API really powerful. (Not sure myself - but I figured I'd mention it and see other thing!)

    The timer API would use an outer envelope, progressing down a series of 'bytecode' type instructions while controlling timings between events. Here's some rough example code:


    EVENT 0
    EVENT 1
    EVENT 2
    JUMP -3


    The above would fire events '0' to '2' repeatedly. The event instruction would fire an event, passing the value as a param in its event object. We might use the param to display a frame from an animation (frames 0 to 2 run repeatedly). The important thing to note here is that the envelope controls the overall timings, while the 'bytecode' controls the sequence of events, loops, etc.

    An abbreviated syntax might be possible, for events which follow in sequence. The below plays a ping-pong sequence 0, 1, 2, 1, 0, 1, 2 .... Adding simple condition instructions allows us to run a sequence a set numbe of times, before exiting or moving onto another sequence. (Factory methods could be used to auto-generate the 'bytecode' for very common sequences, like a basic A to B animation, or a ping-pong animation.)


    EVENT 0 TO 2
    EVENT 1
    JUMP -2


    The above is probably not a very good explaination - but hopefully it is suffcient to get the general idea across.

    Posted by: javakiddy on February 23, 2005 at 04:41 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds