Sunday, 21 March 2021

mouse position and drawing are not aligned on screen

I am drawing on screen but what is drawn doesn't match where the mouse is. I am already using unproject to change screen cords to world cords. I am using fill viewport, I think the drawing is not scaled up to current screen size maybe?

public void setPoint(float x , float y) {
        mPoints.get(currentPointIndex).set(x,y,0);
        if (x != 0 && y != 0) {
            getCamera().unproject(mPoints.get(currentPointIndex));
        }
 }


public void render(float delta) {
        super.render(delta);
        
        for(int i=0; i < maxPoints-1; i++) {
            Vector3 pnt = mPoints.get(i); 
            Vector3 lastPnt = null;
            if(i>0) lastPnt = mPoints.get(i-1);
            if(pnt.x == 0 && pnt.y == 0) continue;
            Vector3 pnt2 = mPoints.get(i+1); 
            if(pnt2.x == 0 && pnt2.y == 0) continue;
                
            drawLine(sb,pnt,pnt2,lineWidth,lineTex,colors.get(i));
        
        }
}

public UiScreen(WriteGame game, ScreenType screenType) {
        super(game, screenType);

        FitViewport sc  = new FitViewport(LAYOUT_HEIGHT,LAYOUT_HEIGHT);
        //sc.update(LAYOUT_HEIGHT,LAYOUT_HEIGHT,true);
        mStage = new Stage(sc);

        mStageCamera = new OrthographicCamera();

        sc.setCamera(mStageCamera);

        mInputMultiplexer = new InputMultiplexer();
        mInputMultiplexer.addProcessor(mStage);
        mGame = game;
}


from mouse position and drawing are not aligned on screen

No comments:

Post a Comment