My problem is getting an item to move across different screens at the same speed and time. At the moment the item doesn’t move or goes way to fast. I specify two points for the item to go to and the max speed.
The Var _oneStep is my attempt to synchronize resolutions.
//Get a fraction of screen size?
_oneStep = ScreenWidth / 100;
//Delta being last update time.
public void MoveItem(double Delta)
{
//Keep at Max speed.
if(Math.abs(_xVelocity) > _maxSpeed || Math.abs(_yVelocity) > _maxSpeed)
{
_accelerationSpeed = 0.0001f * (_maxSpeed / _oneStep);
}
//Or Speed up.
else
{
_accelerationSpeed = 0.00030f * (_maxSpeed / _oneStep);
}
//Destination is above 10% distance or below speed up or down
_xVelocity += _accelerationSpeed * Math.cos(Math.toRadians(_degrees));
_yVelocity += _accelerationSpeed * Math.sin(Math.toRadians(_degrees));
_currentPosition.x += (((_xVelocity * _accelerationSpeed) + _oneStep) * Delta);
_currentPosition.y += (((_yVelocity * _accelerationSpeed) + _oneStep) * Delta);
CheckAtDestination();
}
Some numbers:
System.out.println("X: "+ _xVelocity + " Y: " + _yVelocity); = X: 1.0018943990787657 Y: 1.0109980390961948
System.out.println("XPos: "+ _currentPosition.x + " YPos: " + _currentPosition.x); = XPos: 36 YPos: 36
System.out.println("Degrees: " + _degrees); = Degrees: 80.22677351282063
System.out.println(Delta); = 0.3309303333093033
Also what happens if Delta turns to 1 or over? Are odd results produced?
Above code works, just make sure the _oneStep var is the screenWidth or Height (depending on your object sizes, could be screen dependent).
So _oneStep = ScreenWidth / 100; and the Delta needs to be added to any movement.