Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

746 B
Raw Blame
import {
    defineSystem, Query, Mut, Res, Time, Commands,
    Transform, Sprite,
} from 'esengine';
import { Trail } from '../components';

export const trailSystem = defineSystem(
    [Query(Mut(Transform), Mut(Sprite), Mut(Trail)), Res(Time), Commands()],
    (query, time, cmds) => {
        for (const [entity, transform, sprite, trail] of query) {
            trail.lifetime -= time.delta;
            sprite.color.a = Math.max(0, trail.lifetime);
            transform.scale = {
                x: trail.lifetime * 1.5,
                y: trail.lifetime * 1.5,
                z: 1,
            };

            if (trail.lifetime <= 0) {
                cmds.despawn(entity);
            }
        }
    },
    { name: 'TrailSystem' }
);