r/reactnative • • Mar 20 '21

Is anyone else building games in React Native? Would love to see what you've done or if you have any handy resources for animations/interactions :) Been working on this for a few months

340 Upvotes

55 comments sorted by

55

u/peterpme Expo Mar 20 '21

You’ve been building this in react native!? Holy shit this is super cool!

15

u/friggitydingo Mar 20 '21

Yeah! Thank you :D I'd been messing with React and was looking at making a mobile game, so I thought it would be a good fit, given the type of game I was making (which doesn't involve complex stuff like interactive player characters, 3D animations or anything)

3

u/leadsepelin Mar 20 '21

Do you have source code of what you are doing? This looks very cool!

24

u/friggitydingo Mar 20 '21

Thank you! :) I don't have the full source code up because it's going to be an online multiplayer game and it's probably best I don't have people trying to find exploits in it lol.

That being said, obviously lots of stuff in the project is just RN components which could be useful for others. I'm thinking of doing a youtube with some tutorials/explanations, but if there's anything in particular you want to know about or see the code for just let me know :)

2

u/Ethanno7 Jun 03 '21

I would LOVE to know how you created that graph structure at the 6 second mark! I have a project I would also like to do that for

3

u/friggitydingo Jun 03 '21

Hey :) I used react-native-svg to draw the circles (nodes) and the lines between them. I have a JS object that defines the inputs and outputs to each node, along with their id (to lookup the name and icon for the technology).

There are three tree branches coming from the center - I define the position of each of the roots, then I have an array containing the consecutive positions of each node along the branch (then I rotate the array to get the other two branches). In RN I render the tree by traversing the config object and chucking them at each of those positions :) I have a separate config file for the dependencies of each technology - to keep the tree geometry separate from the game information. The colours of each node/line are based on the tech config and whether or not those dependencies are met.

The nodes are wrapped in button-like objects so they can be pressed. The whole thing is inside a set a PanGestureHandler view from react-native-gesture-handler so you can pan around and look at different parts of the tree. Hope this helps :)

13

u/[deleted] Mar 20 '21

I am learning React currently and seeing this just made so much more excited about it! Your game looks beautiful and fun, can't wait to see it when you're done.

4

u/friggitydingo Mar 20 '21

Hey glad to hear that! Thanks a lot! :D I just started learning React like 6 months ago then started with React Native. Hope you do some fun things with RN too!

10

u/Crazralfrill Mar 20 '21

Looks great !

I'm making a React Native game too (a card game)

I'm working with expo right now. I use Reanimated V2 for my animations (mostly for card interaction). For simplier animation, I use moti, which is really easy to use.

Honestly, React Native doesn't seem to be the right tool for this kind of project. I have a lots of issues :

  • I can't use a debugguer because of Reanimated 2 doesn't work nice with expo for the moment

  • I couldn't make lottie to work (I think the expo package is out of date)

  • Sounds effects doesn't work very well. Sometimes, some sounds effects are not played, I don't know why.... I use expo-av.

  • I have issues with image flickering on Android when replacing image by another one.

  • Not a bug, but it's a little bit hard to keep the game playable on all device size. I use react-native-size-matters for that.

  • Keeping good performance is hard too. For the moment, it works with decent performance. But what will happen when it will grow in complexity ?

I came from a webdev background. They are a lots of things that are easy to do in web who becomes very difficult with mobile developpement.

I could eject from expo too, which would help on some issue. I think I will have to at some point, but I'm a little bit afraid for the moment.

And I'm complaining a lot, but my game is progressing :)

3

u/friggitydingo Mar 20 '21

Thanks! I'm using Expo too. Glad that your game is progressing :)

I've seen Reanimated around but hadn't yet needed to try it out - how do you find it? Aside from not playing nicely with expo lol.

I've only just started playing around with expo-av for sound effects. I've had slight delays on the sound effects, and the first time I try to play them they don't play (I'm sure that's just some coding issue on my part), but I'm hoping those delays will reduce in a proper build. My method was to load SFX and keep them loaded, set the playback position to 0 before playing them, and when the SFX finishes, use a setOnPlaybackStatusUpdate callback to pause the sound.

I have also been a bit worried about how the game would scale with complexity and whether the performance would take a hit, but I've found that the more I work on it, the more I understand the framework and I end up going back and rewriting things to work better as I go :)

Definitely not the most straight-forward platform for making games, but I really enjoy building things with React so it's been worth it for me :) It works fairly well for my type of game, which mostly involves making individual requests to a database to upgrade buildings, send fleets, etc, just moving numbers around and animating some visuals.

3

u/Crazralfrill Mar 20 '21

