massimo
I’ve tweeted this yesterday and it’s getting some attention, so I decided to post it here to share comments, ideas and answer questions, if anybody got some ![]()
The tweet can be found here
https://twitter.com/wstucco/status/1046485501774057473
What I did is write a custom Scene module and a custom Component model on top of Scenic, reusing and extending Scenic’s own Scene and Component modules, that automatically keep track of component creation and can communicate.
The Scene has an internal list of children components and send to each of them an :animation_frame message on regular intervals, the interval is the amount of milliseconds coming out from the formula
trunc(1_000 / FPS * multiplier)
Note:
The timing is not perfect yet, 60 FPS generate an interval of 16ms, which is actually 62.5 FPS
I’m starting a series of posts on this argument and the first one will about writing a Timer that has resolution in the microseconds instead of milliseconds (I’ve managed to have an std deviation of about 30 microseconds at 60 FPS)
You can find some more information on this thread
https://twitter.com/BoydMulterer/status/1046497642442678272
I will use this post as placeholder to post about progresses in the area of pixel animation without having access to pixels
I’ll post the code of the project as soon as I’ll be back home on my couch
With Scenic Elixir enters in the arena of GUI applications and it does in a pretty spectacular way
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 10 of 15 Posts
AstonJ
This is awesome - well done!!
amnu3387
This looks great! I’m re-writing the engine and html/js front-end for a game of mine and can’t wait to try doing the interface with Scenic.
AstonJ
Please keep us posted @amnu3387!
I’m loving reading about all these Scenic projects
massimo
@AstonJ @amnu3387
The code is online
axelson
I wonder if SchedEx would be a good fit for the scheduling for your game. It is what powers beats (a drum engine):
The talk also contains some interesting discussion on the impact of the current state of millisecond-level timers in Erlang.
massimo
SchedEx run the scheduled function with
Still only milliseconds
To get strict 60FPS you need to run
updateevery 16.666666[…] ms or 16,666.666[…] microsecondsUsually, in procedural languages, this is solved in the game loop in two ways
This way the update knows how much time has passed since the last update and can advance the game state proportionally to the amount of time passed
The other way is
This way the game wait exactly (well, more or less)
frame_durationms (at 60FPS 16.66ms) before updating the world againElixir is not good in tight loops, it doesn’t even have
whileloops, but it’s good at sending async messages as fast as possible, so we need to use a different approach (but the logic is very similar)If you look at the code there’s a
Timermodule that implements a timer with resolution in the microseconds range. It’s not used in the game, but I’ve started working on it.I’ll be back soon with a short post that explains the internals of it.
To answer you question: music is played in BPM which is beats per minute
Having a timer that can send messages in milliseconds is more than enough, 120 BPM, which is very fast for music, sends only 2 messages per second or a message every 500ms
amnu3387
Thanks! I will check it once I have some time (now you made me want to write a dragon force clone… in elixir)
massimo
I’ve just completed another little challenge
This time I’ve implemented the color cycling effect natively in Elixir and Scenic
All the code, including decoding and re-encoding the PNGs and their palettes is pure Elixir
I will release it soon on Gitlab
For those who don’t know what color cycling is
I was heavily inspired by this demo
https://twitter.com/wstucco/status/1051168787347705856
AstonJ
Awesome stuff Massimo
massimo
Code is online for those interested