×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    37

    Regarding Tile Game Scroll

    Hi Folks,


    I have implemented a small and very basic algorithm for tile game and it's working fine it scrolls smoothly.
    Still I have not implemeted keyPress() or keyRepeated() in my canvas Class but when i press key repeatedly (Nokia 3650) then scroll become a jerky motion and when i release the key it's again scroll smoothly.
    why it is so even i have not implemented singel key function.

  2. #2
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    121

    It's the events...

    Whether you want them or not, key events will be generated.

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    How are you implementing this scrolling? Are you using serviceRepaints()?
    serviceRepaints() will put the paint() method at the front of the event queue even if there are key events pending. That might help. Be careful though, you have to remember to leave some time for the MIDlet to respond to the rest of the events (after you have implemented them of course), or your game will be unresponsive.

    shmoove

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    121

    Actually...

    It sounds like your code is not waiting for a time between repaints. You need to do this to try to keep your framerate constant, and it hides the time MIDP spends messing about with key events etc.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    37

    Regarding Tile Game Scroll

    Hi,

    Tahnx all of u for such a nice response...let me tell u how i am doing this.

    I am taking two offscreen images (Back Buffer ) and drawing the tile on these offscreen images and scrolling. B'coz series 60 can handel upto three full size images at a time.

    Now i am putting this entire offscreen on screen and doing (x--) to scroll this followed by second ofscreen image.

    //=============================================

    public void run()
    {
    long tm = System.currentTimeMillis();
    while (Thread.currentThread() == animator)
    {
    repaint();
    // System.out.println("start");

    try
    {
    tm += delay;
    Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
    }
    catch (InterruptedException e)
    {
    break;
    }


    }
    }


    //==========================================

    paint(Graphics g)
    {

    Graphics g=gr;

    if(this.isDoubleBuffered())
    {
    g=graphics;
    }

    myBackground.draw(g);
    myBackground.setPosition();
    gr.drawImage(buffer,0,0,g.TOP|g.LEFT);

    }

    //============================================


    is this right way of doing tile game in series 60 pls suggest me thanx alot.

    wating for reply.

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    After you call repaint() in the run() method, add a call to serviceRepaints(), and that will put the paint request before all those key events in the event queue.

    shmoove

  7. #7
    Registered User
    Join Date
    Sep 2003
    Posts
    37

    Not Confident

    Hi thanx alot,


    Thanx all of u ....do u think the way i am imlementing tile game is the right way....my ultimate target to get smoothest scrolling.

    do u think this will....pls suggest me improvments or tell me about options.


    thanx all of u
    wating for reply

  8. #8
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    If you add the call to serviceRepaints(), then I would change this:
    Code:
    Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
    to use a constant slightly bigger than 0. Otherwise, if the painting takes too long you'll end up constantly repainting the screen and not leave any time for handling key events.
    It's looks OK to me. There are other options which are also OK. Different techniques (like synchronizing the painting using callSerially()) might work slightly better or worse on different phones. There is no "perfect" way. Nothing beats doing tests on real devices.

    shmoove

Posting Permissions

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