Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As a project developer, I want to be able to render the world to a canvas using a function #23

Closed
ryangrahamnc opened this issue Jul 29, 2022 · 7 comments

Comments

@ryangrahamnc
Copy link

The testbed is neat at all, but its only useful for proof of concepts. It also doesnt seem to be exposed anywhere. Which means anyone working on their own project will be unable to visualize their world unless they copypaste all their files into the testbed website.

What I'd prefer is a function to call that renders a world to canvas. (The original box2d.js has this, but that project is old and throws errors in modern environments. The dev also doesnt publish to npm despite having git updates)

I'd like something where I can run everything in a functional way in places that I control:

const initWorld = ()=>{ ... };
const tick = ()=>{
    handleInputs();
    world.step(time);
    renderWorld({ world, canvas });
};

I'm looking through the code, but it seems impossible to figure out how to get this working. I know the functionality is there given that the testbed works. But I dont understand why its not easily available.

I dont particularly care how the api looks. bounds, strokeColor, and strokeSize are good enough for me.
box2d.js has a class structure that probably works decently: https://github.com/kripken/box2d.js/#using-debug-draw

@Lusito
Copy link
Owner

Lusito commented Aug 28, 2022

Yes, I've thought about this too, back when I started this project. It wasn't easily possible then though. Can't remember the exact problems I faced. But I will take another look when I find some time.

@8Observer8
Copy link

8Observer8 commented Sep 1, 2022

These screenshots show how important it is to be able to draw colliders:

image

image

@Lusito
Copy link
Owner

Lusito commented Sep 4, 2022

I've just released @box2d/debug-draw, check the documentation here:
https://lusito.github.io/box2d.ts/docs/guide/debug-draw/

@Lusito Lusito closed this as completed Sep 4, 2022
@8Observer8
Copy link

8Observer8 commented Sep 6, 2022

I installed 0.10.0:

image

But I have the error:

image

I do not have the debug-draw folder inside of @box2d:

image

@Lusito
Copy link
Owner

Lusito commented Sep 7, 2022

@8Observer8 It seems npm had some issue installing. Have you tried just running npm install again?

Edit: Nevermind, you installed version 0.10 of the core library, but you didn't install @box2d/debug-draw

Try running npm install @box2d/debug-draw

@Lusito
Copy link
Owner

Lusito commented Sep 7, 2022

Just FYI, anything with an @ in front is a scope (think of it like a company/project prefix). I.e. @box2d is not a package, but rather @box2d/core, @box2d/lights, @box2d/particles, @box2d/controllers and @box2d/debug-draw are all separate packages you need to install separately.

@8Observer8
Copy link

I thought it would be like in C++. But okay, it's better than nothing. Thank you.

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

No branches or pull requests

3 participants