Jump to content

Using a vector class with sprites


SarahJ
 Share

Recommended Posts

you have to add more functions to Point and ObservablePoint prototypes. The thing is , its better not clone Observables because they affect transform cache calculations.

myMixin = {
   add: function() {... return new Point();} // return point everywhere
   subtract: function() { ... }
}

Object.assign(PIXI.Point.prototype, myMixin);
Object.assign(PIXI.ObservablePoint.prototype, myMixin);

sprite.position = point1.add(point2); // be aware that its NOT ASSIGNMENT, its value copy in setter.

 

 

Link to comment
Share on other sites

if you do mutable methods like these, dont forget that ObservablePoint has to notify transform: https://github.com/pixijs/pixi.js/blob/dev/packages/math/src/ObservablePoint.js#L52 , either you have to call "set" inside, either callback. 

using "set" inside those functions is good idea, because both Point and ObservablePoint implementations will be the same in that case.

Points class in pixi aren't universal. We didnt add those functions exactly because different users want different implementations for their games.

You're blessed for hacks ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...