Skip to content

Commit

Permalink
Added moveLOcalXY() that respects the Sprite rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfyxon committed Dec 18, 2023
1 parent b550a99 commit 4706c44
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/lib/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ function Sprite(image,x,y,rot,w,h){
spr.area.offsetVec(vector);
}

spr.moveLocalXY = function(x_, y_){
const angle = deg2rad(spr.rotation);
const localX = x_ * Math.cos(angle) - y_ * Math.sin(angle);
const localY = x_ * Math.sin(angle) + y_ * Math.cos(angle);
return spr.moveXY(localX, localY);
}

spr.rescale = function(scale){
spr.area.rescale(scale);
return spr;
Expand Down

0 comments on commit 4706c44

Please sign in to comment.