UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

34 lines (24 loc) 956 B
import { clamp01 } from "../../../../../core/math/clamp01.js"; import { RIBBON_ATTRIBUTE_ADDRESS_AGE, RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET } from "../ribbon_attributes_spec.js"; /** * Fixed function simulation engine for ribbons */ export class RibbonXFixedPhysicsSimulator { /** * * @param {RibbonX} ribbon * @param {number} max_age * @param {number} timeDelta */ update(ribbon, max_age, timeDelta) { const n = ribbon.getCount(); for (let i = 0; i < n; i++) { // age the ribbon const age = ribbon.incrementPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_AGE, timeDelta); const relative_age = clamp01(age / max_age); // apply alpha over-time ribbon.setPointAlpha(i, 1.0 - relative_age); ribbon.setPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET, relative_age); } } }