I am trying to allow the player to click hold then drag and let go which will accomplish drawing a line from where you clicked to where you let go. However I can't seem to figure out how to keep the lines rendered. Everytime you click drag and let go it draws the line correctly then disappears if you try and draw another line. Here is my code for the input listener which gets the position
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(button == Buttons.LEFT){
buttonPositions[0].x = screenX;
buttonPositions[0].y = screenY;
projector.unproject(buttonPositions[0]);
}
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if(button == Buttons.LEFT){
buttonPositions[1].x = screenX;
buttonPositions[1].y = screenY;
projector.unproject(buttonPositions[1]);
lineDraws.add(buttonPositions);
}
return false;
}
buttonPositions
is an array of Vector2
of size 2
so you can add where you clicked and where you let go then the arraylist
lineDraws stores that Vector2 array, then I try to loop through this list and render it like so
public void render(float delta){
if(!tutOver){
startTutorial();
}
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.begin();
for(int i = 0; i < listener.getPositionsList().size() - 1; i+=2){
renderer.line(listener.getPositionsList().get(i)[0], listener.getPositionsList().get(i + 1)[1]);
}
renderer.end();
}
I am at a loss as to what to do, and the i+=2
is so it will draw the first two coordinates then the next two. Any help is greatly appreciated!