Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  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. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement