×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Jun 2003
    Posts
    81

    Simple game do NOT imply simple solution...

    Hi!
    I'm trying to make a game where there are a number of balls bouncing (for now only with 45 degree angle) on a rectangular area and where you can controll a cursor moving horizontally or vertically in the same rectangular area.

    The problem seems to be very simple, but there are a lot of things to care attention in order to have the best result.

    There are 2 main targets that I would like to reach:
    1-smooth movement of balls
    2-very quick response to keypress event

    Unfortunately two targets are in conflic each other, because if you want a smooth movement you have to repaint practically every loop inside a while statement, but in this way you don't leave spaces for response key.

    If you put a sleep (also a sleep(5) !!) the balls movements becomes very slow, but unfortunately you don't get any improvements for the "response key problem".

    There is to note that every step I don't clean all the screen but only the previous point where there was the balls, and then I repaint only the balls in the next position.
    I have tried also to use fillRect insted balls image with the same results...

    Also using keyRepeated, the time from one cursor movement and the other (especially after the first button press) is too slow for my taget.

    I have to try to use more than one thread?

    Every advice, also the smallest, will be very appreciated!!!
    Many thanks in advance!

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    1

    I am also having this slow key response problem

    For some reason my apps are also responding slowly to key presses - even when practically no code is executed in the main loop. how is this solved? my apps work fine on other phones and i have seen several midp1 games that don't have this problem, so i am stumped.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    I believe that you would want seperate threads for the drawing and the key-checking.

  4. #4
    Regular Contributor
    Join Date
    Jan 2004
    Posts
    82
    Maybe this will help you.
    I made a arcade space shooter and I have quick responses to key events and smooth movement of shots/enemys/etc.
    I implemented a Timer that starts each time the canvas is shown and stopps when canvas is hidden.
    When the Timer is started you can define the interval in which the run() method of TimerTask is executed, and each time run() is executed it calls the canvas' paint() method. interval = 1000/(Frames per second) I have 15 Frames/second and it looks smoth.

    Code:
     
    Canvas.showNotify(){
        startFrameTimer();
    }
    
    Canvas.hideNotify{
        stoppFrameTimer();
    }
    
    stoppFrameTimer(){
        iTimer.cancel();
    }
    
    startFrameTimer(){
        iTimer = new Timer();
        iTimerTask = new TimerTask{
            public void run(){
                repaint();
            }
        };
        iTimer.schedule(iTimerTask, interval, interval);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×