0
\$\begingroup\$

I tried to combine matdesl's and libgdx's draw lines algo ang code. but i can only create a line.

problem is i want to make a fruit ninja swipe effect but only knows this... problem is i want to make a fruit ninja swipe effect but only knows this... anyone try to help me on improving just a line to have a swipe effect like fruit ninja?

    public class GameTouch {

private static final int MAX_LINES = 1000;
private OrthographicCamera camera;
private Mesh lineMesh;
private Vector3 unprojectedVertex = new Vector3();
private FixedList<Vector2> list;


public GameTouch(){
    this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    lineMesh = new Mesh(false, MAX_LINES , 0, new VertexAttribute(Usage.Position, 2, "a_pos"));
    list = new FixedList<Vector2>();
}

public void update(float delta){

    camera.update();
    camera.apply(Gdx.gl10);


    if(Gdx.input.isTouched()){
        unprojectedVertex.set(Gdx.input.getX(), Gdx.input.getY(), 0);
        camera.unproject(unprojectedVertex);
        Vector2 input = new Vector2();
        input.x = unprojectedVertex.x;
        input.y = unprojectedVertex.y;

        if(list.size > 0){

            Vector2 temp = new Vector2();
            float sqlen = temp.set(input).sub(list.get(0)).len2();
            Array<Vector2> tempA = new FixedList<Vector2>();
            if(sqlen >= 3){
                list.insert(input);

            }



            lineMesh.setVertices(getVertices(list), 0, list.size * 2);


        }else{
            list.insert(input);
        }
    }else{

         if(list.size > 0){
            list.removeIndex(list.size - 1);
         }
    }
    if(list.size > 2){
        //lineMesh
        lineMesh.render(GL10.GL_TRIANGLE_STRIP);
        Gdx.gl10.glColor4f(0f, 0f, 1, 0.5f);
    }
}

private float[] getVertices(Array<Vector2> list){
    float[] vertices = new float[list.size * 2];
    int counter = 0;
    for(Vector2 vertex : list){
        vertices[counter++] = vertex.x;
        vertices[counter++] = vertex.y;
    }


    return vertices;
}

private class FixedList<T> extends Array<T>{

        public FixedList(){
            super(Vector2.class);
        }


        public FixedList(int capacity , Class<T> type){
            super(false, capacity , type);
        }

        public void insert(T t){
            T[] items = this.items;

            size = Math.min(size + 1 , items.length);

            for(int i = size - 1 ; i > 0 ; i--){
                items[i] = items[i - 1];
            }

            items[0] = t;
        }
    }
}
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

seems like the answer is already here. this problem is heavily outdated i have already found the solution.

just find its source code in github

\$\endgroup\$

You must log in to answer this question.

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