Skip to content

Fix clamp not updating on screen size changes #517

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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: 7 additions & 1 deletion src/plugins/Clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
y: number | null;
scaleX: number | null;
scaleY: number | null;
screenWidth: number | null;
screenHeight: number | null;
};

protected noUnderflow!: boolean;
Expand Down Expand Up @@ -124,7 +126,7 @@
}

this.parseUnderflow();
this.last = { x: null, y: null, scaleX: null, scaleY: null };
this.last = { x: null, y: null, scaleX: null, scaleY: null, screenWidth: null, screenHeight: null };
this.update();
}

Expand All @@ -144,13 +146,13 @@
else
{
this.underflowX
= clamp.indexOf('left') !== -1

Check warning on line 149 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Do not nest ternary expressions
? -1
: clamp.indexOf('right') !== -1
? 1
: 0;
this.underflowY
= clamp.indexOf('top') !== -1

Check warning on line 155 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Do not nest ternary expressions
? -1
: clamp.indexOf('bottom') !== -1
? 1
Expand Down Expand Up @@ -179,6 +181,8 @@
&& this.parent.y === this.last.y
&& this.parent.scale.x === this.last.scaleX
&& this.parent.scale.y === this.last.scaleY
&& this.parent.screenWidth === this.last.screenWidth
&& this.parent.screenHeight === this.last.screenHeight

Check warning on line 185 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
)
{
return;
Expand Down Expand Up @@ -257,8 +261,8 @@
= -(this.options.right === true
? this.parent.worldWidth
: this.options.right)
* this.parent.scale.x

Check warning on line 264 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations
+ this.parent.screenWidth;

Check warning on line 265 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations
decelerate.x = 0;
moved = true;
}
Expand Down Expand Up @@ -343,8 +347,8 @@
= -(this.options.bottom === true
? this.parent.worldHeight
: this.options.bottom)
* this.parent.scale.y

Check warning on line 350 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations
+ this.parent.screenHeight;

Check warning on line 351 in src/plugins/Clamp.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations
decelerate.y = 0;
moved = true;
}
Expand All @@ -363,6 +367,8 @@
this.last.y = this.parent.y;
this.last.scaleX = this.parent.scale.x;
this.last.scaleY = this.parent.scale.y;
this.last.screenWidth = this.parent.screenWidth;
this.last.screenHeight = this.parent.screenHeight;
}

public reset(): void
Expand Down
Loading