rive-app / rive-wasm

Wasm/JS runtime for Rive
MIT License
669 stars 46 forks source link

rive advanced canvas has missing and incorrect types for Vec2D #265

Closed jrabek closed 1 year ago

jrabek commented 1 year ago

In order to use the code from rive-canvas that shows how to convert touch points into the coordinate system of the artboard, it is necessary to construct a 2d vector and also get the values from it.

Currently new rive.Vec2D in Typescript isn't possible since the type lacks a constructor that accepts x and y.

Also the return types of x and y are void. Also seems strange that they are functions and not just properties like the other math types in Rive.

https://github.com/rive-app/rive-wasm/blob/master/js/src/rive_advanced.mjs.d.ts#L660

/**
 * Rive Vector class
 */
export declare class Vec2D {
  /**
   * Returns the x coordinate of the vector
   */
  x(): void;
  /**
   * Returns the y coordinate of the vector
   */
  y(): void;
}
jrabek commented 1 year ago

I am reimplementing https://github.com/rive-app/rive-wasm/blob/master/js/src/utils/registerTouchInteractions.js#L18 in a Phaser friendly way.

Related: https://github.com/rive-app/rive-wasm/issues/262

jrabek commented 1 year ago

Here is how I am using it: https://github.com/jrabek/rive-phaser-plugin

zplata commented 1 year ago

Thanks for raising this @jrabek - we'll take a look at this and figure out what's going on. Also you're right..seems strange that it is methods for x and y. Also will take a look at changing that to properties and let you know if issues arise from that.

zplata commented 1 year ago

This should be fixed in 1.0.86. Just to be safe though, we'll still keep the x and y as functions on Vec2D but change them to properties in the next major bump of this runtime!

zplata commented 1 year ago

Closing for now, but happy to re-open if the new version is still an issue for you!