Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fromScreen not using viewport scale, mousePos() not working with letterbox/stretch #436

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/transform/pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ export function pos(...args: Vec2Args): PosComp {
// Transform a world point (relative to the root) to a local point (relative to this)
fromWorld(this: GameObj<PosComp>, p: Vec2): Vec2 {
return this.parent
? this.parent.transform.invert().multVec2(p).sub(this.pos)
: p.sub(this.pos);
? this.parent.transform.invert().multVec2(
p.scale(1 / getViewportScale()),
).sub(this.pos)
: p.sub(this.pos).scale(1 / getViewportScale());
},

// Transform a screen point (relative to the camera) to a local point (relative to this)
Expand Down Expand Up @@ -167,7 +169,7 @@ export function pos(...args: Vec2Args): PosComp {
const pos = this.toWorld(p);
return isFixed(this)
? pos
: k.toScreen(pos);
: k.toScreen(pos.scale(1 / getViewportScale()));
},

// Transform a screen point (relative to the camera) to a local point (relative to this)
Expand Down