Skip to content

Commit

Permalink
Added rotateTowardsXY() and rotateTowardsVec() to Sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfyxon committed Dec 15, 2023
1 parent 3aa8261 commit ec2407c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scripts/lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ function Sprite(image,x,y,rot,w,h){
return spr;
}

spr.rotateTowardsXY = function(x_, y_) {
const deltaX = x_ - spr.getX();
const deltaY = y_ - spr.getY();
spr.rotation = rad2deg( Math.atan2(deltaY, deltaX) );
return spr;
}

spr.rotateTowardsVec = function(vector){
return spr.rotateTowardsXY(vector.x,vector.y);
}

spr.render = function(canvas){
if(!spr.visible) return;
const ctx = canvas.getContext("2d");
Expand Down

0 comments on commit ec2407c

Please sign in to comment.