in my menu i move the text from right to left on selection
Start Game
Options
Exit
to do this i update the x , y values during drawing the string in the loop of the canvas class
but its too slow on nokia phones and old phones is there any other way to fast this proccess
Here is CanvasClass that extends GameCanvas
- Code: Select all
package gamedemov_1_3_2;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
public class CanvasClass
extends GameCanvas implements Runnable {
public static LayerManager m_GameLayerManager ;
public static volatile Thread animationThread = null;
public static Graphics graphics;
public static boolean m_bRunning = false;
public static boolean inMenu = true;
private static final int SLEEP = 30;
private boolean allowKeys = true;
public static int m_iWidth; // To hold screen width
public static int m_iHeight; // To hold screen height
public CanvasClass() {
super(true);
m_bRunning = true;
m_GameLayerManager = new LayerManager();
setFullScreenMode(true);
m_iWidth = getWidth();
m_iHeight = getHeight();
graphics = getGraphics();
MainMenu.initMenu();
}
//main_game_loop
public void run() {
try {
while (m_bRunning) {
if (MainMenu1.isActive) {
MenuInput();
if(MainMenu.onFire == 1){
MainMenu1.x1 = MainMenu1.x1 - 3;
if (MainMenu1.x1 <= -140) {
MainMenu1.x1 = 2;
MainMenu1.onFire = 0;
MainMenu1.onFireMenu();
}
}
}
MainMenu1.DrawScreen(graphics);
flushGraphics();
Thread.sleep(1);
}
else {
GameInput();
if(GameClass.run()){
GameClass.DrawScreen(graphics);
flushGraphics();
}
Thread.sleep(SLEEP);
}
}
} //end while
catch (InterruptedException ie) {
System.out.println(ie.toString());
}
}
synchronized void start() {
m_bRunning = true;
animationThread = new Thread(this);
animationThread.start();
}
static synchronized void stop() {
m_bRunning = false;
animationThread = null;
}
public void MenuInput() throws IOException,
MIDletStateChangeException {
int keyCode = getKeyStates();
MainMenu1.input(keyCode);
}
public void GameInput() {
int keyCode = getKeyStates();
GameClass.input(keyCode);
}
}
}
Here is Draw screen method in my Menu class
sry i didnt post all the class bcz its to large and not optimized yet
- Code: Select all
public static void DrawScreen(Graphics g) {
g.setColor(0, 0, 0);
g.fillRect(0, 0, 90, 100);
CanvasClass.m_GameLayerManager.paint(g, 0, 0);
g.drawImage(m_BGImg, 0, 0, Graphics.TOP | Graphics.LEFT);
for (int i = 0; i < menuItems.length; i++) {
g.setColor(colorR[i], colorG[i], colorB[i]);
g.drawString(menuItems[i], x1, (i * y), Graphics.TOP | Graphics.LEFT);
}
g.setColor(255, 255, 255);
g.drawString(m_sSelectKey, 0 , CanvasClass.m_iHeight-15 , Graphics.TOP | Graphics.LEFT);
g.drawString(m_sBackKey, CanvasClass.m_iWidth-28 , CanvasClass.m_iHeight-15 , Graphics.TOP | Graphics.LEFT);
}
I also used this way
calculating the frames per second then moving the text based on FPS
- Code: Select all
public long m_lPreviousFrameTime = 0;
public long m_lFrameTimeDelta = 0;
..
..
long lCurrentTime = System.currentTimeMillis();
m_lFrameTimeDelta = lCurrentTime - m_lPreviousFrameTime;
m_lPreviousFrameTime = lCurrentTime;
..
..
long lSpeed = 2 * (m_lFrameTimeDelta/10);
Menu.x1 = (Menu.x1 - (int)lSpeed);
if (Menu.x1 <= -140) {
Menu.x1 = 2;
Menu.onFire = (byte)0;
Menu.onFireMenu();
}
its a little bit faster but its not moving smoothly
it keeps flickering
thx in advance
