954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

diffrence of move function speed on devices

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

mahdi68
Junior Poster in Training
95 posts since Jun 2009
Reputation Points: 6
Solved Threads: 0
 

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

adams161
Posting Whiz in Training
281 posts since May 2008
Reputation Points: 31
Solved Threads: 27
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: