Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
HTML5 Canvas translate, rotate, scale

for a little game i write a camera component for html5 canvas. You should be able to zoom (mousewheel), pan (left mouse) and rotate (right mouse). My Problem is after rotation if you try to move up the orientation is wrong and the image moves down.

I prepared a example here:

https://codepen.io/rogerbuecker/pen/yLzYqXq

My current draw code:

canvas.width = window.innerWidth
canvas.height = window.innerHeight
    
// Translate to the canvas centre before zooming - so you'll always zoom on what you're looking directly at
ctx.translate( window.innerWidth / 2, window.innerHeight / 2 )
ctx.rotate(cameraRotation*Math.PI / 180)
ctx.scale(cameraZoom, cameraZoom)
ctx.translate( -window.innerWidth / 2 + cameraOffset.x, -window.innerHeight / 2 + cameraOffset.y )

Regards Roger

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I found a solution:

https://codepen.io/rogerbuecker/pen/yLzYqXq

Missed the part where i invertSelf the Transformation to get the Position

var transform = ctx.getTransform();
const invMat = transform.invertSelf();
about 4 years ago · Juan Pablo Isaza Report

0

I don't have too much experience with canvas, but I have a little with css transform property.

Try to create a container object, inside it put whatever you have now. Then when you need to move the image or something related to have a persistant orientation just move or apply whatever you want to the big container, then to rotate do to the small one inside it.

Let me know if it works for you.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!