I'm surprised you're not using Reanimated.
First I was using Reanimated V1. It was a pain in the ass. I coded my card interaction with it (card draw, drag'n'drop, zoom on touch etc...). It worked, but the code was really complicated and hard to change. When reanimated 2 was released I remake it from scratch and it was really a nicer experience, even if it's still in beta.
So I recommand it.

For SFX, I have delay too. I'm loading all the sound on the app startup and just call replayAsync.
Well, if you resolve this issue, I would be happy if you share the solution with me ;)
I'm using .mp3 right now. .wav files are better suited for sound effects but I didn't tried it yet.

3

u/friggitydingo Mar 22 '21

Hey, this is the best luck I've had with playing sounds - have a look if you want https://gist.github.com/Benjamiiiin/ca8b9ee5fb7d10b596ec9de7d55bfd87

I don't have support for looping in that example, but not hard to add

2

u/Crazralfrill Mar 22 '21

Thanks, here's my not working code (delay and sounds not played sometimes) :

https://gist.github.com/yleclanche/44b1f3f82e07d84e681ecaa8282e308f

How did you manage to fix your issue ? Is this the call to setAudioModeAsync ?

2

u/friggitydingo Mar 22 '21

Ahh I see, yours is similar to the last version I had, where I was storing the sounds in an object and keeping them loaded. I tried replayAsync like you are, and a couple of other things, like playAsync followed by setPositionAsync(0), but couldn't get anything consistent that way.

The one I sent only loads sounds as they need to be played, and immediately unloads them once they're finished. I did this as a last resort, but it seems to be working quite well actually, and I think it's the recommended expo way to do it. I still have a small delay on sounds when running locally, but haven't tried it in a build yet.

The setAudioModeAsync call is just to control the way Android handles your sounds' interactions with sounds being played from other apps :)

2

u/Crazralfrill Mar 22 '21

That's seems a little bit counterintuitive, but I will try this, thanks !

1

u/friggitydingo Mar 22 '21

Yeah I know! Not sure what the motivation is for that, especially given how little memory small SFX files would take up... Good luck with it :)

2

u/friggitydingo Mar 20 '21

Okay I'll definitely take another look at Reainimated then :) Cool!

Haha sure, I reckon I can fix the audio issue - I'll let you know when I work it out! I also haven't tried .wav files, just mp3s.

2

u/harimanok Mar 20 '21

We are re-writing Evil Apples (a card game) in React Native. The results are pretty good though we have spent a whole lot of time trying to optimize the game.

7

u/Lngdnzi Mar 20 '21 edited Jun 24 '25

tidy steep chase growth disarm market test alleged badge sharp

This post was mass deleted and anonymized with Redact

21

u/friggitydingo Mar 20 '21

Thanks a lot! Most of the graphics are just standard rn Image components, or Animated.Image, with scale and opacity animations. Some things like the sun and gas giant I was using rn-sprite-sheet to animate spritesheets but I made my own version to make scaling stuff easier. The rotating planet is just an Animated.View with some maths to work out the right left/top offsets and then applying some transforms in the style

9

u/friggitydingo Mar 20 '21

Also react-native-svg for some UI elements and the tech tree :)

1

u/Lngdnzi Mar 21 '21 edited Jun 24 '25

enter fragile history degree important tart fuel ink chief butter

This post was mass deleted and anonymized with Redact

2

u/friggitydingo Mar 21 '21

Nice, good luck with it! Nah no need for an engine really, just RN and some of my own stuff. The game mostly involves interaction with a server which sets and gets game/user data from a mongo db, and the app will re-render stuff based on the response. The game has an RTS/idle element to it, and resources and jobs and stuff will only be calculated when you actually make a request to the server, based on the time that has passed.

2

u/Lngdnzi Mar 21 '21 edited Jun 24 '25

yam repeat birds sleep friendly nutty degree stocking touch pot

This post was mass deleted and anonymized with Redact

5

u/robotpoolparty Mar 20 '21

I gave up on games in react native. But you make it look possible! What are you using as the foundation for all of the animations / interactions?

5

u/friggitydingo Mar 20 '21

Sorry to hear that, I guess it depends what sort of game you're making. Mine doesn't have like a character you're controlling or moving around, which I imagine would be difficult in rn. A lot of the simple animations are just the plain old Animated library with animated timings to scale things in and out, or change opacities. I was using rn-sprite-sheet for some spritesheet animations but I ended up making my own custom one instead. I use react-native-gesture-handler for some of the panning views, and have been using panhandler for some drag and drop stuff :)

2

u/robotpoolparty Mar 20 '21

Thanks for the info. Glad to hear you were able to custom build a lot of things from the ground up! Nice work!

