Jump to content

Using Phaser with Elixir + Phoenix, How To


trinimac
 Share

Recommended Posts

Hi,

 

I've been learning Elixir + Phoenix for fun, after using Ruby + Sinatra for a group project. 

I'd like to set up a web based game, and i'm interested in using Phaser inside an Elixir + Phoenix setup.

I was wondering if anyone could give me a quick debrief; I'm assuming it's possible but is it better to use Phoenix simply 

for launching the app? (so any calculations should be done within Javascript), or is it possible to set up most of the logic inside Elixir 

and be done server side (which I think would be better for avoiding hacks)?

Link to comment
Share on other sites

There will be certain calculations that will happen on the client (e.g where to render an object) and there are other calculations that could happen anywhere, such as the outcome of Unit A attacking Unit B (for example). For the 2nd case there you could do those calcs on the client, it'll likely be quicker that way (without waiting for network latency) and if you game is a single player experience then thats fine to take that approach (for multiplayer you could do that, but it maybe will be trickier).

However, you could perform that attack-example calc on a remote service somewhere, which could be where Elixir/Phoenix is running (I don't know Phoenix, its not a browser client thing though right?). Looking through the docs Phoenix exposes a JS client which I'm guessing helps with this communication. It would be asynchronous so I guess it would be something like, invoke a remote function with some parameters and wait for the response, then do something with the response i.e. invoke 'Attack' with 'Unit 1' & 'Unit 2', your server then returns the outcome of that attack and you do some more client-side JS stuff to render (or otherwise manage) the outcome of that response. This process of invoking a function and handling a response is the same if you were executing a client-side JS function, the only difference being that it becomes a synchronous operation rather than an asynchronous one, but, conceptually, its about the same.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...