Hi,
Iam need of help,my problem is iam constructing a brick game,in this game we have bricks with 3 diff colors they needs to be moving on the screen from top to bottom of canvas class and if we arrange the same colored bricks in a row it must be added to the score,but the problem is when iam trying to move the image from top to bottom its moving at time to down,so i need help to move the image with the controled speed but if i use delay in canvas class its giving error or if i use threads its not controling and if i use thread in the canvas class iam getting error.
What kinda of error?
- compile-time-error
- runtime-time-error
Give the name of the error, and if it is a runtime-error, also give the stacktrace.
Maybe even better to show some relevant code (not more than 20 lines) so that we know what you are actually doing.
[quote]i use delay in canvas class its giving error
[/quote]
As far as I know, System.currentTimeMills() is rather exact in J2ME…
So you can rely on it, while implementing bricks movement.
try to do something like this:
private long lastUpdateTime;
private final static int MOVE_TIMER = 300;
public void moveBrick(){
if (System.currentTimeMillis() - lastUpdateTime > MOVE_TIMER){
lastUpdateTime = System.currentTimeMillis();
// ... move-your-brick-code goes here
}
}
As far as I know, System.currentTimeMills() is rather exact in J2ME…
So you can rely on it, while implementing bricks movement.
try to do something like this:
private long lastUpdateTime;
private final static int MOVE_TIMER = 300;
public void moveBrick(){
if (System.currentTimeMillis() - lastUpdateTime > MOVE_TIMER){
lastUpdateTime = System.currentTimeMillis();
// ... move-your-brick-code goes here
}
}
[/quote]
currentTimeMilis() is not accurate on windows. nanoTime() is better.