Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to move block in the array
    text
    copied!<p>Hey yall im trying to get my block to move based on where it is in the array so if it is in array[0][0] and i draw it on screen i want it to move when i put a new block in [0][1] and delete whats in [0][0] but im having trouble can yall help?</p> <pre><code>package com.example.coloroblind; import java.util.ArrayList; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.util.Log; import android.view.View; public class GameView extends View { block array[][]; int bottom, top; private float rectY = 10; private float rectX = 10; boolean start = false; boolean move = false; int w;// The width int h;// The hieght int x, y; // the x and y location of the block&amp; index of the array // Needed for the block color private Paint paint; // Constructor public GameView(Context context) { super(context); paint = new Paint(); } // Called back to draw the view. Also called by invalidate(). @Override protected void onDraw(Canvas canvas) { // starts and initializes the array with the one block before going into the main program // sets the hight and width the size of the screen if (start == false) { w = this.getWidth() - 55; h = this.getHeight() - 55; bottom = h; top = 0; firstCreateBlockArray();// creates the first block start = true; } paint.setColor(Color.BLUE); for (int x = 0; x &lt; w; x++) { for (int y = 0; y &lt; h; y++) { if (array[x][y] != null) canvas.drawRoundRect(array[x][y], 6, 6, paint); update(x, y);// this is suppose to move the array block } } // Delay try { Thread.sleep(300); } catch (InterruptedException e) { } invalidate(); // Force a re-draw } private void firstCreateBlockArray() { // Creates the array2d of blocks and sets to null array = new block[w][h]; for (int x = 0; x &lt; w; x++) { for (int y = 0; y &lt; h; y++) { array[x][y] = null; } } int hori = (int) (Math.random() * w) + 1; array[hori][0] = new block(hori, 0);// sets the horizonatall of the block randomly } // suppose ot change position of the block in the array private void update(int x, int y) { // Detect collision and react if (y &lt; bottom - 1) { array[x][y + 1] = array[x][y]; // array[x][y]=null; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload