animation running slow on some computers

M

Mike Crenshaw

hi
I've made an applet doing an animation. The problem is that it runs great on
some computers and really slow on others. Even fast computers.. (2ghz and
up)..
here is what i do:

private Image background; //544 * 425
private Image object; //66 * 26
private Image doubleBufferImage; //544 * 425
private Graphics doubleBufferGraphics;
private int ox; //new position to draw object
private int oy; //same
....
public void paint(Graphics g) {
doubleBufferGraphics.setClip(0,0,background.getWidth(this),
background.getHeight(this));
doubleBufferGraphics.drawImage(background,0,0,this);
doubleBufferGraphics.setClip(ox, oy, object.getWidth(this),
object.getHeight(this));
doubleBufferGraphics.drawImage(object, ox, oy, this);
g.drawImage(doubleBufferImage, 0, 0, this);
}

any ideas?

heres the whole thing

import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;

public class Test extends Applet implements Runnable, KeyListener{

private Image background;
private Image object;
private Image doubleBufferImage;
private Graphics doubleBufferGraphics;
private MediaTracker tracker;
private int ox;
private int oy;
private Thread t;

public void init() {
tracker = new MediaTracker(this);
background = getImage (getCodeBase (), "background.gif");
object = getImage (getCodeBase (), "object.gif");
tracker.addImage(background,0);
tracker.addImage(object,1);
addKeyListener(this);
try
{
tracker.waitForAll();
}
catch(Exception e){System.out.println("error "+e);}
doubleBufferImage = createImage (background.getWidth(this),
background.getHeight(this));
doubleBufferGraphics= doubleBufferImage.getGraphics ();
}

public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e)
{
t = new Thread(this);
t.start();
}

public void run()
{
for (int i = 0; i < 25; i++)
{
ox +=20;
oy +=15;
paint(getGraphics());
}
ox=0;
oy=0;
}

public synchronized void paint(Graphics g) {
doubleBufferGraphics.setClip(0,0,background.getWidth(this),
background.getHeight(this));
doubleBufferGraphics.drawImage(background,0,0,this);
doubleBufferGraphics.setClip(ox, oy, object.getWidth(this),
object.getHeight(this));
doubleBufferGraphics.drawImage(object, ox, oy, this);
g.drawImage(doubleBufferImage, 0, 0, this);
}}
 
M

Magnus

I have a similar problem.
I never had this problem when running MS VM.
Now converted my applet to swing components and using sun plugin.
Are you using sun vm?
Did you solve the problem?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top