Closed MazeChaZer closed 5 years ago
Thanks for the feedback! This is like this because there's not really any difference in when these functions need to be called and it matches the Processing api.
If you really want this distinction, is there a downside to doing something like this? You could even call them update
and view
! 😛
let draw = (state, env) => {
...do draw things
};
let tick = (state, env) => {
...do tick things
newState
};
Reprocessing.run(
~setup,
~draw=((s, e) => draw(s, e); tick(s, e)));
Great idea, I didn't even think about doing that :sweat_smile:
This is what I'm doing now in my project. I just switched around the execution order of render
and tick
, so that the render
function gets the updated state from tick
:
let draw = (state, env) => {
let newState = tick(state, env);
render(newState, env);
newState;
};
Thanks for your quick response! You can close the issue if there are no further points :)
Awesome, glad to hear it helped. Let us know if you run into any other issues :)
I created my first reprocesing project today, worked really well :). A little thing I stumbled upon was how the
draw
function works. I was surprised that it renders the state but at the same time produces a new state. I was working withEnv.deltaTime
and asked myself: Should I first render the current state or should I first produce my new state and render that? After looking at the 2048 example I decided to first render the current state and then produce the new state afterwards. But thinking about it now it makes more sense to produce the new state first, so that the time delta is reflected in the rendering. Coming from Elm previously, I was used to the separation ofupdate
(which produces the new state) andview
(which renders the state). It seems to me, that this separation could simplify therun
function, too. Instead ofthere would be
Before each call of the
draw
function, thetick
function would be called, if it was defined. There stuff like time deltas can be handled. Then thedraw
function is executed and just renders the state. To me this is more intuitive, I'm really interested what others think about this.