From 4706c44079e1160a73fd33833c284ad5ab2a4093 Mon Sep 17 00:00:00 2001 From: Wolfyxon Date: Mon, 18 Dec 2023 16:51:39 +0100 Subject: [PATCH] Added moveLOcalXY() that respects the Sprite rotation --- scripts/lib/game.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/lib/game.js b/scripts/lib/game.js index 55a5c401..77b1f322 100644 --- a/scripts/lib/game.js +++ b/scripts/lib/game.js @@ -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;