Giter VIP home page Giter VIP logo

Comments (6)

ahmdsdk avatar ahmdsdk commented on May 18, 2024

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.

bberak avatar bberak commented on May 18, 2024

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.

ahmdsdk avatar ahmdsdk commented on May 18, 2024

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.

bberak avatar bberak commented on May 18, 2024

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.

ahmdsdk avatar ahmdsdk commented on May 18, 2024

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.

ahmdsdk avatar ahmdsdk commented on May 18, 2024

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)

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.