How to make an object blink?

I have a character in my game that I would like to blink (on and off at a particular frequency) so that the user can see him easier on the screen when something gets highlighted. What is the best way to make this happen?

Wait some period of time, set the cull hint on the spatial to always. Wait some more… set the cull hint to inherit. Repeat.

Do it in a control.

If any of these things sounds too terribly foreign then also do some more JME tutorials. (Specifically about controls).

Do you have a link for me regarding controls, or a code snippet? I’m a newby :smile:

Here you go:

Here is a simple example without Control or AppState - just copy-paste the code.
As pspeed said: better use Control for this (or AppState if you want global control).
As both pspeed and jmaasing said: read the wiki and go through the tutorials.
Or buy one of the three jME3.0 books that are currently available, some are quite good.

package mygame;

import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.shape.Box;

 * Simple test with two blinking techniques...
 * @author Ogli
public class SimpleTest extends SimpleApplication {

    public int counter = 0;
    public static void main(String[] args) {
        SimpleTest app = new SimpleTest();
    public Geometry blinkingBox1;
    public Geometry blinkingBox2;
    public Material blinkingMaterial;
    public Material otherMaterial;
    public ColorRGBA normalColor = ColorRGBA.Blue;
    public ColorRGBA blinkColor = ColorRGBA.White;
    public void simpleInitApp() 
        //create the blinking box
        Box b = new Box(1, 1, 1);
        blinkingBox1 = new Geometry("Box", b);
        blinkingMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        blinkingMaterial.setColor("Color", normalColor);
        //create the other blinking box
        Box b2 = new Box(1.3f,2.1f,1.3f);
        blinkingBox2 = new Geometry("Box 2", b2);
        otherMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        otherMaterial.setColor("Color", ColorRGBA.LightGray);
        Node box2Node = new Node();
        box2Node.move(5, 0, 0);        
        //make camera a little faster than usual

    public float secondsPassed = 0f;
    public float blinkOnTime = 0.5f;
    public float blinkOffTime = 0.5f;
    public boolean blinkOn = true;
    public void simpleUpdate(float tpf) {
        //TODO: add update code
        secondsPassed += tpf;
        float maxTime = blinkOn ? blinkOnTime : blinkOffTime;
        if(secondsPassed > maxTime)
            secondsPassed = 0;
                blinkOn = false;
                //blinking box 1
                blinkingMaterial.setColor("Color", normalColor);
                //blinking box 2
                blinkOn = true;
                //blinking box 1
                blinkingMaterial.setColor("Color", blinkColor);
                //blinking box 2

    public void simpleRender(RenderManager rm) {
        //TODO: add render code
1 Like

You might have noticed that multiple ways are possible to achieve the ‘blinking’ effect.
Those are just two very simple effects - one could also write a “pulsating color shader” in GLSL.

And other effects are possible too:

  • Render a decal on the ground (for example a ring) :low_brightness: and let it have
    varying size or color - just one idea.
  • Or maybe a 3d-arrow :arrow_down: or exclamation mark :exclamation: above the head (like in MMOs) would do the trick - just another idea.
1 Like

Since this thread is similar to a problem I have, I’m going to write it here. If I should create a thread, no problems.

How do I make an object fade away, to become transparent over time? Is there any filter or control created for that? If not, how do I do it then?

And btw, can someone give me an example of a wait(int seconds) method for me to create? I have been using timers (fields that increment with the tpf value), but for some cases it is more friendly to have a method like that.

What do you mean wait()… like, that line wouldn’t complete until the time had expired? So you’d block the whole rendering thread waiting?

As to the other, it’s a completely different topic.

Different topic, yes.
Many answers in the docs and :chimpanzee_google: is your friend…

I was able to write a simple fade-over-time in a few minutes.
Here are some important lines:

public float fading = 1.0f;
fading *= 0.9f;
blinkingMaterial.setColor("Color", new ColorRGBA(0,0,1,fading));

The other code is very similar to the blinking demo.
You can change some things and play around.

And as before, there are multiple ways to reach your destination.
This is just very simple stuff, other solutions are better.

For the waiting-function,
from time to time I emulate low framerates (fps near 1 or 2 or so…)
just by having this simple code block in some standard place:

catch(Exception ex)


Simple but effective… :chimpanzee_smile:

@Ogli and @pspeed thanks for the replys. I now have an ideia how to make object fade away.

The mthod wait() i wanted was some sort of method that would wait a certain time WITHOUT stop rendering the game. I used Thread.sleep(), but it has that problem.

So waiting without waiting. The would be a trick.

No, I think I know what you mean, Evilblow.

You want to stop all game-logic but keep rendering.
I’ve planned that for my game too, for when the user enters the main menu - in the background I want to keep rendering the game scene, but the game is paused completely.
I wrote a PauseOtherControlsControl that even stops the in-engine AnimationControl etc.
But since I’m now working on something completely different, I didn’t continue working on that thing.

Maybe one of the core devs has a better solution for that problem.
And I hope that I get your intentions right, Evilblow.

The background should also have a rotating camera (which is the only object that gets some kind of tpf update). So rendering to a texture is not the solution.
Further, some people will want this feature to show steps of their 3d algorithm from a different point of view - e.g. their LOD terrain rendering seen from above the camera. It’s used in scientific 3d graphics stuff quite often in order to demonstrate how the algorithms work. People can then “freeze” their LOD algorithm and use a fly camera to navigate around the area.