-
-
Notifications
You must be signed in to change notification settings - Fork 94
scrollcam component #898
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
base: master
Are you sure you want to change the base?
scrollcam component #898
Conversation
| * @param x number | ||
| * @param y number | ||
| */ | ||
| setScrollFactor(x: number, y: number): void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be ...args: Vec2Args rather than hardcoding x and y
| * @subgroup Component Types | ||
| */ | ||
| export interface CamScrollComp extends Comp | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
run pnpm fmt
| * @returns The current factor of the object as a {@link Vec2 `Vec2`} | ||
| */ | ||
| getScrollFactor(): Vec2; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is basePos not exposed on the interface
| //@ts-ignore | ||
| basePos: null as Vec2 | null, | ||
|
|
||
| add() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this add hook does nothing so remove it
commit: |
| update() | ||
| { | ||
| const obj = this as unknown as GameObj<PosComp> & { basePos: Vec2 | null }; | ||
| update() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just use update(this: GameObj<PosComp | CamScrollComp>) {
| }, | ||
|
|
||
| setScrollFactor(x: number, y: number) { | ||
| setScrollFactor(x: number, y: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also vec2args here
| }, | ||
|
|
||
| getScrollFactor() { return this.factor.clone() }, | ||
| getScrollFactor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also are thes necessary when you can access the factor property (it's not private / in the closure)
src/core/contextType.ts
Outdated
| * @param y number | ||
| * @returns the camera scroll comp | ||
| */ | ||
| scrollcam(x: number, y: number): CamScrollComp; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is bug??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now should be fixed
| }, | ||
|
|
||
| getScroll() { | ||
| return this.factor.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have getScroll if factor is public? Was factor supposed to be a closure variable instead maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably meant
let factor = vec2(...args);
let basePos = vec2();
return {
id: "scroll",
require: ["pos"],So they are inaccessible from outside
| }, | ||
|
|
||
| getScroll() { | ||
| return this.factor.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably meant
let factor = vec2(...args);
let basePos = vec2();
return {
id: "scroll",
require: ["pos"],So they are inaccessible from outside
| fixed(fixed?: boolean): FixedComp; | ||
|
|
||
| /** | ||
| * Make the object scrolls with camera based on a factor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also add a mention of "parallax scrolling" since that's what this component also does.
it might be more intuitive to rename the component as well to parallax() but that's up to you
| update(this: GameObj<PosComp | CamScrollComp>) { | ||
| const cam = getCamPos(); | ||
|
|
||
| if (!this.basePos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line will never work because you're setting it intially to the zero vector on line 29 which is an object and considered truthy
| basePos: Vec2; | ||
| } | ||
|
|
||
| export function scrollcam(...args: Vec2Args): CamScrollComp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another idea: instead of the vanishing point always being the camera position, you could have another argument that would change the vanishing point relative to the screen rectangle to change the perspective. So like for vec2(0, -1/3) would mean the vanishing point is in the center but 1/6 of the screen height below the camera.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain it a bit better? is not making much sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, you're asking for a way to set the point on any offset from the camera?
this could be good, I can try
added a new component, the
scrollcamcomponent implements a simple parallax system inspired by haxeflixel functions likesetScrollFactor.the example test also available for further test and verifications.
Summary
scrollcamcomponent2025-09-21.21-39-00.mp4