简体   繁体   中英

LibGDX Sprite Rendering issues

I'm using LibGDX and having an issue rendering Sprites, I've been working on it for 6hours now, and now I'm almost at the point where I want to rip my own hair out.

If I just draw the sprite, the sprite draws like so (the small green thingy: https://gyazo.com/6a70bb710fdd6bb9d372cef050cb6c4e

If I draw anything after that, lets say my rayHandler, the sprite doesn't draw: https://gyazo.com/432d7cbd19f55b6be7252537b14cd35b

Here is my render method:

    @Override
public void render(float delta) {

    /**
     * Clear screen.
     */
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    continuousInput(delta);
    update(delta);

    /**
     * Start 'spriteBatch'.
     */
    spriteBatch.begin();
    spriteBatch.setProjectionMatrix(cameraHandler.orthographicCamera.combined);
    spriteBatch.disableBlending();

    /**
     * Render our handlers
     */
    spriteBatch.draw(texture, 100, 1);
    //mapHandler.render(delta);
  //  lightHandler.render(delta);
 //   playerHandler.render(delta, spriteBatch);
    spriteBatch.draw(texture, 100, 1);
    spriteBatch.draw(texture, 1, 1);

    /**
     * End 'spriteBatch'.
     */
    spriteBatch.end();
}

My project is rather big so I won't include any specific classes, but if you guys know this as a common problem then a solution would be extremely helpful. Here is the code for my entire project, it got messy at the end because I was extremely aggitated.

NOTE: The map and everything renders fine, I think it's an issue with the spriteBatch but I can't figure it out.

SOURCE: http://www.filedropper.com/resident

Once again, thank you! Any response is appreciated. - Jake

The biggest glaring problem is that you're drawing non-SpriteBatch stuff in between spriteBatch.begin() and end() . When you call spriteBatch.begin() , it sets up its shader along with its parameters, blend parameters, etc. and doesn't expect them to be changed by other objects until end() is called.

I presume your lightHandler.render() is calling something in box2dlights to render the light to the scene, and so that object is going to modify the currently active shader and the blend parameters and sprite batch won't know that happened and cannot react.

So call spriteBatch.end() before drawing anything that isn't drawn with sprite batch. You can call begin() again if you need to draw sprites on top of your non-SpriteBatch stuff.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM