screen updates don't match program logic/state or order

Discussion in 'Javascript' started by robert, Aug 23, 2003.

  1. robert

    robert Guest

    hi!

    there's a line in my Javascript program that makes a change in the
    appearance of an area of the screen. it is a game program, so there are
    a cascade of changes after the user makes a move. these are carefully
    sequenced and timed in a loop which contains the "action" statement

    document.images[k].src = offGIF[currNode];

    unfortunately, the *actual* screen updating appears to be 1)
    asynchronous and 2) faulty!

    _asynchronou_s in that things change in the wrong order, as if each has
    its own thread and they run at random.

    _faulty_ in that occasionally an area that would change from, say,
    picture1.gif to picture2.gif and back again (according to game logic)
    lands up showing picture2.gif. even though the internal game logic has
    it recorded (and i assume document.images[k].src would be correct, even
    though the screen is not) as picture1.

    so.

    is there a way to wait or surrender control to the system until the
    program statement's intent has actually been rendered to the screen?
    something i can test to see if the unerlying system mechanism has caught
    up with all changes to document.images?

    -- rob
     
    robert, Aug 23, 2003
    #1
    1. Advertising

  2. robert wrote:
    > hi!
    >
    > there's a line in my Javascript program that makes a change in the
    > appearance of an area of the screen. it is a game program, so there are
    > a cascade of changes after the user makes a move. these are carefully
    > sequenced and timed in a loop which contains the "action" statement
    >
    > document.images[k].src = offGIF[currNode];
    >
    > unfortunately, the *actual* screen updating appears to be 1)
    > asynchronous and 2) faulty!
    >
    > _asynchronou_s in that things change in the wrong order, as if each has
    > its own thread and they run at random.
    >
    > _faulty_ in that occasionally an area that would change from, say,
    > picture1.gif to picture2.gif and back again (according to game logic)
    > lands up showing picture2.gif. even though the internal game logic has
    > it recorded (and i assume document.images[k].src would be correct, even
    > though the screen is not) as picture1.
    >
    > so.
    >
    > is there a way to wait or surrender control to the system until the
    > program statement's intent has actually been rendered to the screen?
    > something i can test to see if the unerlying system mechanism has caught
    > up with all changes to document.images?


    Loading images takes time, if you assign to
    imgElement.src
    then the statement just triggers the change and then returns.
    If needed you can use the onload handler of the img object
    imgElement.onload = function (evt) {
    imgElement2.src = 'whatelse.gif';
    }
    imgElement.src = 'whatever.gif';

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Aug 23, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kris Dugan

    Need constant screen with periodic updates

    Kris Dugan, Jun 7, 2004, in forum: C Programming
    Replies:
    8
    Views:
    343
    Thomas Dickey
    Jun 8, 2004
  2. Hemkesh
    Replies:
    1
    Views:
    360
    Nigel Wade
    Feb 20, 2009
  3. spike
    Replies:
    8
    Views:
    1,486
    Steve Holden
    Feb 9, 2010
  4. Kris Dugan

    Need constant screen with periodic updates

    Kris Dugan, Jun 7, 2004, in forum: Perl Misc
    Replies:
    11
    Views:
    223
    Joe Smith
    Jun 9, 2004
  5. ccc31807

    logic question for text file updates

    ccc31807, Mar 26, 2010, in forum: Perl Misc
    Replies:
    11
    Views:
    174
    Xho Jingleheimerschmidt
    Mar 27, 2010
Loading...

Share This Page