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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:27:24+00:00 2026-06-02T06:27:24+00:00

I have a game where you click on a 2D HTML5 canvas to set

  • 0

I have a game where you click on a 2D HTML5 canvas to set a point for your character to move to. When I click, I’ve noticed that the character will appear to the lower right hand corner of where my mouse is clicking. So I assume that the x,y coordinate arguments of context.drawImage() are for where to start drawing the upper-left corner of the image. According to this spec, I’m right: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#drawing-images-to-the-canvas

I’ve tried to adjust this by drawing at centerX and centerY, as shown below. I seem to get the similar results as above. Huh? What should I do?

Here’s my character class draw function, which is called by a update() that runs on a timer.

this.Draw = function () {
    // var centerX = this.currentX + (this.avatarWidth/2);
    // var centerY = this.currentY + (this.avatarHeight/2);
    // console.log("hermes' supposed draw location = " + centerX + "," + centerY + " | currentX,Y = " + this.currentX + "," + this.currentY);
    // console.log("currentX,Y = " + this.currentX + "," + this.currentY);
    context.drawImage(hermesAvatar, this.currentX, this.currentY, this.avatarWidth, this.avatarHeight);
}; // end draw fxn
  • 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-02T06:27:25+00:00Added an answer on June 2, 2026 at 6:27 am

    Subtract, don’t add, half the width and height:

    this.Draw = function () {
        var centerX = this.currentX - this.avatarWidth / 2;
        var centerY = this.currentY - this.avatarHeight / 2;
        // console.log("hermes' supposed draw location = " + centerX + "," + centerY + " | currentX,Y = " + this.currentX + "," + this.currentY);
        // console.log("currentX,Y = " + this.currentX + "," + this.currentY);
        context.drawImage(hermesAvatar, centerX, centerY, this.avatarWidth, this.avatarHeight);
    }; // end draw fxn
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have played many Point and Click adventure game (Broken Sword, Sam & Max,
This is for an HTML5 canvas game that I am making. In the game,
I have written a simple memory game. You click on one of 16 cards
I have a game where user controls a character (with his finger) and i
I have a game that currently runs under Windows and Mac OS X and
I have a game engine that uses OpenGL for display. I coded a small
Most of us know that HTML5 Canvas element is having much better support with
I have a simple game that is in progress. As of right now all
I have a trivial little game I wrote in javascript that creates a wave
I'm using the HTML5 canvas and JavaScript to make a basic game, and I

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.