I've just started developing game in android using LibGDX. I've follow some samples and now my simple game can draw path when user move their finger around the screen.

now problems appear when i add another feature to allow user to pinch zoom in and out. after zooming OUT the orthographic camera user can still draw the path BUT the path can no longer follow user finger to the edge of the screen, the user can only draw the path around the center of the screen. looks like the coordinate projection after zoom out not changed and still limited to the projection before zoom out!

how can i make my game to keep drawing line around the entire screen even after the user have zooming out the camera?

here's my code:

   1. in my Screen implemented class:

public void render(float arg0) {
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);


    public boolean touchDragged(int screenX, int screenY, int pointer) {
        // TODO Auto-generated method stub
        isDrawing = true;

        Vector2 v = new Vector2(screenX, Gdx.graphics.getHeight()-screenY);

        //add new point for drawing path

        return true;

   2. in my Renderer class:

cam = new OrthographicCamera();
    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

public void setZoom(float zoom) {
     this.cam.zoom = zoom;

//the triangle strip renderer
    path = new PathClass();

public void render() {

    //generate the triangle strip from our path
    Array<Vector2> xox = screen.path();

    //the vertex color for tinting, i.e. for opacity
    path.color = Color.WHITE;

    //render the triangles to the screen

   3. on my PathClass:

public void draw(Camera cam) {
    if (tristrip.size<=0)

    gl20.begin(cam.combined, GL20.GL_TRIANGLE_STRIP);
    for (int i=0; i<tristrip.size; i++) {
        if (i==batchSize) {
            gl20.begin(cam.combined, GL20.GL_TRIANGLE_STRIP);
        Vector2 point = tristrip.get(i);
        gl20.color(color.r, color.g, color.b, color.a);
        gl20.vertex(point.x, point.y, 0f);
  • \$\begingroup\$ Did you eventually figure this out? \$\endgroup\$
    – Jax
    Commented May 11, 2015 at 15:59
  • \$\begingroup\$ If you did you could post the answer to your problem and I will up vote. \$\endgroup\$
    – Jax
    Commented May 11, 2015 at 16:00

1 Answer 1

Vector3 v = new Vector3(screenX, Gdx.graphics.getHeight()-screenY, 0);

camera.unproject(v);//converts v to world coords

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .