okay okay got it, but could you tell me how i could subscribe to browser scroll event?
by user 263967078346653697
okay okay got it, but could you tell me how i could subscribe to browser scroll event?
by user 263967078346653697
i dont even know where to search for it
by user 263967078346653697
but this is html?
by user 263967078346653697
Itβs javascript
i mean this looks like it also requires html page to scroll
by user 263967078346653697
got this without changing any scripts
by user 263967078346653697
says timelinedirectordoesnt exist
by user 263967078346653697
hmm
by user 263967078346653697
its here
by user 263967078346653697
on the same object just like the sample
by user 263967078346653697
It says that the value being set to time is not a number (it happens for example is something is divided by 0)
okay so it has to be that html window is not found
by user 263967078346653697
i looked over the scollytelling sample once more
by user 263967078346653697
i dont see how it has the html scroll thingy
by user 263967078346653697
import { Behaviour, PlayableDirector, serializeable } from "@needle-tools/engine";
import { Mathf } from "@needle-tools/engine/src/engine/engine_math";
// Documentation β https://docs.needle.tools/scripting
export class ScrollTimeline extends Behaviour {
@serializeable(PlayableDirector)
timeline?: PlayableDirector;
@serializeable()
startOffset: number;
@serializeable()
lerpSpeed: number = 2.5;
private targetTime: number = 0;
start() {
window.addEventListener("wheel", (evt: WheelEvent) => this.updateTime(evt.deltaY));
let lastTouchPosition = -1;
window.addEventListener("touchmove", (evt: TouchEvent) => {
if (lastTouchPosition === -1) {
lastTouchPosition = evt.touches[0].clientY;
}
const delta = evt.touches[0].clientY - lastTouchPosition;
if (delta < 10) {
this.updateTime(-delta);
}
lastTouchPosition = evt.touches[0].clientY;
});
}
private updateTime(delta) {
if (!this.timeline) return;
this.targetTime += delta * 0.01;
this.targetTime = Mathf.clamp(this.targetTime, 0, this.timeline.duration);
}
onBeforeRender(): void {
if (!this.timeline) return;
this.timeline.pause();
this.timeline.time = Mathf.lerp(this.timeline.time, this.targetTime, this.lerpSpeed * this.context.time.deltaTime);
this.timeline.evaluate();
}
}
alternative version with mousewheel and touch scroll
hahaaaa
by user 263967078346653697
it works! If i were to make it a separate script
by user 263967078346653697
would i need to take care of the npm thing?
by user 263967078346653697
I just pushed it to the samples repo too. Made some minor tweaks but its essentially the same