kaplay icon indicating copy to clipboard operation
kaplay copied to clipboard

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

Open lajbel opened this issue 1 year ago • 5 comments

Description

Issues or related

  • Related Issue #
  • Closes #325

lajbel avatar Oct 06 '24 14:10 lajbel

Open in Stackblitz

pnpm add https://pkg.pr.new/kaplayjs/kaplay@436

commit: 7381226

pkg-pr-new[bot] avatar Oct 06 '24 14:10 pkg-pr-new[bot]

Additionally, you don't want to divide each time, it is better to store 1 / factor and multiply instead.

mflerackers avatar Oct 06 '24 14:10 mflerackers

So scale is fine now, it's stretch that is bugged. If letterbox: true then it works since the canvas's aspect ratio is as specified. stretch makes it not be as specified, so it gets off.

kaplay({
    scale: 3,
    width: 20,
    height: 40,
    stretch: true
});

const x = add([
    anchor("center"),
    circle(3),
    color(RED),
    pos(),
]);

getTreeRoot().use(pos());

onMouseMove(pos => {
    x.pos = getTreeRoot().fromScreen(pos);
});

dragoncoder047 avatar Oct 06 '24 19:10 dragoncoder047

Yeah, when stretch is used, you no longer have a uniform scale. You need a vec2 in that case.

mflerackers avatar Oct 06 '24 22:10 mflerackers

So scale is fine now, it's stretch that is bugged. If letterbox: true then it works since the canvas's aspect ratio is as specified. stretch makes it not be as specified, so it gets off.

kaplay({
    scale: 3,
    width: 20,
    height: 40,
    stretch: true
});

const x = add([
    anchor("center"),
    circle(3),
    color(RED),
    pos(),
]);

getTreeRoot().use(pos());

onMouseMove(pos => {
    x.pos = getTreeRoot().fromScreen(pos);
});

The question is if there's an user case using only Stretch without letterbox

lajbel avatar Oct 13 '24 22:10 lajbel

resolved conflicts in commit 894d9df6d65baa497d017fb09db200cb39066eae

niceEli avatar Oct 30 '24 20:10 niceEli

no idea for fail should of worked properly

niceEli avatar Oct 30 '24 20:10 niceEli