Skip to content

liquidfun's GetPositionBuffer() doesn't return a list #77

Description

@ivan-enzhaev

I try to use liquid fun. GetPositionBuffer doesn't return a list:

    const positions = particleSystem.GetPositionBuffer();
    console.log(positions[0]);

I prints undefined.

But it must return a list because C++ works like this:

    b2Vec2 *pos = m_particleSystem->GetPositionBuffer();
    qDebug() << pos[0].x  << pos[0].y;

Full example that includes the liquid fun lib library: get-position-buffer-box2dwasm-js.zip

index.js

import { box2d, initBox2D } from "./init-box2d.js";

async function init() {
    await initBox2D();

    const {
        b2CircleShape,
        b2ParticleGroupDef,
        b2ParticleSystemDef,
        b2Vec2,
        b2World
    } = box2d;

    const world = new b2World();
    const pixelsPerMeter = 50;

    const particleSystemDef = new b2ParticleSystemDef();
    particleSystemDef.radius = 5 / pixelsPerMeter;
    const particleSystem = world.CreateParticleSystem(particleSystemDef);
    const spawnArea = new b2CircleShape();
    spawnArea.m_radius = 20 / pixelsPerMeter;
    spawnArea.m_p.x = 100 / pixelsPerMeter;
    spawnArea.m_p.y = 30 / pixelsPerMeter;
    const particleGroupDefinition = new b2ParticleGroupDef();
    particleGroupDefinition.shape = spawnArea;
    particleSystem.CreateParticleGroup(particleGroupDefinition);

    const positions = particleSystem.GetPositionBuffer();
    console.log(positions[0].x);
}

init();

index.html

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Liquid fun</title>
</head>

<body>
    <script type="importmap">
        {
            "imports": {
                "box2d-wasm": "/libs/box2d-wasm@7.0.0/es/entry.js"
            }
        }
    </script>

    <script type="module" src="./js/index.js"></script>
</body>

</html>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions