-
Notifications
You must be signed in to change notification settings - Fork 169
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
Can't destroy previous entities when game reloads #8
Comments
Hi @lupino22, Thanks for getting in touch. One of the the things I'm not currently happy with in the React Native Game Engine API is how the entities are updated externally. Currently, the game engine will hold a reference to your initial entities and only reload when the whole GameEngine unmounts and remounts or when the swap method is called Back to your issue in particular.. When you navigate away from your game and back again, is the component that contains your Another thing to keep in mind is that your setInterval callback will always and only have a reference to the entities that get passed into world_scale the first time it is called. If the entities get swapped - and the timer is not finished - it will still have a reference to the old entities. Lastly, what version of RNGE are you using? I pushed an update about a week ago that clears the events every time the Cheers! |
Hi @bberak Game Engine component is remounted when i navigate back and i use Also i managed the way to interrupt the intervals when game engine is unmounted. I'll keep in touch. Thanks for the response. |
Is there any way to make timed animation (like |
Hi @lupino22, I've built an "animation" system for one of my games that avoids the need to use external timers and callbacks. Perhaps you can adapt it to your needs. Here is the source of the animation: https://github.com/bberak/react-native-donkey-kong/blob/master/src/systems/animation.js And here is an example of how to use the system:
See https://github.com/bberak/react-native-donkey-kong/blob/master/src/systems/platforms.js for the full usage. |
Thanks @bberak I believe doing by your "animation" system is more proper way than mine. I'll try your "animation" system. Thanks for your effort. |
No worries @lupino22, let me know how it goes! |
Hello @bberak |
Hi @lupino22, Well at least we can cross the animations off the list :) You mentioned that the component is unmounted and re-mounted during the navigation process? Can you show me your render function? In particular, if you have something like this:
Or
Also, what does new World() return? Can you share a quick snippet to indicate the general code? If you're using a third party library like ThreeJS or something - you might need to clean up your scene.. If your scene is holding references to the old objects - it could still get rendered. Another way we can debug this would be to add a distinct entity into your world { "test": "Find me" } when the navigation occurs, and find and log this entity in your systems - that way you can be sure whether or not your systems are receiving the new entities or not. Also make sure your systems are not holding any references to the entities after they are done. The systems should always process the entities being passed into them by the engine. |
Redering
World:
|
Also i made something like this :p
|
Hi @lupino22, Can you try changing your code to (just for debugging) to something like this:
I say this because if your component is mounting and unmounting the game engine - then you probably don't need to swap manually. Also change your entities to:
Then check the value of test in your systems and see what is being printed:
Hopefully that will get us more info for debugging.. |
Hi @bberak I made changes that you've made and debugging
When i re navigate into game component
Look like i'm having multiple |
So I wonder if it's possible that you have multiple instances of the GameEngine running? Could it be that each time your are navigating, your navigation system is adding another GameEngine into the viewstack, and not popping off the current GameEngine when you are navigating away? |
Yes i think so. I'm about to change my navigation library which is |
Yeah that makes sense @lupino22. It might be worthwhile to put the
|
That is the one thing make me so confused. Component life cycle is just fine. When i re-navigate |
After the unmount happens, does you see logs in the console that indicate that the engine is still running? Also, do you need the Can you tell if |
Once i unmount happens, game engine will be not running. Just in case I put the
|
Hmm, I'd suggest the following:
|
That sounds really nice. Let me talk with my team about sharing my source code. How about I'll mail my response about this. |
Sounds good - @lupino22, if you do share some code - just completely strip out the proprietary stuff, a skeleton will do. Cheers. |
I've found the bug.. The GameEngine uses a timer to run the systems at ~60 fps. However, there is a bug with how I'm clearing subscribers during unmounting which means a reference to the update function (and potentially the entire GameEngine) was being kept in memory - hence multiple GameEngines could be running at the same time. This bug has been fixed in version 0.9.5 |
I've got system function to handle events like this way:
And function
world_scale
looks like:This function scales all the entities smoothly in given duration, constantly. Like camera zooming. Function works perfectly until i exit the game by navigating into the other component and re-enter to the game component. (I'm using
react-native-router-flux
to navigate)The problem is when i re-navigate into the game and dispatch the event
EV_CONTROL_CAMERA_SCALE
, then functionworld_scale
will be working with previous entities (which should be not existing). But in the meantime entities already rendered on the screen and not scaling.I think navigation is not the problem source. Every time when i navigate, i clear the previous state by using
Actions.reset
The text was updated successfully, but these errors were encountered: