Hi
please look this code , when i run it on nokia N97 it`s run very slow but i test it on samsung corby it`s run true , i think if i use game canvas problem be sloved . what should i do to solve this problem .

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.microedition.lcdui.*;

/**
 * @author mahdi
 */
public class MIDPCanvas extends Canvas implements Runnable {

    Graphics g;
    Image img;
    int x = getWidth() / 2;
    Display display;

    public MIDPCanvas(Display display) {

        this.display = display;
        try {
            img = Image.createImage("/pic.jpg");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    protected void paint(Graphics g) {
        g.drawImage(img, x, getHeight() / 2, Graphics.VCENTER | Graphics.HCENTER);
        display.callSerially(this);
    }

    public void run() {
        try {
            Thread.sleep(10);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        x--;
        repaint();
    }
}

its run on wtk very fast but in other emulator like LG or nokia its slow
thanks

I don't know anything about these phones but I've been tracking CPU use in a phone drawing program, and one key thing to control is number of times you repaint the screen. also if you repaint, if possible specify the rectangle to repaint in, repaint by itself draws the whole screen.

Mike

as already pointed out by adams you are refreshing your graphic to much (actually 100 times per second). You should do it something about 15-20 times per second, but may be even less...
Do not relay on emulator as hat is using your processor and it will much faster then real device

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.