massimo

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 :slight_smile:

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

Showing Posts 1 to 10

AstonJ

AstonJ

This is awesome - well done!! :023:

amnu3387

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

AstonJ

Please keep us posted @amnu3387! :smiley:

I’m loving reading about all these Scenic projects :003:

massimo

massimo OP

@AstonJ @amnu3387

The code is online :slight_smile:

axelson

axelson

Scenic Core Team

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

massimo OP

SchedEx run the scheduled function with

Process.send_after(self(), :run, delay)

Still only milliseconds

To get strict 60FPS you need to run update every 16.666666[…] ms or 16,666.666[…] microseconds

Usually, in procedural languages, this is solved in the game loop in two ways

while(true)
  elapsed_time = last_time - current_time()       
  update(elapsed_time)

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

while(true)
  elapsed_time = last_time - current_time()       
  while(elapsed_time < frame_duration)
    elapsed_time = last_time - current_time()       
  last_time = current_time()   

  update()

This way the game wait exactly (well, more or less) frame_duration ms (at 60FPS 16.66ms) before updating the world again

Elixir is not good in tight loops, it doesn’t even have while loops, 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 Timer module 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

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

massimo OP

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

Color cycling , also known as palette shifting , is a technique used in computer graphics in which colors are changed in order to give the impression of animation. This technique was mainly used in early computer games, as storing one image and changing its palette required less memory and processor power than storing the animation as several frames

I was heavily inspired by this demo

https://twitter.com/wstucco/status/1051168787347705856

16
Post #8
AstonJ

AstonJ

Awesome stuff Massimo :023:

massimo

massimo OP

Code is online for those interested :slight_smile:

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews