Hello there,
I’m a totally newbie if it comes to Phaser and I have two main questions about it (we’re talking about Phaser 3 here).
I’m gonna provide a little bit of context: so I’m creating a game, where math equations are falling from the top of the canvas, on the bottom there are spikes, if math equation reaches the bottom it’s being destroyed and a life is taken from the player. The player has to provide answers for the lowest math equation on the screen, before it gets to the spikes.
I want to embed this game inside React project, so my first question is how to properly use it with React, because I want to trigger actions on impact with spikes etc, that will update score, lives and push it to the backend after the game is finished.
The second question is: how to get always the lowest equation on screen (closest to the spikes) in a way that user can put answer in an input and it’ll be checked with the lowest equation (node?). For now I have only falling circles. I want to somehow get always the lowest circle visible and check if the string equation that it has is answered correctly, if yes the score should be increased and equation removed from the screen.
Thank you for your response @yannick I really appreciate the attitude Yes, that is working! Do you maybe have any idea for the second question? How to always get the lowest falling equation on screen and check is result inputted by user is correct?
You are creating a new bubble and destroying if after it hits a spike.
You should create a phaser group, with maybe 3 - 4 bubbles. And instead of destroying it, reset its position.
This is more efficient and you can then simply iterate through the bubbles group bubbles.children.each(bubble=>{}) and get the y value of each bubble. The bubble with the highest y value is the lowest.
iterate (where? within update method?) constantly over them to get the lowest?
If it’s solved correctly I should reset position of that bubble to somewhere over the screen and load new equation to it?
If it reached the spikes remove one life and do the same as above
Would you mind, if you of course have the time, creating a small snippet with only that lowest bubble logic within update() or smth?
My main concerns here are:
how to in a proper way generate “new” bubbles within a group (the case is they should also keep falling faster and more of them should appear during the time of the game)
would it be okay to iterate all the time over those bubbles? Should I do it in update()?
Yes, yes, I’ve went through many of them, but wasn’t able to find something similar, I’m gonna investigate more and ask questions if something will be unclear
@yannick hi, sorry I ask question here…
Do you know how to go to other react component, like using “this.props.history.push(”/"), because I can not using in phaser+react component like this: