hi
Im making a breakout clone for j2me midp2 phones and im having some trouble with timebased movement(i think thats the problem)…
Here is my moveBall method that should make the ball move 20 pixels pr second.
private void moveBall(double elapsedTime) {
float speed = 20; // adjust by experiment
double bxmov = (speed * elapsedTime) / 1000;
double bymov = (speed * elapsedTime) / 1000;
ut("bxmov double = "+bxmov);
if (!ball.isDirectionXPositive()) {
bxmov *= -1;
}
if (!ball.isDirectionYPositive()) {
bymov *= -1;
}
//System.out.println("bxmov=" + bxmov);
ball.setSpeed((int)bxmov, (int)bymov);
wallCrashCheck();
brickCrashCheck();
//ball.setPosition(ball.getX() + bxmov, ball.getY() + bymov );
ball.setPosition(ball.getX() + ball.speedX(), ball.getY()
+ ball.speedY());
}
The sleep of the main loop is 20 milliseconds.
This gives different problems. Some times the bxmov is less then 1 or 0.67 etc. that makes the ball move 0 pixles on that frame. This works on the emulator actually, the ball moves quite slowly but ok,and it hits all the bricks ( its a breakout clone) and the collision code works properly.
When i transfer the game to my mobile phone SE K750i it runs like crazy…the ball moves very fast and it just runs through the bricks. IS there something wrong with my timecode or should I just add to the collision detection so that it calculates a hit when the ball moves too far?
How can I make sure that if the game runs on nokia phone it wont act crazy because of different sleep times etc…even if i sleep 20 milliseconds, will it sleep 21 milliseconds on SE and 25 ms on nokia and 50 ms on the emulator?
Developing for j2me wasnt as easy as i thought. Lots of problems hehe :
If someone wants to look at the full source it is here:
http://www.vestheimonline.com/bricker2mesource.zip