HISE Logo Forum
    • Categories
    • Register
    • Login

    Animation lag.

    Scheduled Pinned Locked Moved General Questions
    7 Posts 4 Posters 94 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • X
      xander
      last edited by

      I am working on a cassette plugin that has wheels that are animated. For some reason, the wheels stutter and aren't smooth. I'm thinking the culprit is the absence of delta time, but I'm not sure. This is the code:

      Content.makeFrontInterface(900, 600);
      
      const var wheel_timer = Engine.createTimerObject();
      const var wheel = Content.getComponent("wheel");
      const var wheel1_b = Content.getComponent("wheel1_b");
      const var wheel2_b = Content.getComponent("wheel2_b");
      
      
      const var wheel2 = Content.getComponent("wheel2");
      var i = 100;
      var j = 100;
      
      wheel_timer.setTimerCallback(function()
      {
      	i = i - 1;
      	
      	if (i%2 == 0) {
      		j -= 1;
      	};
      	
      	if (i > 1) {	
      		wheel.setValue(i);
      		wheel2_b.setValue(i);
      	} else {
      		i = 100;
      	};
      	
      	if (j > 1) {	
      			wheel2.setValue(j);
      			wheel1_b.setValue(j);
      		} else {
      			j = 100;
      		};
      	
      	
      });
      
      wheel_timer.startTimer(20);
      
      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @xander
        last edited by

        @xander FYI, macOS might skip timer callbacks if you go below 30milliseconds. You can rule out performance issues by choosing a very low timer frequency (eg. 100ms), then see whether your logic skips some steps or it's related to UI performance.

        X 1 Reply Last reply Reply Quote 0
        • X
          xander @Christoph Hart
          last edited by

          @Christoph-Hart, I'm developing in Windows, and it seems to correlate directly to how fast my PC is running. Now, I am doing this with knobs. Would turning them into Lottie animations fix this, possibly?

          ustkU 2 Replies Last reply Reply Quote 0
          • ustkU
            ustk @xander
            last edited by

            @xander You can also use reg variables instead of var, they are way faster

            Can't help pressing F5 in the forum...

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @ustk
              last edited by

              @ustk I don't think it makes a difference in this context

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              1 Reply Last reply Reply Quote 1
              • ustkU
                ustk @xander
                last edited by ustk

                @xander I also noticed your logic forces to go back to 100 when i==2 (i > 1) instead of 0 which is probably the cause of the stuttering you see
                And you have a lot of branching. Here's a simplified version that goes back to 100 only when vars are equal to 0

                wheel_timer.setTimerCallback(function()
                {
                	--i;
                	j -= 0.5;
                		
                	wheel.setValue(i);
                	wheel2_b.setValue(i);
                	
                	wheel2.setValue(j);
                	wheel1_b.setValue(j);
                
                	if (i == 0)
                		i = 100;
                		
                	if (j == 0)
                		j = 100;
                });
                

                Can't help pressing F5 in the forum...

                X 1 Reply Last reply Reply Quote 2
                • X
                  xander @ustk
                  last edited by

                  @ustk This didn't fix it completely, but it definitely helped a lot, thank you

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  55

                  Online

                  1.7k

                  Users

                  11.7k

                  Topics

                  101.9k

                  Posts