java - libGdx: Draw Line on Stage and keep it there -
i working on app, need draw trace of sprites. tried shaperenderer, , draws lines correctly, after line drawn, gets erased again. tried polyline, , add points each update, after time polyline large draw.
i have code in overriden actor class, on every draw call checks if sprite has moved, , if so, line gets drawn shaperenderer. there way, keep line ?
code:
shaperenderer renderer = stageactivity.stagelistener.shaperenderer; renderer.setcolor(color); gdx.gl.gllinewidth(strokewidth); line.add(sprite.look.getx()); line.add(sprite.look.gety()); renderer.polyline(getlinevertices());
the getlinevertices() method converting arraylist float[] array.
edit:
since code above has poor performance lot of lines, tried out framebuffer need (i think), not draw, doing wrong ?
buffer.begin(); renderer.begin(shaperenderer.shapetype.line); renderer.line(previouspoint.x, previouspoint.y, sprite.look.getx(), sprite.look.gety()); renderer.end(); buffer.end(); batch.draw(buffer.getcolorbuffertexture(), 0, 0);
the buffer global variable in actor.
you should keep lines points in collections when necessary update , draw lines these collections in render
method independently
array<vector2> lines = new array<vector2>(); ... //when need draw next line update lines array lines.add(new vector2(sprite.look.getx(), sprite.look.gety())); //and in render method you're rendering these lines independently if(lines.size() > 1) { //one point not line for(int = 1; < lines.size(); i++) renderer.line(lines.get(i-1), lines.get(i)); }
also consider not drawing lines time - if count of lines big (like thousands) have performance issues anyway - drawing rather expensive operation
Comments
Post a Comment