-
Notifications
You must be signed in to change notification settings - Fork 176
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
Multi-touch Support between GameEngine and View #55
Comments
Hi @xiendong, This should be possible - it was initially designed to work that way, but it could be that a new version of React Native introduced some issues with these edge cases. You could try playing around with the Otherwise, if you could share your code via a snack - I'd be happy to fire up my old Android device and do some debugging. These things are not always easy to track down because it really depends on the style and component tree of your app. Cheers! |
Hello @bberak, thanks for the swift reply. Here is a sample code on snack: On iOS, the |
Thanks @xiendong - I'll take a look. I've just bricked my old android device - so trying to find a cheap alternative (picking something up tomorrow)! |
Hi @xiendong, I got my Android device up and running and was able to reproduce the issue. I can confirm that this is an Android (React Native on Android?) issue - nothing related to RNGE (at least not directly). What I mean by that is - if you remove the That said, I was able to fix the problem by using the I hope that helps and let me know how it goes! |
Hello, looks like the snack is causing some confusion. Grey colouring does not indicate that it is actually pressed ( With the top-most box as Box 1 and the bottom-most box as Box 4, Box 1 is a component that consists of By using RN Gesture Handler's
The behaviour is consistent with the description above when Do you have any advice on this? Thanks! |
Hey @xiendong, Sorry, I've tried several things but cannot get the behaviour to be consistent and correct like with iOS. I'll let you know if any of my attempts work. Can I ask what your end goal is? Perhaps this is something you can design differently to overcome this challenge? Alternatively, perhaps you can make the |
Currently, I have a touchable game that uses the |
Can these buttons be moved inside the Tomorrow I'll try adding some |
I realised in Here are some relevant issues: For now, I reattempted your initial solution by using a touchable from Thanks for your help so far! |
Hi @xiendong, I'm glad you got it working. Yes, under the hood RNGE uses the //-- React syntax might not be correct, just a quick example
export default function App() {
...
const handleTouchStart = ev => this.refs.gameEngine.onTouchStartHandler(ev);
const handleTouchMove = ev => this.refs.gameEngine.onTouchMoveHandler (ev);
const handleTouchEnd = ev => this.refs.gameEngine.onTouchEndHandler(ev);
return (
<View style={styles.container}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}>
<GameEngine
ref={"gameEngine"}
handleTouches={false} //-- This would be a new prop to prevent the game engine from handling touches
style={[gamePressed ? styles.pressDown : styles.pressUp]}
systems={[handleGamePress]}>
<Text>TouchableWithoutFeedback Game Engine {gamePressed ? 'YES' : ''}</Text>
</GameEngine>
//-- Other touchable components go here..
</View>
);
} That said, I'm not sure if this will help in your situation.. Ideally the developer won't have to worry about this touch handling stuff - and we'll have parity between iOS and Android. |
Hmm, I'm not sure too. I think the main problem lies in the inconsistent Thanks for your quick support nonetheless! |
Hello @bberak, I just realised that my approach still doesn't work. While the |
Alright @xiendong, I'll create a branch and we can try a few things. It doesn't sound like an ideal solution though - is there any way you can create these buttons as game entities (and therefore within the view of the game engine)? |
Hmm, it might not be elegant too, but let me think how to dispatch the touch callbacks from |
Ahh okay, thanks for the context @xiendong - that helps me visualize the problem. You might already be aware, but there is a |
Hey @xiendong, Not sure how far you've gotten with this, but here is kind of where my head was going with this problem (although it is not an ideal solution): https://snack.expo.io/@bberak/authentic-banana |
Hello @bberak, I’ve been working on the other parts of the game, so I haven’t work on a fix for the bug yet. I saw your solution, and I was thinking how it might impact the positioning of the sprites in the game. I’m not sure if I have the control over how the sprites are rendered (meaning that I might not be able to nicely bound the sprites up in a box via children of some I am wondering if a What do you think? Thank you for your help! |
Hi @xiendong, Sorry I didn't quite follow the above but it sounds like the default rendering method of the import MyCustomRenderer from "./my-custom-renderer";
...
<GameEngine
systems={[]}
entities={{}}
renderer={MyCustomRenderer}
/> Here is the source code of the DefaultRenderer. In a nutshell, it loops through the entities and renders the ones that have a Let me know if that helps! |
Hello! Sorry for the delayed reply, was busy with other things as well. I eventually solved the touch problem by having a parent touch component |
Nice solution @xiendong! Did you provide a new |
@xiendong Any chance you could post your solution? I'm actually trying to get react-native-game-engine working for react-native-web but I'm not having any luck with the default |
@bberak I didn't provide a new Separately, I realised that there is actually no need to keep entities as state, but as ref instead if there is a way to cause the react component to update at each screen refresh (e.g. via a state counter). Empirically it seem to be more efficient but at least it's more explicit that the entities object should be mutated rather than copied. Thanks! |
@cmaycumber I'm not quite sure if my solution would help you because you might not be able to directly call touch event handlers from react-native-web. Let me know if you do and then I'll find a way to post my solution. Thanks! |
Hi @cmaycumber, I'm not too familiar with |
I'll definitely look into it a bit for you. That would be great if the touch processor worked with RNW out of the box! From my current understanding I think the problem resides with touches being treated separately from clicks because it seems to work on mobile devices in the browser. I've been able to get it working for the meantime by adding a TapGestureHandler around the GameEngine and sending dispatch events on press. |
Nice work around @cmaycumber. In the meantime, I'll have a bit of a play with React Native Web to see how best to proceed.. |
Hello! I am making a game that a user may tap on both the
GameEngine
component and buttons(implemented via
View::onTouch
) that are located outside ofGameEngine
concurrently.On iOS, it works as expected: when one finger is placed on the
GameEngine
component, the user can still tap on a button that is located outside theGameEngine
, vice versa.On Android, however, when one finger is placed on the
GameEngine
component and the other finger taps on a button that is outside ofGameEngine
, the additional tap gesture is handled byGameEngine
instead of theView
button.Do you have an insight into fixing this issue? Thanks!
The text was updated successfully, but these errors were encountered: