users
[Top] [All Lists]

RE: [cinjug-users] tracing a path

To: "Jason Kretzer" <jrkretzer@xxxxxxxxx>
Subject: RE: [cinjug-users] tracing a path
From: "Sam Corder" <samus@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Jun 2005 12:27:17 -0400 (EDT)
Cc: users@xxxxxxxxxx
Delivered-to: mailing list users@cinjug.org
Importance: Normal
In-reply-to: <20050603153251.38620.qmail@web50104.mail.yahoo.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <16950.64613.641000.962533@gargle.gargle.HOWL> <20050603153251.38620.qmail@web50104.mail.yahoo.com>
User-agent: SquirrelMail/1.4.4
On Fri, June 3, 2005 11:32 am, Jason Kretzer said:

> Some problems I have ran into.
>
> 1.) When just drawing the path(no image, just lines),
> the line would disappear if I moved the window off the
> screen.
> SOLUTION: Store all lines in a data structure and
> redraw them in the paint method.
> Extended issue:  needs to be done while drawing is in
> progress as well, in case another window is moved in
> front of the current one or the current one is
> minimized or moved off screen.

Alternate solution:
Only draw to your back buffer but don't clear it between animation frames.
 Then on the paint method of the canvas copy the back buffer image to the
front buffer.  This will give the continuous motion effect you are looking
for.  The problem with storing all of your lines is that over time it will
take longer and longer to draw a frame and your application will consume a
lot of memory.  You could alleviate it some by only drawing the last X
number lines but your program will still be doing a lot of unnecessary
work.  Unless you need to do some other kind of transform on the lines
after they have been plotted, storing that data is not necessary.

>
> 2.) Adding the animation.  I am using double buffering
> but I still get MAJOR flicker and jumpy behavior when
> drawing the line.

Are you using some kind of frame rate limiter?  i.e.

loop
{
  store start time

  calculate new point
  draw a line from the old point to the new point
  have an image move from the old point to the new point

  store elapsed time (current time - start time)
  Thread.sleep(1000 - elapsed time) //1 fps.
}

>
>
> It is with this problem, I have come to you. I know
> that you will probably need to see some source, so if
> you would like to help, email me and I will send you
> the source code.  I just did not want to spam the list
> with it.
>
> Thanks everyone.
>
> -Jason
>

Experiment with some free java games that give you the source.  You'll see
that most of them have an animation loop like above and draw to a back
buffer and then copy that to the screen buffer.  You'll also see that they
clear the back buffer between each frame.  If you comment out that line
you'll get this tearing/shadowy look on the screen.  I think javanoid has
the source available.  It's a decent arkanoid/break out clone.  Hope that
helps.

-Sam Corder


<Prev in Thread] Current Thread [Next in Thread>