0
\$\begingroup\$

Sorry if the question is dumb but my brain just cannot solve it for some reason..

So I've made one opengl object public static Square ball = new Square(75,75);

And I am trying to make it so that every so often a new ball appears on the screen

public void Loop(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    long timeSinceStart = SystemClock.uptimeMillis();
    long deltaTime = timeSinceStart - oldTimeSinceStart;
    oldTimeSinceStart = timeSinceStart;
    if(deltaTime >= 15) {
        RandBall(gl);
    }}

code for RandBall()

   `public void RandBall(GL10 gl) {
     gl.glPushMatrix();
         gl.glTranslatef(rand.nextInt((1280 - 0) + 1) + 0,
                         rand.nextInt((720 - 0) + 1) + 0, 0);
         getBall().draw(gl);
     gl.glPopMatrix();  
}`

but when I run the code it draws only one object and constantly changes its coordinates. How do I make it so that it draws multiple objects with different random coordinates? The solution is probably going to be an easy one but I just can't see it :/

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You are calling glClear(GL10.GL_COLOR_BIT... every time you enter loop(). You keep erasing the last ball drawn. To see each one you need to redrawn each ball every frame. Just store the position information created by RandBall() in a container such as ArrayList. Then after you call glClear() loop through the list and draw the ball at each position.

\$\endgroup\$

You must log in to answer this question.

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