Sprite "flip" issue

Hi Everyone,

I am attempting to flip a sprite on a key press. After some googling many people suggested to use setLocalScale (-1f,1f,0) this would effectively mirror the sprite. However for me on JDK 3.2.1 this does not work. My sprite just disappears. If I use setLocalScale(-1f,-1f,0) the sprite appears upside down and facing the correct direction.

Below is a quick code example of my issue. a sprite named “Player” will need to be in the textures folder. If anyone has suggestions on how to mirror/flip the sprite on key press i am open to ideas/what i am doing wrong :smiley:

Thanks for looking

    
    Spatial player;
    
    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp()
        {
        //setup camera for 2D games
        cam.setParallelProjection(true);
        cam.setLocation(new Vector3f(0,0,0.5f));
        getFlyByCamera().setEnabled(false);
        
        player = getSpatial("Player");
        player.setUserData("alive",true);
        player.move(settings.getWidth()/2, settings.getHeight()/2,0);
        //The Below Works 
        player.setLocalScale(-1f,-1f,0);
        //The Below Does Not Work
        //player.setLocalScale(-1f,1f,0);
        guiNode.attachChild(player);
        }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }

    @Override
    public void simpleRender(RenderManager rm) {
        //TODO: add render code
    }
    
    private Spatial getSpatial(String name)
    {
        Node node = new Node(name);
        //Load the sprites
        Picture pic = new Picture(name);
        Texture2D tex = (Texture2D) assetManager.loadTexture("Textures/"+name+".png");
        pic.setTexture(assetManager, tex, true);
        
        
        
        //adjust picture
        float width = tex.getImage().getWidth();
        float height = tex.getImage().getHeight();
        pic.setWidth(width);
        pic.setHeight(height);
        
        pic.move(-width/2f, -height/2f,0);
        //add a material to the picture
        Material picMat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
        picMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.AlphaAdditive);
        node.setMaterial(picMat);
 
        //set the radius of the spatial
        //(using width only as a simple approximation)
        node.setUserData("radius", width/2);
 
        //attach the picture to the node and return it
        node.attachChild(pic);

        return node;
        
        
    }
}
`

When you flip the triangles, their windig order is reversed and they will be culled
(you will be looking at them from behind).

Try adding

picMat.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);

to disable culling.

Turning off culling of both faces and then only culling the back face yield the same results. The sprite still disappears.

Ill keep looking at this I must be missing something.

What does this mean? You should only turn off culling. Don’t set something else. Culling the back face is the default… you don’t want that. You want no culling. Not any. None.

In the final result, you want culling off… ie: both faces always rendered. Let the GPU take care of what to render.