×

Discussion Board

Results 1 to 3 of 3

Thread: sprite mover

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    37

    sprite mover

    hi
    how can I set 2 state for a sprite.
    I mean I have 2 image of the same sprite: spriteOn.png and spriteOff.png
    I can simply draw them on the display using the paint method.
    but how can I alternate them using a fixed time (about 500 ms)?
    I tryied to use the wait and the timer method with no success.
    a simply example code will be very wellcome.

    thanks

    eml

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    try to use System.currentTimeMillis() and check time while you repaint (if you use another thread to update) or simple - use timer. hmmm...but what do you want to do? an idea depends on expected result.

    gediman

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    8
    A simple thread should do it... the thread is created by

    Thread paintThread = new Swaper();
    paintThread.start();

    and the code for the thread:

    private class Swaper extends Thread{
    public Swaper (){
    //constructor
    }

    public void run(){
    this.setPriority(Thread.MIN_PRIORITY);
    while (true){
    something.repaint();
    }

    try{
    this.sleep(500);
    }catch (Exception e){
    }
    }

    and instead of something.repaint();
    in the thread you could have a method that swaps the images and repaints or something...
    Last edited by thid; 2003-04-07 at 20:13.

Posting Permissions

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