GithubHelp home page GithubHelp logo

Comments (12)

spkingr avatar spkingr commented on May 5, 2024

Another question:

  • How to destroy or remove the component from the game world? I use component.world.destroyBody(component.body); , but it not works.
  • Can ContactListener work with KINEMATIC boy type? And how to test the collision between DYNAMIC body with KINEMATIC body?

Thanks!

from flame.

luanpotter avatar luanpotter commented on May 5, 2024

Hi, @spkingr ! Maybe it's not so clear in the docs, but textureWidth should be the width of each frame of the animation, in your case, 250.0 px. That's because the width of the whole image is know by the Animation Component, but you need to specify how to slice the image to select your frames. Maybe it's a huge spritesheet and your assets are just a small section.

Regarding the box2d related questions, maybe @feroult can help you out better than me :)

from flame.

feroult avatar feroult commented on May 5, 2024

@spkingr Inside a Box2DComponent we have the world and components attribute. The first controls the mechanics and the later the rendering. You can check the top of the file:

  World world;
  List<BodyComponent> components = [];

I think the problem is that the world.destroyBody is not removing the component from the components list.

It is probably a better design to have an API to make the process of creating and destroying bodies atomically change this two variables.

from flame.

feroult avatar feroult commented on May 5, 2024

Just created an API: 443f304

Box2DComponent.remove(BodyComponent)

from flame.

spkingr avatar spkingr commented on May 5, 2024

@luanpotter Thanks very much! I have tried and it works fine now. Is there any API like flip or scaleX to flip the animation sprites? The swan sprite is always backward with face forward.

from flame.

spkingr avatar spkingr commented on May 5, 2024

@feroult
I got it, thank you!
I edit the source code in my project, and I found some problems:

  1. I cannot add any common component like ParallaxComponent and AnimationComponent anymore
  2. I removed the body, however, it still situated in the world, and responses the physics
  3. I found that userData defined in BodyDef or Body is useless. After reading the source code, I change the code in fixture.dart, this line:
void create(Body body, FixtureDef def) {
    userData = def.userData;
    //...

to

void create(Body body, FixtureDef def) {
    //userData = def.userData;
    userData = body.userData;
    //...

It works for me now in collision detection.

I try to change the code in Box2DComponent class:

void remove(BodyComponent component){
    components.remove(component);

    component.body.setActive(false); //added
    component.body.userData = null; //added
    world.destroyBody(component.body);
}

@override
  void render(canvas) {
    if (viewport.size == new Size(0.0, 0.0)) {
      return;
    }
    components.forEach((c) {
      if(c.body.isActive()){ //added
        c.render(canvas);
      }
    });
  }

But the problem 1 and 2 still there, help, thanks!

from flame.

feroult avatar feroult commented on May 5, 2024

I made this change to the API so the Box2D Component would only accept BodyComponents and no regular components anymore.

You can still mix then in the higher-level Game render method.

I think this way we have a better design, what do you think?

from flame.

spkingr avatar spkingr commented on May 5, 2024

That's okay, separate the physic components with regular ones will be much more efficiency. And I think sometimes the simple game won't need physic at all, supply some util methods for math is enough.
By the way, can we use libgdx in Flutter?

from flame.

luanpotter avatar luanpotter commented on May 5, 2024

@spkingr, AFAIK it's not possible to use libgdx with flutter; libgdx is a different framework that works with Java and also provide the ability to make multi-platform games, but their are not compatible. In flame we use Flutter low levels API to render, witch are similar to OpenGL bindings, but not exactly the same.

from flame.

spkingr avatar spkingr commented on May 5, 2024

@luanpotter I got it. I have cloned flame library just now, I will try to make clear how the code works, try to have a look insight into it. I think make games in Flutter is great and challengeable. By the way, where should I get started to dive into? Thanks. :)

from flame.

luanpotter avatar luanpotter commented on May 5, 2024

I'd suggest reading the README.md tutorial, it's the very basic needed for a very simple game (probably you've already done so and are more advanced). Then, you can read the complete guide for more in-depth explanations, the source code & docs have pretty good details too. Finally, take a look at our 'sample' games;

  • flame-example: is VERY simple, comes with a tutorial, a bit outdated
  • bgug: a complete game, a bit outdated as well, but finished with most stuff a game could have (no box2d though)
  • haunt: an incomplete game featuring box2d and the most recent version of the APIs, has a few features but is not finished yet

You can also open issues with questions, help with PRs and please send us your work to eventually be showcased here (we are planning on something along those lines).

Thanks for your interest!

from flame.

luanpotter avatar luanpotter commented on May 5, 2024

@spkingr I will close this issue for now, if you have more questions or would like to submit issues, prs, et cetera, please feel free to open new issues!

from flame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.