scrollcam component#898
Conversation
| * @param x number | ||
| * @param y number | ||
| */ | ||
| setScrollFactor(x: number, y: number): void; |
There was a problem hiding this comment.
should be ...args: Vec2Args rather than hardcoding x and y
| * @subgroup Component Types | ||
| */ | ||
| export interface CamScrollComp extends Comp | ||
| { |
| * @returns The current factor of the object as a {@link Vec2 `Vec2`} | ||
| */ | ||
| getScrollFactor(): Vec2; | ||
| } |
There was a problem hiding this comment.
why is basePos not exposed on the interface
| //@ts-ignore | ||
| basePos: null as Vec2 | null, | ||
|
|
||
| add() |
There was a problem hiding this comment.
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.
you can just use update(this: GameObj<PosComp | CamScrollComp>) {
| }, | ||
|
|
||
| setScrollFactor(x: number, y: number) { | ||
| setScrollFactor(x: number, y: number) { |
| }, | ||
|
|
||
| getScrollFactor() { return this.factor.clone() }, | ||
| getScrollFactor() { |
There was a problem hiding this comment.
also are thes necessary when you can access the factor property (it's not private / in the closure)
| * @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.
now should be fixed
| }, | ||
|
|
||
| getScroll() { | ||
| return this.factor.clone(); |
There was a problem hiding this comment.
Why have getScroll if factor is public? Was factor supposed to be a closure variable instead maybe?
There was a problem hiding this comment.
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.
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.
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.
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
|
I made some changes to the parallax component because the old code has been broken, the effect has not being applied so, I used the literal of MoveBy to fix it |
|
|
||
| const delta: Vec2 = cam.sub(this.lastCam); | ||
| this.moveBy( | ||
| this.pos = this.pos.add( |
There was a problem hiding this comment.
moveBy does exactly this. You're saying it isn't working?
There was a problem hiding this comment.
I thought this was about organization, I will return back to the original version instead
There was a problem hiding this comment.
We might remove the pos setter/getter in the future and have only moveTo, moveBy and getPos. So it's better to leave moveBy.
There was a problem hiding this comment.
yea I notice I "can't" set the pos directly, that's why broke the old version.
There was a problem hiding this comment.
yea I notice I "can't" set the pos directly, that's why broke the old version.
There was a problem hiding this comment.
You can, just not pos.x or pos.y separately, you need to replace the entire pos. That's why we're thinking of removing that property.
There was a problem hiding this comment.
yea make sense, will be for good if those properties be private, only internal access
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