Create account / Log in

Custom Java class blinking effect

Talk about module design ideas and techniques.

Moderators: uckelman, Tim M

Custom Java class blinking effect

Postby Mu0n » April 23rd, 2017, 1:52 pm

I'm wondering what exact steps you would recommend if I want to make a Shape over a Piece blink for a few seconds.

What I can already do:
-Properly compile and add a decorator custom Java class to a Piece
-Access the Map in which this visual effect should happen
-Produce a proper Shape that has the position, size and orientation of the Piece
-Draw that shape with a transparent shade


What I can't do yet:
-Start some kind of Thread or Executorservice that will draw that shape on and off for n times, and get acceptable levels of fluidity.
Mu0n
 
Posts: 52
Joined: September 5th, 2013, 5:01 pm

Re: Custom Java class blinking effect

Postby Mu0n » April 25th, 2017, 6:58 pm

I solved it, I used a Timer():

final Timer timer = new Timer();
timer.schedule(new TimerTask() {
int count = 1;
@Override
public void run() {
try{
//do stuff
//control how many times using the count variable
}
} catch (Exception e) {

}
}
}, 0,DELAYBETWEENFLASHES);
}

to achieve the blink, I used an an anonymous class that implements Drawable,
in the draw function, I use a boolean toggle which alternates between:

1) drawing the shape
2) repainting the map

there are probably some optimisations to do, but I'm working on other more urgent things for my module and it's good enough.
Sometimes, the last "flash" of my blink (which uses a transparent alpha colored shape) will stay drawn at the end of the cycle but will disappear if you move the mouse or click somewhere in the background of the Map.
Mu0n
 
Posts: 52
Joined: September 5th, 2013, 5:01 pm


Return to Module Design

Who is online

Users browsing this forum: No registered users and 4 guests