Screen refresh rate

I want to scroll text sideways and do it as smooth as possible. With 50ms timer delay on simulator text scrolls quite smooth, but on actual device fps are well below 60fps. If i request update at the end of onUpdate() on simulator text line scrolls way too fast, but on VivoActive 4 it seems smooth. Is it right approach, because i don't have ability to test on other devices.

	function onUpdate(dc as Dc) as Void {
		dc.setColor(0xffffff, 0xffffff);
		dc.clear();

		DrawUtils.drawHeaderAndFooter(stopInfo[:name], drawStopIndicator, up, down, dc);

		dc.setClip(DrawUtils.clipX, DrawUtils.clipY, DrawUtils.clipWidth, DrawUtils.clipHeight);
		dc.setColor(0x000000, 0xffffff);

		var printedLines = 0;
		for (var i = $.pageIndex * 4; printedLines < 4 && i < stopInfo[:busID].size(); i++) {
			scrollLines[printedLines].updateText(dc);
			printedLines++;
		}

		dc.clearClip();
		DrawUtils.drawTimes(stopInfo, dc);

		// Ui.requestUpdate();
		scrollTimer.start(method(:trigerUiUpdate), 50, false);
	}

function updateText(dc) {

	dc.drawText(x + currentPos, y, font, text, Graphics.TEXT_JUSTIFY_LEFT | Graphics.TEXT_JUSTIFY_VCENTER);

	if (isStatic == false) {
		currentPos -= 2;

		if (currentPos < -textWidth - loopSpace) {
			currentPos = 0;
		}
	}
}

function drawTimes() (garmin dont allow to paste it here )

  • I don't understand why you sent this part of the code. We could discuss if you should decrease it by 2 or 1 or 3 pixels, but from what you wrote above this is probably not (or not the only) thing that you can fine tune, and to me it sounds that the more interesting part would be to see is where you request for the next update, how you decide after how many milliseconds you want it to be called again.

  • I added more code, at the end of onUpdate() is either Ui.requestUpdate() or callback to trigger it after 50ms as it is smallest timer delay.

  • Ui.requestUpdate(); will call onUpdate, and scrollTimer.start(method(:trigerUiUpdate), 50, false); will call  trigerUiUpdate() (which we don't see). What calls updateText()?

  • in for loop scrollLines[printedLines].onUpdate(dc) (line 12 in onUpdate)

  • so scrollLines[printedLines].onUpdate(dc); calls updateText(dc)?

    This is not good IMHO. When you draw in onUpdate you should draw one frame only. When you call updateText multiple times in a loop then you'll only see the last one of them - similar to if you would do it once but instead of -2 you move it by -8.

  • scrollLines[printedLines].onUpdate(dc) and updateText(dc) is actually the same method, i only renamed for sake of simplicity. Inside loop i call updateText(dc) for each ScrollableLine instance and draw it to dc. So it redraws all lines with -2 offset on every onUpdate(). 

  • ah ok.

    If I were you I'd probably try to do with the timer, and make my code in such a way that 50 is a constant, and I can change it per device groups or devices (using monkey.jungle + directories where the const can sit in a file in its own)

    const ANIMATION_DELAY_MS = 50;

    If users will tell you it's too slow or fast on some device you can add a new folder with a file where you have a different value and in the monkey.jungle file point the specific device to use that folder instead of the default one.