Tick System for performing tasks X times a second.
npm install @stefftek/tick.js !License   !Build
npm i @stefftek/tick.js
`
or - script tag for the browser
`html
`Usage
$3
with Common JS
`js
/ Import Tick.js /
const TickSystem = require("@stefftek/tick.js");
`
or - TypeScript Import
`js
/ Import Tick.js /
import TickSystem from "@stefftek/tick.js";
`
$3
`js
/ Create New Tick System /
/ Starts Tick System aswell /
/ Default Tickrate: 64 /
const tickSystem = new TickSystem();/ To use other Tickrate /
const tickSystem = new TickSystem(32);
/ Add new Callback /
tickSystem.onTick(debug);
/ Remove Callback /
tickSystem.offTick(debug);
/ Debug Function /
function debug() {
console.log(tickSystem.currentTick);
}
/ Stop Ticking /
tickSystem.stop();
/ Start Ticking /
/ Only needed if stopped /
tickSystem.start();
`$3
`js
/ Wait 100 ticks till execution /
tickSystem.executeAfter(100, () => {
console.log("I ran after 100 ticks!");
});/ Wait 3 seconds till execution /
tickSystem.executeAfterSeconds(3, () => {
console.log("I ran after 3 seconds!");
});
`What is a tick rate?
Tick Rate defines how many times a second, the onTick function will execute. A much more simple explaination: Tick Rate is __kinda__ like FPS in Games. More FPS means smoother animations or physics interpolation, but the cost is a higher usage of system resources.
Variables
`js
tickSystem.callbacks : Array // All Callbacks that are registeredtickSystem.tickRate : Number // Tick rate specified on creation
tickSystem.currentTick : Number // The current tick from 0 to (tickRate - 1)
tickSystem.tickLatency : Number // Latency between the ticks in ms
tickSystem.tickDelta : Number // Latency between the ticks in seconds
tickSystem.lastTick : Number // Timestamp in ms of the last executed tick
tickSystem.tickTime : Number // Time in ms per tick
tickSystem.performanceMonitor : PerformanceMonitor // Performance Monitor if enabled
`$3
Performance Monitoring
$3
To measure the performance of the tick system, you can enable performance monitoring.
`js
tickSystem.monitor(true);
`
To Disable, use .monitor(false);Performance Reports can be collected either manual or for
- the last frame
- the last second
- and for the last 5 seconds
combined.
To collect performance reports, either use
`js
tickSystem.performanceMonitor.report()
`
for a group report, or
`js
tickSystem.performanceMonitor.singleReport(10) // Tick count
``