I’m writing a game with libgdx using JRuby and I’m having issues getting the ScissorStack to work exactly right. This is an open world game and I want all of the interior rooms the player is currently not in to be blacked out. I have it barely working. Here is the main code:
unless @player.room.nil?
@cam.position.y = @player.room.y + @player.height / 2 + 1 + @camOffset
@roomCam.position.y = @player.room.y - @player.height / 2 - 1 - @camOffset
ScissorStack.calculateScissors(
@roomCam, @roomCam.position.x, @roomCam.position.y, @roomCam.viewportWidth, @roomCam.viewportHeight,
@renderer.getSpriteBatch.getTransformMatrix, @player.room, @scissor
)
scissorPos = Vector2.new(@scissor.x, @scissor.y)
ScissorStack.toWindowCoordinates(@roomCam, @renderer.getSpriteBatch.getTransformMatrix, scissorPos)
@scissor.x = scissorPos.x - Gdx.graphics.width / 2
@scissor.y = scissorPos.y + Gdx.graphics.height / 2
@scissor.width = @scissor.width * Const::BTW
@scissor.height = @scissor.height * Const::BTW
ScissorStack.pushScissors(@scissor)
end
I’ve rigged it to almost do what I want it to, but there are problems. @player.room is the Rectangle the player is colliding with. Right now I just freeze the camera in the Y direction because when the player could jump it caused the ScissorStack to jump as well. I want the player to be able to jump and even have the camera raise with her, but then have the masking rectangle stay in the same place. I don’t understand why it works in the X direction, but not Y. Right now I’ve just hacked it by using a second camera that doesn’t jump with the player. It’s messy and not what I want. Any help would be much appreciated. There is clearly something about the ScissorStack calculations I just don’t understand.