Comments (12)
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 withKINEMATIC
boy type? And how to test the collision betweenDYNAMIC
body withKINEMATIC
body?
Thanks!
from flame.
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.
@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.
Just created an API: 443f304
Box2DComponent.remove(BodyComponent)
from flame.
@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.
@feroult
I got it, thank you!
I edit the source code in my project, and I found some problems:
- I cannot add any common
component
likeParallaxComponent
andAnimationComponent
anymore - I removed the body, however, it still situated in the world, and responses the physics
- I found that
userData
defined inBodyDef
orBody
is useless. After reading the source code, I change the code infixture.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.
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.
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.
@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.
@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.
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.
@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)
- JoystickComponent onLoad no longer works starting v1.15 HOT 1
- Rays outside a CircleHitbox are seen by RaycastResult as inside. HOT 3
- Keyboard not working when resizing the web HOT 5
- Support dynamic changes to the layer opacity on tiled maps
- Tilemaps error occuring on Chrome mobile HOT 2
- ZigZagController with ColorEffect causes an exception HOT 4
- TextBoxComponent with typer text shows pink image before rendering text HOT 5
- SpriteWidget has unused parameters HOT 1
- Anchor is invalid when transform by matrix4 ?
- Klondike Tutorial, Step 5: Add code and further explanation of FlatButton and others, or at least a link to its code #19 HOT 6
- Strange phenomenon in flame rendering text HOT 7
- Convert ClipComponent factory Constructor to redirecting Constructor. HOT 1
- Unable scroll the text of the ScrollTextBoxComponent if I do not use timePerChar HOT 1
- Can not find asset when Flame Game is used as a module or package HOT 8
- texture packer can't override images HOT 6
- I'd like to call the child onRemove. HOT 4
- Add onComplete callback to ScrollTextBoxComponent HOT 2
- Flame + Forge2D + Riverpod == broken? HOT 1
- Change `Forge2DGame`'s `cameraComponent` constructor parameter to `camera` for consistency with `FlameGame`
- Not compatible contact type HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flame.