Skip to content

Conversation

@itzKiwiSky
Copy link
Contributor

added a new component, the scrollcam component implements a simple parallax system inspired by haxeflixel functions like setScrollFactor.

the example test also available for further test and verifications.

Summary

  • scrollcam component
  • test for the component
2025-09-21.21-39-00.mp4

* @param x number
* @param y number
*/
setScrollFactor(x: number, y: number): void;
Copy link
Contributor

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
{
Copy link
Contributor

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;
}
Copy link
Contributor

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()
Copy link
Contributor

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/kaplayjs/kaplay@898

commit: 60f1bca

update()
{
const obj = this as unknown as GameObj<PosComp> & { basePos: Vec2 | null };
update() {
Copy link
Contributor

@dragoncoder047 dragoncoder047 Sep 22, 2025

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) {
Copy link
Contributor

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() {
Copy link
Contributor

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)

* @param y number
* @returns the camera scroll comp
*/
scrollcam(x: number, y: number): CamScrollComp;

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is bug??

Copy link
Contributor Author

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();
Copy link
Member

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?

Copy link
Member

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();
Copy link
Member

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

@lajbel lajbel added this to the 4000.0.0-alpha.24 milestone Nov 4, 2025
fixed(fixed?: boolean): FixedComp;

/**
* Make the object scrolls with camera based on a factor
Copy link
Contributor

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) {
Copy link
Contributor

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

@lajbel lajbel removed this from the 4000.0.0-alpha.24 milestone Jan 1, 2026
basePos: Vec2;
}

export function scrollcam(...args: Vec2Args): CamScrollComp {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants