method void moveUp() wrong!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

method void moveUp() wrong!

cao_ni_ma
微信图片_20200301130417.png
   method void moveUp() {
      if (y > 1) {
         do Screen.setColor(false);
         do Screen.drawRectangle(x, (y + size) - 1, x + size, y + size);
         let y = y - 2;
         do Screen.setColor(true);
         do Screen.drawRectangle(x, y, x + size, y + 1);
      }
      return;
   }

After running the upper code, the changes should be like in the file which I upload. ( the red line marks the process )
I think the consequences didn't meet with the goal to move the square up by 2 pixels, instead, It left  the area(x,y-1,x+size,y+2) in white.



I guess the right code should be

   method void moveUp() {
      if (y > 1) {
         do Screen.setColor(false);
         do Screen.drawRectangle(x, (y + size) - 2, x + size, y + size);
         let y = y - 2;
         do Screen.setColor(true);
         do Screen.drawRectangle(x, y, x + size, y + 2);
      }
      return;
   }
Reply | Threaded
Open this post in threaded view
|

Re: method void moveUp() wrong!

WBahn
Administrator
Are you trying to ask a question? If so, it's hard to tell what it might be.

You might to a test to see exactly how your drawRectable() function works. Specifically, if you draw a rectangle from (x,y) to (x+dx,y+dy), is the number of rows and columns that are drawn dx and dy.