4

u/Stock_Chance_2615 Mar 20 '21

Have you had a look at react native game engine

1

u/friggitydingo Mar 20 '21

No I hadn't seen this! Wow, looks pretty handy. I'll have to see if this can solve any of my gesture/animation/drag-and-drop woes haha

2

u/Stock_Chance_2615 Mar 20 '21

I’m sure it will 💪

3

u/NotDraven----Draaven Mar 21 '21

Way to go man ,thats great!

3

u/smoonme21 Mar 21 '21

Holy fuck this is crazy! Well done !!!

1

u/friggitydingo Mar 21 '21

Haha thanks! :)

2

u/friggitydingo Mar 20 '21

If anyone wants to see more of the project you can check out my twitter, otherwise hit me up if I can answer any questions that might help with your own stuff :)

2

u/jakeforaker83 Mar 20 '21

Download link please?

1

u/friggitydingo Mar 20 '21

Haven't finished/released it yet, work in progress!

2

u/chrismar303 Mar 20 '21

Wow this is awesome! How are you making games with RN!?

2

u/friggitydingo Mar 20 '21

Hey thanks! Using lots of RN Animated, using the transform property in components' styles to move/scale/fade stuff :) Lots of Image components for my art, etc

2

u/felipefa77 Mar 20 '21

Wow man, that's looking really nice!

I'm also building a React Native game, but mine is way simpler and doesn't have a lot of animations (at least not yet as they are not really needed in my case for the MVP). I'll try to make a post about it when I have the chance, hopefully sooner than later.

Keep up the good work!

2

u/friggitydingo Mar 20 '21

Thanks a lot! :) Mine started out really simple too (no animations, just buttons and images) and slowly evolved more features. Would love to see what you're doing soon, good luck to you too!

2

u/stroma_ru Mar 20 '21

I'm new to RN but I did find a tool that worked well with flutter, it's called rive.app They have a community supported runtime for RN. Maybe worth looking at.

1

u/friggitydingo Mar 20 '21

I will check that out, thanks!!

2

u/post_hazanko Mar 20 '21

that looks great, nice art/design

1

u/friggitydingo Mar 20 '21

Thanks!! :)

2

u/astral_turd Mar 20 '21

Amazing stuff! Be proud

1

u/friggitydingo Mar 20 '21

Thanks so much :D

2

u/Gloomy_Economy2137 Mar 20 '21 edited Mar 20 '21

Lol, just released my game making video and came to share and saw this post just at top 🤭

Building T-rex game of google: https://youtu.be/KqV_W5sCn7w

1

u/friggitydingo Mar 20 '21

Haha, well you're in good company. Nice vid and project! I'm looking at doing some youtube vids myself. Keep it up!

2

u/Gloomy_Economy2137 Mar 20 '21

I will look for your vids 😁

2

u/jgstruggling Mar 20 '21

I had no idea RN was capable of this! This is so cool! I was reading and you said you just started learning 6mo ago!? What kind of resources have you been using to learn? I’m getting into and would love to know what you did

2

u/friggitydingo Mar 21 '21

Hey thanks heaps :) So I'm using expo and have mostly just been using the examples in the React Native docs, running and messing with those, scouring forums like stackoverflow when I run into problems, etc. I don't think I've used anything particularly special for the game vs a normal RN app, aside from lots of images! When I use other people's packages like react-native-gesture-handler or rn-sprite-sheet I just consult the docs and examples on their git pages.

Not sure if that's any help haha. I find using Typescript rather than JavaScript is nicer, much easier to keep track of what my objects and functions are doing, and I use interfaces a lot. I find for learning these sorts of things, having motivation in the form of a particular goal or project is the best way to get yourself to learn things along the way. The game used to look suuuper basic and I went through several iterations to get here

2

u/lord_drgical Mar 24 '21

Wow very cool!!! I am also working on a game ( like a yugioh card game clone, mainly to add to my portfolio ). I have a little more than 1 year of react native experience, I'm curious, do you use navigations in this ? or all they all custom animations for containers/views ( an example at 0:04 when you pressed on the laboratory level ). Also, are you using any special modules that helped you with all the graphics?

1

u/friggitydingo Mar 24 '21

Thanks! :) I am using react-navigation for moving between the major screens like the planet view and galaxy view. For the modals like the laboratory view, I'm using a custom modal component I made - although I was using react-native-modal for a while. As for graphics, not really, it's mostly just Animated components. Some things like the sun or the spinning gas giant were rn-sprite-sheet, but I've also made my own spritesheet component now.

1

u/Used_Coast_8647 Nov 20 '23

Hey! after 3 years, is your game finished? can I try it?