SHARE
TWEET

Untitled

a guest Jun 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // vX - sprite's velocity in x direction
  2. const getVx = value<Velocity>('character.vX');
  3. const setVx = action<Velocity>('character.vX');
  4. const onVxChange = react<Velocity>('character.vX');
  5.  
  6. // or simpler
  7. const [ getVx, setVx, onVxChange ] = state<Velocity>('character.vX');
  8.  
  9. // read current value, e.g. inside the ticker to update sprite's x position:
  10. const ticker = () => {
  11.   sprite.x += getVx();
  12. }
  13.  
  14. // set new value
  15. const BOOST = 2;
  16. setVx(prevVx => prevVx * BOOST);
  17.  
  18. // react to state change
  19. onVxChange((newValue, prevValue) => {
  20.   // ...
  21. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top