Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // vX - sprite's velocity in x direction
- const getVx = value<Velocity>('character.vX');
- const setVx = action<Velocity>('character.vX');
- const onVxChange = react<Velocity>('character.vX');
- // or simpler
- const [ getVx, setVx, onVxChange ] = state<Velocity>('character.vX');
- // read current value, e.g. inside the ticker to update sprite's x position:
- const ticker = () => {
- sprite.x += getVx();
- }
- // set new value
- const BOOST = 2;
- setVx(prevVx => prevVx * BOOST);
- // react to state change
- onVxChange((newValue, prevValue) => {
- // ...
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement