Jump to content

Any idea how to stop object from flickering


DNGunpla
 Share

Recommended Posts

Currently I am working on a project that requires moving the clock hands, where the hour hand moves 30 degrees while the minute hand moves by 6 degrees.

Example:
https://gyazo.com/72f11ae5f8fdefdbc96c502f7d7fbc48

However,  I have this issue of the object flickering whenever I stopped at a point.

Issue Example:
20180418_100149.jpg

Right now this is my code for moving the minute hand and the hour hand

Quote

dragMinutes: function(){
        this.calculateAngles(minute);
      
        minutes += direction; //0.5 is speed
      
        hours = (minutes/1440)*24; //24h = 1440 minutes,

    },

    dragHours: function(){
        this.calculateAngles(hour);
        
        hours += direction; //0.05 is speed

        
        //minutes = hours* 60;
    },

    calculateAngles: function(dial){
        //round to whole numbers
        mouseangle = Math.floor(this.game.physics.arcade.angleToPointer(dial)*180/Math.PI);
      
        //difference between mouse and dial
        difference = Math.abs(mouseangle - dial.angle);
      
        //if reached 9 o clock going counterclockwise, reverse the difference calculation.
        if(difference>180){
            difference = 180 - mouseangle + dial.angle;
        }else{
            difference = mouseangle - dial.angle;
        }
        
        if(difference < 0){
            direction = -1;
        }else if (difference == 0){
            direction = 0;
        }else if (difference > 0){
            direction = 1;
        }
    },


In the Update Function:
 

Quote

if (minute.input.pointerDown())
        {   
            minutes = hours*60;
            this.dragMinutes();
        }
      
        if (hour.input.pointerDown())
        {   

            this.dragHours();
        }

 minute.angle = minutes*6 -90;//6 degrees = 1 minute, 90 degrees, because 12 o clock is facing upward
        minute.angle = Math.round(minute.angle);

hour.angle = hours*30-90; //30 degrees = 1 hour
        hour.angle = Math.round(hour.angle);


Is there anyway to fix it?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...