> let Plane_SPEED=22;
> let plane$ = game$.pipe(
> withLatestFrom(input$,input2$)
>
> ,scan(([ss,s,w],[ticl,toc,tic]) => {
> let Plane_WIDTH=100;
> let speed=2
> if(s==undefined){s=0}
>
> let next=this.paddlepos+toc*33*ticl.deltaTime
>
> return Math.max(Math.min(next, this.myCanvas.nativeElement.width - Plane_WIDTH / 2), Plane_WIDTH / 2);
> }),
> // sample(input$),
> distinctUntilChanged())
>
> plane$.subscribe(data=>this.update(data))
>
> const input$ =
> merge(
> fromEvent(document, 'keydown', event => {
> let x=this.paddlepos;
> switch (event.keyCode) {
> case PADDLE_KEYS.left:
> return this.paddlepos=-1
> case PADDLE_KEYS.right:
> return this.paddlepos=+1
> default:
> return null;
> }
>
> ))
> const game$ =interval(22, animationFrameScheduler ).pipe(
> map(() => ({
> time: Date.now(),
> deltaTime: null,
> //pox:this.myCanvas.nativeElement.width / 2
> }))
> ,scan(
> (previous, current) => ({
> time: current.time,
> deltaTime: (current.time - previous.time) / 1000,
> // pox: (current.pox+previous.pox)
>
> })
> ))
Okay so this is the code I know it is maybe needed to do a codepen but my question is about this code,
right now the expected behaviour is to have a box animated every frame in browser and when i press arrow left and right it is suppose to move while i hold the key only… but actual behaviour is i press right arrow and i get a smooth movement to the right stopping outside half the canvas if i press left it fixes itself in the start position… and code in pure js is just observable. dot notation to acess the operators in typescript u need to use pipe, etx if Anyone good at math know this stuff Id be happy =)