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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:48:36+00:00 2026-05-27T12:48:36+00:00

I have scenario where there are several items on a the context stack and

  • 0

I have scenario where there are several items on a the context stack and I need to get an x, y coordinate relative to the canvas itself.

The situation is I am writing a 2D game in HTML5 and I want the “character” being controlled by the user to be able to aim towards the mouse. The character is nested in transformations. There is a camera object that transforms the canvas to follow the character and perform zooms/rotations, and of course the character itself is transformed downwards, and at times rotated away from it’s centre.

If I could get the position of my character relative to the canvas, I could do an atan2 to aim towards the mouse. Alternatively, if I could get the mouse coordinates relative to the centre of my character, then I could do the same.

Is there any way to do this other than to reverse all of my transform calculations?

  • 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-27T12:48:37+00:00Added an answer on May 27, 2026 at 12:48 pm

    Unfortunately I ended up manually reversing the transformations. The following code is what I put into the camera object:

    /**
    Transforms mousex and mousey to the positions within the game.
    */
    this.transformMouse = function(mousex, mousey){
        var xScale = screenWidth / (currentMaxX - currentMinX);
        var yScale = screenHeight / (currentMaxY - currentMinY);
    
        this.tmousex = (mousex - screenWidth / 2) / xScale + (currentMaxX + currentMinX) / 2; 
        this.tmousey = (mousey - screenHeight / 2) / yScale + (currentMaxY + currentMinY) / 2;
    }
    

    the tmousex and tmousey are the transformed x and y positions of the mouse. This does not account for rotation – the reversal of the transformation will have to go into the character code (rotation of camera and character will just be added after the atan2 code).

    Hope this helps anyone with the same problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a scenario where there are several subclasses which have got similar
My scenario is that there are several different models which can have comments. Trying
I have a scenario. (Windows Forms, C#, .NET) There is a main form which
Scenario I have a Windows Forms Application. Inside the main form there is a
I have a simple producer/consumer scenario, where there is only ever a single item
I have a scenario where I need to upload a file from one web
We have a scenario where we want to display a list of items and
I have a scenario where an item is being tagged with several tags, some
I'm going to test a complex scenario which expects several other steps to have
I have a scenario where I have several jqgrids. Clicking row in one grid

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.