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 9155211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:07+00:00 2026-06-17T12:33:07+00:00

I am making a game of paddle ball, I have designed and scripted ball

  • 0

I am making a game of paddle ball, I have designed and scripted ball under boundary.
I want to make a paddle more and that moves with current mouse position.
How do i get that?
This is my code of ball moving under boundary, I need a paddle at bottom.

<!doctype html>
<html>
<body onload="init();">
<script>
var context;
var x=150;
var y=150;
var dx=2;
var dy=4;

function init()
{
  context= myCanvas.getContext('2d');
  setInterval(draw,10);
}

function draw()
{
  context.clearRect(0,0, 300,300);
  context.beginPath();
  context.fillStyle="#98bf26";
  // Draws a circle of radius 20 at the coordinates 100,100 on the canvas
  context.arc(x,y,10,0,Math.PI*2,true);
  context.closePath();
  context.fill();


  // Boundary Logic
if( x<0 || x>300) dx=-dx;
if( y<0 || y>300) dy=-dy;
x+=dx;
y+=dy;
}

</script>

  <canvas id="myCanvas" width="300" height="300" style="border:1px dotted #111;" >
  </canvas>
</body>
</html>
  • 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-06-17T12:33:08+00:00Added an answer on June 17, 2026 at 12:33 pm

    Try to add to your code

    myCanvas.onmousemove = mouse_move_callback
    

    Where mouse_move_callback is a function like

    function mouse_move_callback(ev) {
      // Get mouse position
      if (ev.offsetX) {
        c_x = ev.offsetX;
        c_y = ev.offsetY;
      }
      if (ev.layerX) {
        c_x = ev.layerX;
        c_y = ev.layerY;
      }
      // Update paddle position
      update_paddle(c_x,c_y);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a game. I would like to have a joystick that moves
I'm making a game where the game's size varies, so I want to make
I'm making a game with cocos2d and I have a bunch of sprites that
We are making a game with a playing character that will have several different
Making game of life I need to a have a grid that is 30x20
I'm making a game engine in Javascript, and I want to have a camera
I am making a game in java and I want to create a simulation
I'm making some game, and I have made it pretty much all, but not
I am making a game, and have a Game model and a User model.
I am making a game that has its own level editor. The editor simply

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.