Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:21:03+00:00 2026-05-22T20:21:03+00:00

I am going crazy trying to figure this out. I am trying to make

  • 0

I am going crazy trying to figure this out. I am trying to make an array or arraylist of Rect (rectangles) that I can update the coordinates and draw on the screen(to make them move).

Right now I have a separate class called Fire in which I make a new rectangle each iteration with the new coordinates in its own onDraw() method. In the View’s onDraw() method’s first iteration I add a new Fire to an arraylist.

In the Fire class I have:

public void onDraw(Canvas canvas){
    moveF();
    Rect r = new Rect(_l,_t,_r,_b);
    canvas.drawRect(r, paint);
}

In the View class I have:

protected void onDraw(Canvas canvas) {
    int i = 0;
    canvas.drawColor(Color.WHITE);
    if(i==0){
        fires.add(new Fire(20,100,40,120));
        i++;
    }
    for(Fire fire : fires){
        fire.onDraw(canvas);
    }
}

I got rid of pointless parts of code, but this is the important stuff. The Rectangle prints, however it prints all the previous locations as well and I don’t understand why. I have been trying to fix this forever and any help you guys could give would be greatly appreciated. I was able to implement this in java easy, but android is giving me problems.

Thanks in advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:21:04+00:00Added an answer on May 22, 2026 at 8:21 pm

    From the code, you are adding new rectangles to the list, and then drawing each rectangle. But from the description, it seems that you just want to draw a single rectangle, with updated coordinates.

    Instead of creating a new Rect each time, reuse a rectangle and update its coordinates with set(...).

    A second problem is that you set i=0 and then immediately check for i==0, which would be always true. Try something like this instead:

    static final Rect rect = new Rect();
    
    // your code here
    
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.WHITE);
    
        moveF();
        rect.set(_l,_t,_r,_b);
        canvas.drawRect(rect, paint);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going crazy trying to figure out this error message that has no obvious
I am going crazy trying to figure this out. I have tried everything I
I've been going crazy trying to figure out why this is happening. The problem
I am going crazy trying to figure this out without success. I have a
Going crazy trying to figure this out for the past 2 hours. I have
I have been going crazy trying to figure out how to query a php
Going crazy trying to find this. Any help would be appreciated. Problem is that
i've been trying to figure this out and i have absolutely no clue why
I'm going crazy trying to make an relative layout work. I was getting an
Ok, I'm going crazy. I've been trying to make a simple .net assembly visible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.