Drawing multiple pixels/rectangles

前端 未结 1 1742
青春惊慌失措
青春惊慌失措 2021-01-28 01:40

I\'m trying to make a java sand game and can\'t get past one bit. i\'ve made my method that draws a rectangle at mouseX and mouseY, and i have set it up so it updates every fram

相关标签:
1条回答
  • 2021-01-28 02:30

    Public Variables:

    Rectangle boxes[] = new Rectangle[maxnum];
    int boxnum = 0;
    

    On mouse move:

    boxes[boxnum] = new Rectangle[e.getX(), e.getY(), sizeX, sizeY);
    boxnum = boxnum + 1;
    

    When drawing your particles:

    counter = 0;
    do
    {
       g.drawRect(boxes[counter].x, boxes[counter].y, sizeX, sizeY);
       counter = counter + 1;
    } while (counter < maxnum);
    

    Where maxnum is the maximum number of boxes you will have. This way you can store multiple rectangles in your array and go through the array and draw them when you update the screen. Hope this helps.

    0 讨论(0)
提交回复
热议问题