How to prevent graphics stuttering?


I recently began using HeapsIO and I’ve begun to notice an issue with stuttering. If I create a simple app where a h2d sprite or text simply moves across the screen, there is a noticible stutter that occurs. It’s pretty random, sometimes things will be smooth, other times it will be super choppy, though mostly it falls somewhere in between.

I’m using Hash Link and have tried both DirectX and SDL implementations, but both result in the same issue. Any suggestions?

For context, here’s an example of that would replicate what occurs (at least on my end):

class Main extends hxd.App {
  public var txt: h2d.Text = null;

  override function init() {
    txt = new h2d.Text(hxd.res.DefaultFont.get(), s2d);
    txt.y = 40;
    txt.text = "Hello World !";

  override function update(dt: Float) {
    txt.x += 3;


You may be dropping frames (though this app is so simple that it shouldn’t). The dt passed into update is actually the amount of time since the last frame, normalized, which means that 1.0 is exactly one frame (which I think is set to 60fps). At any rate, to make things appear smoother, you may try txt.x += 3.0 * dt;. That should at least get a consistent rate of movement, even though it doesn’t help the frame rate at all.


You are not considering dt. The framerate isn’t constant and you have to account for the actual time that has passed. Just multiply whatever value for dt.
If you notice subpixel tearing you will need to take into account fractional parts when adding translation values.



I agree with you about the use dt value for getting constant speed.

But the OP seems to have another problem: with such a simple program, dt value should be constant (something like 1/60th seconds, or less if he has disabled vbl).

My advice is to check with top (linux) or task manager (windows) if there is something hogging the cpu when launching the program.


According to my experience, even with such a simple program and high-end hardware you will get stuttering at times. The framerate is simulated with a delay and there is no hardware interrupt driving the simulation. In the end, you will get some odd frames that will break the illusion of constant movement speed.


On Windows you might not get the best framerate depending on your drivers / video cards / etc.
On HashLink, setting the window to fullscreen exclusive might work better.

var wnd = hxd.Window.get();
#if hl @:privateAccess wnd.fullScreenMode = Fullscreen; #end