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

  • Home
  • SEARCH
  • 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 6653153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:14:01+00:00 2026-05-26T01:14:01+00:00

Hello could somebody tell me wath is wrong with my code. When i do

  • 0

Hello could somebody tell me wath is wrong with my code. When i do the clear rect, it’s doesn’t work.

I just try to move the ball in the canvas. Actually my ball leave a mark. This kind of line is leave.
enter image description here

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="_js/jquery1.6.js" type="text/jscript"></script> 
    </head>
    <body>    
        <canvas id="dropBall" width="400" height="400"></canvas>
     <script>
         var dropBall = $("#dropBall")[0];
         var dropContext = dropBall.getContext("2d");
dropContext.fillStyle = "green";
         var ballX = 200;
         var ballY = 200;
         function activeBall() {
             dropContext.clearRect(0, 0, dropBall.width, dropBall.height);
             dropContext.arc(ballX, ballY, 10, 2 * Math.PI, 0, true);
             dropContext.fill();

             ballY--;
             ballX++;
             var time = 100;
             setTimeout("activeBall()", time);
         }
         activeBall();
    </script>
    </body>
  • 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-26T01:14:02+00:00Added an answer on May 26, 2026 at 1:14 am

    Shouldn’t it be:

    dropContext.clearRect(ballX,ballY,dropBall.width,dropBall.height);
    

    or am I misunderstanding something?

    If you do it the other way around, then the only rectangle getting cleared is the square from (0,0) to (width of ball,height of ball).

    EDIT:
    It actually might be

    dropContext.clearRect(ballX-(dropBall.width/2),ballY-(dropBall.height/2),dropBall.width,dropBall.height);
    

    If your ball is centered at ballX.

    EDIT EDIT:

    I fixed it for you:

    function activeBall() {
             dropContext.clearRect(ballX-(dropBall.width/2),ballY-(dropBall.height/2),dropBall.width,dropBall.height);
             dropContext.beginPath();
             dropContext.arc(ballX, ballY, 10, 2 * Math.PI, 0, true);
             dropContext.fill();
    
             ballY--;
             ballX++;
             var time = 100;
             setTimeout("activeBall()", time);
         }
    
    1. You were clearing a rectangle on the top-left corner of your canvas.
    2. You have to call beginPath() and then do all your drawing work. Clearing has to be called outside of beginPath() and fill().

    The specific lines are:

             dropContext.clearRect(ballX-(dropBall.width/2),ballY-(dropBall.height/2),dropBall.width,dropBall.height);
             dropContext.beginPath();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello is it possible if someone could tell me the easiest way to create
Hello folks! Could you tell me a good(non-redundant) way to find out the following:
Hello I'm having problems making an inner join in access. Could somebody correct my
Hello could someone help me udnerstand how this code works ? go(Start,Dest,Route):- go0(Start,Dest,[],R), rev(R,Route).
Hello could someone help me udnerstand how this code works ? go(Start,Dest,Route):- go0(Start,Dest,[],R), rev(R,Route).
Could somebody tell me where would the execution log be stored when using the
Hello pls could someone help... I've tried everything to get this to work in
I would appreciate it if somebody could tell me how to bind a listbox
How could I achieve the following: document.all.regTitle.innerHTML = 'Hello World'; Using jQuery where regTitle
I could do this in C#.. int number = 2; string str = Hello

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.