Get Delta Speed from object running move action

  • sathono
    Likes 0

    Problem Description

    Hello, I am trying to figure out a decent way of obtaining a objects delta speed horizontally and vertically when its running a MoveBy/To action. As of right now I am using a update loop and calculating the distance the moving object has moved to, every .01 seconds like this:

     

    	trackDistance:function()
    	{
    		if (this.prevX != -1)
    		{
    			this.moveX = (this.x - this.prevX);
    			this.moveY = (this.y - this.prevY);
    		}
    		else if (this.prevX == this.x)
    		{
    			this.moveX = this.moveY = 0;
    			this.unschedule(this.trackDistance);
    		}
    		
    		this.prevX = this.x;
    		this.prevY = this.y;
    	},

    This works relatively well, however the program cannot keep up when the objects are moving at high speeds, or if there is any lag. Is there any way to better approach this situation?

  • Sonar Systems admin
    Likes 0

    How much do you have going on in the screen

  • sathono
    Likes 0

    Not to much is going on at the moment, however when I get further into development I do plan to have a extensive amount of objects present at once.

  • Sonar Systems admin
    Likes 0

    You need to factor in delta, do you know how to do this?

  • sathono
    Likes 0

    Im not aware how exactly to approach this, would you be able to explain?

  • Sonar Systems admin
    Likes 0

Login to reply