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) {
    long timeSinceStart = SystemClock.uptimeMillis();
    long deltaTime = timeSinceStart - oldTimeSinceStart;
    oldTimeSinceStart = timeSinceStart;
    if(deltaTime >= 15) {

code for RandBall()

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

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 :/


1 Answer 1


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.


You must log in to answer this question.

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