user8340536 user8340536 - 2 years ago 109
Android Question

How to change color of a sprite randomly

I wrote the following code:

int color = Color.argb8888(255, rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));

With this code I want to change the color of a sprite randomly. Unfortunately, the color of all sprites on the stage get changed but I want to declare which sprite I want to tint. How can I improve my code?

Answer Source

I prefer to use in this way :

final Image image=new Image(new Texture("badlogic.jpg"));
final Color colors[]=new Color[]{Color.YELLOW,Color.RED,Color.CYAN};
image.addAction(Actions.forever(Actions.sequence(Actions.delay(.2f), Runnable() {
            public void run() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download