Closed sc0ttj closed 2 years ago
Ideally, to make this as generic, and reusable as possible, it should be done as a "ticker" ... something like so:
import { Component, onTick } from '@scottjarvis/component'
Component.onTick = onTick;
const Game = new Component({ ... });
Game.onTick(props => {
// the code here executes on a fixed-time loop
// ..update your game state here
});
Game.view = props => {
// define what to draw to canvas here
};
// render executes at a variable frame rate, namely as close to 60fps as possible
Game.render('.container')
Done, closing.
Do a "Game loop" addon - a proper fixed-time loop, with variable render loop.
See these links:
Game loops:
export default
)Libraries & Game engines:
Articles on proper game loops:
NOTES:
Dont use Euler loops, use semi-implicit Euler loops, or RK4..
Euler will crash with springs that don't end, RK4 is most accurate, but might be too "heavy"..
See https://gafferongames.com/post/integration_basics/ for explanation of these 3 types of loops.