Comments (6)
I added
Matter.Body.scale(bodyB, 0.1, 0.1, {x: bodyB.bounds.min.x-1000, y: bodyB.bounds.max.y});
before the remove function and now the bodies are disappearing as intended, but I'm not sure if this is a good workaround.
from react-native-game-engine.
Hi @ahmdsdk,
Did you get this issue sorted? Also, are you using the GameEngine component or the GameLoop?
The reason I ask is because if you're using the GameEngine - all your logic should generally go in the Systems functions - and not in the entities themselves (ie the componentDidMount function).
Here is an example of how I removed bodies in the React Native Donkey Kong game: https://github.com/bberak/react-native-donkey-kong/blob/master/src/utils/barrels.js
from react-native-game-engine.
Hello again @bberak
Thank you for replying.
I've been working while skimming through your Donkey Kong project.
I think I got this sorted by scaling them down to nothing, but I don't think that's a good way to do it. I will use the visible property and recycle the same bodies, which could improve the performance.
I'm using the GameEngine, and I'm removing the bodies in the Systems with a RemoveBodies function which looks for events that are triggered in the collisionStart in the componentDidMount, but only for when game is over, I will also do that for all collision events.
Again, thanks a lot for your reply.
from react-native-game-engine.
Hi @ahmdsdk - don't mention it!
Glad you got this sorted at least. Interesting approach regarding the collision triggers in the componentDidMount function - just remember to clean up any event listeners in the componentWillUnmount function too.
from react-native-game-engine.
Hi @bberak
I guess I thought that I got this sorted it out but it seems that this is actually what was causing the game to lag (I think). Btw, about clearing the event listeners I tried using DeviceEventEmitter with addListener and removing it in componentWillUnmout but it didn't seem to clean the Matter.Events. I guess now I have two issues regarding removing the bodies from the screen and cleaning the event listeners.
I have created an expo snack with how the I approached the game. I will keep trying to solve this, but I would appreciate any feedback or help. Thank you again.
EDIT:
I even tried Matter.Events.off in componentWillUnmount but it doesn't seem to work.
componentWillUnmount(){ Matter.Events.off(engine, 'collisionStart', () => { console.log("CLEARED EVENT"); }); }
from react-native-game-engine.
Hello @bberak
I just figured out my mistakes. Sorry for wasting your time. I realized that I wasn't properly deleting the bodies after they have fallen out of the screen. I thought that Matter.World.remove(world, body); was enough to remove them from the world; although I realized it didn't I kept trying different ways, until I went through your RNDK repo and realized that you were actually deleting the item from the object entities. When I did that all the lagging stopped :D!
Excuse my ignorance but I have just started recently with Matter js and RNGE. I also decided not to go with the Matter.Events.on() subscription but instead followed your method using Matter.Query.ray(). Thanks again for your time.
On iOS release is working perfect now. I think both these issues have been solved and I can close them now. I'm going to check out the performance on android.
In the future I will fix the repo and the snack to represent the current fixes.
Many thanks again for this awesome library.
from react-native-game-engine.
Related Issues (20)
- Touch array is empty in iOS HOT 1
- Functions not in TypeScript definition files HOT 8
- How can i catch in Entity onPress event and value on System.js HOT 3
- Custom fonts used inside GameEngine not working
- Default timer doesn't stop when calling `.stop()` HOT 3
- Nested entity property change doesn't trigger rerender process HOT 3
- How to use TouchEvent for continious handelrs? HOT 1
- Systems functions
- FPS issues HOT 9
- Add animation for moving HOT 10
- Best Way to handle touch as directional control HOT 3
- Support for Expo SDK 43, 44, 45 HOT 7
- Cant handle multitouch operations and it is really slow HOT 4
- How to change Game Engine's coordinate ?
- Tilemap free pan
- while dragging create line like WordSearch game
- What type of game can i build???
- is there anyone who is maintaining this library yet? HOT 2
- GameEngine re-rendering on entities change HOT 3
- Types not importing; not a real fix, but raising the issue 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 react-native-game-engine.