I need help. I have a player and I want jump the player in same diametric order. I wanted to fix this with getHeight with return ( innerHeight/100 * per ), but there's no improvement. Even worse, if the canvas size becomes bigger the player doesn't jump as high and if the window becomes smaller the player jumps higher! I dont want to callibrate in hard code way. I need responsive function!
"leave a comment before vote negative"
r.player.force = {
x: 0,
y: -(getHeight(0.03)),
};
Matter.Body.applyForce(r.player, { x: r.player.position.x, y: r.player.position.y }, r.player.force);
public getHeight(percente: number): number {
return this.reperH() / 100 * percente;
}
this.reperH = function () {
if ((window as any).innerHeight > (window as any).innerWidth / this.aspectRatio) {
return (window as any).innerWidth / this.aspectRatio;
} else {
return (window as any).innerHeight;
}
};
Full source : link
I figure that matter.js already have diametric scale with simple number inputs.
When i remove all getHeight and getWidth and put numbers everything start works fine again.
It is my solution for any platform to get percent always no matter for screen size. My opinion : Matter.js looks like good solution.