JsonKody
Hello,
I’m relatively new to Phoenix, having just started the Pragmatic Studio LiveView course. Concurrently, I’m learning Three.js via the Threejs-Journey course. My primary background is in JS/TS/Vue development.
I’m interested in creating a straightforward “memory card” game. I envision it as an online multiplayer game, where two players can connect or create a “game room” that displays the 3D memory card game. My idea is to utilize Phoenix as the game server, primarily responsible for tracking the positions of the cards.
My main question is: would LiveView be suitable for such a project? While I can conceptualize the connection between a Vue or React app and making REST calls on every card flip, I’m finding it challenging to visualize how I’d integrate the game with LiveView, especially in the context of websockets.
Any guidance or insights you can provide would be greatly appreciated!
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
Hello and welcome to the forums!
I was typing up an answer to this earlier and then it disappeared! So, here it is:
The short answer is: yes, very-well suited. Almost tailor-made!
Here’s a talk and repo for implementing King of Tokyo (a multiplayer board game, if you are unfamiliar) in LiveView.
a8t
I don’t know how threejs works but have you looked at Phoenix Channels, which is part of what Liveview is written on top of
kokolegorille
You should think of channels as bidirectional super controllers
brightball
I saw a talk about Three.JS a couple of weeks ago. Really cool technology!
Keep us posted on how this progresses.
mindok
Hi @JsonKody, and welcome!
LiveView would be awesome for this project and simplifies a lot of the plumbing over raw Phoenix Channels. I have embedded Babylon JS (Threejs alternative), and Konvajs (2D rather than 3D) and they work great. Here are a few of the ingredients you need:
See JavaScript interoperability — Phoenix LiveView v1.2.5
This can have event handlers to handle events pushed from the server (i.e. the server-side LiveView code) (see
handleEventin the linked doc. It can also push information back to the server LiveView usingpushEventorpushEventTo.The fact that there is a long-lived server process on the other end of the conversation simplifies state management enormously.
phx-hookfor instructions. Note that ifthreejsis doing DOM manipulation, you will need to mark the DOM node that it attaches to in a special way to prevent patching from the server (usephx-update="ignore" (see https://hexdocs.pm/phoenix_live_view/dom-patching.html)The LiveView can send events to the client hook using
push_event(see JavaScript interoperability — Phoenix LiveView v1.2.5) and handles event from the client side usinghandle_event.PubSubwith a topic per game. When the LiveView mounts, it can subscribe to the PubSub topic related to the game. This will ensure that LiveView process receives the game events. In the project @sodapopcan linked, you can see it happening here: king_of_tokyo/lib/king_of_tokyo_web/live/game_live.ex at 27f992f28e5be80125f36aed79d95812c568b1c0 · dkarter/king_of_tokyo · GitHub. The events are handled in the varioushandle_infofunctions in the same file.To notify other game participants in the same game, you would use
Phones.PubSubtobroadcastevents to the game topic. It’s a bit hard to follow in the linked project as they spin up a backing process per game in theGameServermodule, but there’s a call here: king_of_tokyo/lib/king_of_tokyo/game_server.ex at 27f992f28e5be80125f36aed79d95812c568b1c0 · dkarter/king_of_tokyo · GitHub - if you backtrack where that’s called from (e.g. thebroadcast_...functions) you can see how the payload is constructed and how that is matched in thehandle_infos in the LiveView.Good luck!
JsonKody
Wow! Thanks for such good answers .. this feels like polar opposite of Stack Overflow ( ͡° ͜ʖ ͡°)
Elixir has amazing comunity <3
I’ll look at all those links after weekend, thank you again.
PS: ok I’ll share it when it’s done but it would be so much work (I’ve some other projects before it - they will help me become proficient with Elixir/Phoenix/Liveview hopefully)